Loading

摘要: #函数就是实现一个特定功能的程序块 #下面这个函数实现了打印helloworld的功能 def print_hello(): print('hello world!') #这是调用方法 print_hello() #下面的函数,实现了传入参数的功能 #在函数中可以嵌套使用其他函数 def print_name(name): print_hello() print('hel... 阅读全文
posted @ 2017-11-18 16:49 上官飞鸿 阅读(24706) 评论(0) 推荐(0)
摘要: import json user = [ [1, [ 11, 12 ]], [2, [ 21, 22 ]], ] print(user) print(type(user)) json_str = json.dumps(user) print(json_str) print(type(json_str... 阅读全文
posted @ 2017-11-16 19:15 上官飞鸿 阅读(341) 评论(0) 推荐(0)
摘要: import time, datetime # 时间的几种格式: # 一:时间戳(timestamp),1970年1月1日0点开始,到现在的秒数(以格林尼治时间为准)。 # 数据类型为'float',浮点数,小数 print('时间戳') print('当前时间') print(time.time()) print(type(time.time())) print('==========... 阅读全文
posted @ 2017-11-16 19:12 上官飞鸿 阅读(11889) 评论(0) 推荐(0)
摘要: import random from random import random, uniform, randint, randrange, choice, sample, shuffle list = ['jack', 'rose', 'tom', 'jerry'] print(random()) # 随机小数 0.0 <= x < 1.0 print(uniform(1, 10)) # ... 阅读全文
posted @ 2017-11-16 19:11 上官飞鸿 阅读(3261) 评论(0) 推荐(0)
摘要: from configparser import ConfigParser fp = 'conf.ini' #定义配置文件名 conf = ConfigParser() #实例化 conf.read(fp) # 打开conf conf.add_section('Section1') #添加conf节点 conf.set('Section1', 'name', 'jack'... 阅读全文
posted @ 2017-11-16 19:05 上官飞鸿 阅读(7822) 评论(0) 推荐(0)
摘要: ''' 1.os.mknod("test.txt") #创建空文件 2.fp = open("test.txt",w) #直接打开一个文件,如果文件不存在则创建文件 3.关于open 模式: r:以读模式打开 w:以写方式打开, a:以追加模式打开 (从 EOF 开始, 必要时创建新文件) r+:以读写模式打开 w... 阅读全文
posted @ 2017-11-16 18:01 上官飞鸿 阅读(404) 评论(0) 推荐(0)
摘要: ''' 一、python中对文件、文件夹操作时经常用到的os模块和shutil模块常用方法。 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件和目录名:os.listdir() 3.函数用来删除一个文件:os.remove() 4.删除多个目录:os.removedirs(r“c:\python”) 5.检验给出的路径是否是一个文... 阅读全文
posted @ 2017-11-16 17:49 上官飞鸿 阅读(3495) 评论(0) 推荐(3)
摘要: test = 'abcdefghijklmnopqrstuvwxyz' print(test) print(test[1:5]) #可以切片 print(test.capitalize()) #首字母大写 print(test.count('a'))#计数 print(test.center(50,'-')) #美观打印 print(test.encode('utf-8'))#转码 pr... 阅读全文
posted @ 2017-11-16 12:42 上官飞鸿 阅读(208) 评论(0) 推荐(0)
摘要: # set自动去重,但是没有值,只有keys = set([3, 5, 9, 10]) # 创建一个数值集合t = set("Hello") # 创建一个唯一字符的集合x = 'x'a = t | s # t 和 s的并集b = t & s # t 和 s的交集c = t - s # 求差集(项在t 阅读全文
posted @ 2017-11-16 12:38 上官飞鸿 阅读(272) 评论(0) 推荐(0)
摘要: 这是带索引的 阅读全文
posted @ 2017-11-16 12:37 上官飞鸿 阅读(2984) 评论(0) 推荐(0)