02 2018 档案

摘要:# 案例 # 文件的复制 # 要求 # 将一个文件, 复制到另外一个副本中 # 步骤分析 # 1. # 只读模式, 打开要复制的文件 import os import shutil path = "files" if not os.path.exists(path): exit() os.chdir(path) source_file = open("a.txt", "r") ... 阅读全文
posted @ 2018-02-26 09:42 delphiclub 阅读(264) 评论(0) 推荐(0) 编辑
摘要:# 文件的作用 # 永久性的存储数据内容 # 文件的使用流程 # 打开 # open("文件","模式") # 模式 # # 读写 # 定位 # f.seek(字节,[0, 1, 2]) # 0 # 开头 # 1 # 当前位置 # 2 # 文件末尾 # f.tell() # 查看当前位置 # 读 # f.read(字节数) # 字节数默认是文件内容长度 # 下标会自动后移 # f.rea... 阅读全文
posted @ 2018-02-25 22:43 delphiclub 阅读(175) 评论(0) 推荐(0) 编辑
摘要:# 函数的概念 # 概念 # 写了一段代码实现了某个小功能; 然后把这些代码集中到一块, 起一个名字; 下一次就可以根据这个名字再次使用这个代码块, 这就是函数 # 作用 # 方便代码的重用 # 分解任务, 简化程序逻辑 # 使代码更加模块化 # 函数分类 # 内建函数 # 三... 阅读全文
posted @ 2018-02-25 17:14 delphiclub 阅读(292) 评论(0) 推荐(0) 编辑
摘要:# 时间日历 # time模块 # 提供了处理时间和表示之间转换的功能 # 获取当前时间戳 # 概念 # 从0时区的1970年1月1日0时0分0秒, 到所给定日期时间的秒数 # 浮点数 # 获取方式 # import time # time.time() import time result = time.time() print(result) # 获取时间元组 # 概念 # 很多p... 阅读全文
posted @ 2018-02-23 23:33 delphiclub 阅读(453) 评论(0) 推荐(0) 编辑
摘要:# 元组概念:有序的不可变的元素集合 # 和列表的区别就是, 元组元素不能修改 # 定义 # 一个元素的写法 # (666,) t = (666,) #正确写法 t = (666) #错误写法,括号当成优先级的括号了 # 多个元素的写法 # (1,2,3) t = (1, 2, 3) print(t, type(t)) #(1... 阅读全文
posted @ 2018-02-23 22:25 delphiclub 阅读(584) 评论(0) 推荐(0) 编辑
摘要:# 集合 # 概念 # 无序的, 不可随机访问的, 不可重复的元素集合 # 与数学中集合的概念类似,可对其进行交、并、差、补等逻辑运算 # 分为可变集合和非可变集合 # set # 为可变集合 # 增 # ... 阅读全文
posted @ 2018-02-23 22:23 delphiclub 阅读(660) 评论(0) 推荐(0) 编辑
摘要:# 字典概念:无序的, 可变的键值对集合 # 定义 # 方式1 # {key: value, key: value...} # 例如 # {"name": "xin", "age": 18} d = {"name": "xin", "age": 18} print(d, type(d)) #{'name': 'xin', 'age': 18} p... 阅读全文
posted @ 2018-02-23 13:10 delphiclub 阅读(648) 评论(0) 推荐(0) 编辑
摘要:# 列表概念:有序的可变的元素集合 # 定义 # 直接定义 nums = [1,2,3,4,5] # 通过range函数构造,python2 和python3 版本之间的差异; # python3 用的时候才会去构造 nums = range(1,101) # 列表嵌套 # 注意和C语言中数组的区别,是否可以存放不同的数据类型 nums = [1,2,"ab",... 阅读全文
posted @ 2018-02-22 23:53 delphiclub 阅读(57647) 评论(0) 推荐(1) 编辑
摘要:# 字符串概念:由单个字符串组成的一个集合 # 普通字符串(非原始字符串) str = "abc" print(str) # abc # 原始字符串(前面加r) str = r"abc" print(str) # abc # 上面2个字符串区别,普通字符串可以加入转义字符,可以使用%来填坑 str = "ab\tc"; print(str) # ab c... 阅读全文
posted @ 2018-02-20 23:12 delphiclub 阅读(244) 评论(0) 推荐(0) 编辑
摘要:1.数值类型分为整形(二进制(0b),八进制(0o),十进制,十六进制(0x) ),浮点型,long,complex(复合行) 当我们说十进制数的时候,是逢10进1,就是说到达10的时候就要向前一位进以为;有0..9这10个数; 按这样的理解二进制,八进制,十六进制,就好理解了,二进制,就是逢2进1 阅读全文
posted @ 2018-02-20 21:32 delphiclub 阅读(283) 评论(0) 推荐(0) 编辑
摘要:# 循环综合应用1. # str = "hello,world" 把字符串给反转显示 str = "hello,world" temp = "" for c in str: temp = c + temp else: print("字符串反转完毕:",temp) # 循环综合应用2 # 打印1..100之间的偶数 # 通过while num = 2 whil... 阅读全文
posted @ 2018-02-16 06:36 delphiclub 阅读(171) 评论(0) 推荐(0) 编辑
摘要:# while的使用 # 要注意些循环的时候,要考虑好循环的结束 # 考虑循环结束的方法有2种: # 1.考虑在循环体里改变while 的条件 # 2.在循环体通过break 语句跳出循环 # 方法1的应用,在循环体改变while的条件 i = 0 while i = 5 : break # while else使用, i = 0 while i ... 阅读全文
posted @ 2018-02-16 06:35 delphiclub 阅读(213) 评论(0) 推荐(0) 编辑
摘要:条件判断可以分: 单分支判断:只有一个if语句 双分支判断:if else 的格式 多分支判断:if elif else 的格式 条件语句嵌套判断 阅读全文
posted @ 2018-02-15 07:24 delphiclub 阅读(206) 评论(0) 推荐(0) 编辑
摘要:#计算人体体脂率 #输入部分 #身高 personHeight = input("请输入你的身高(m):") personHeight = float(personHeight) #体重 personWeight = input("请输入你的体重(Kg):") personWeight = float(personWeight) #年龄 personAge = input("请输入你的年龄... 阅读全文
posted @ 2018-02-13 23:03 delphiclub 阅读(1136) 评论(0) 推荐(0) 编辑
摘要:# _*_ coding:utf-8 _*_ #在2.*版本和3.*版本上是有区别的 # content = raw_input("请输入内容:") # print(type(content)) #str # print(content) content = input("请输入内容:") print(type(content)) #python2(int),python3(str) pri... 阅读全文
posted @ 2018-02-12 22:26 delphiclub 阅读(137) 评论(0) 推荐(0) 编辑
摘要:# 一。算术运算符(+,-,*,**, /, //, %) # 加法运算符+ print(1 + 2) # 字符串相连 print("1"+"2") # 重载 print([1,2] + [3,4]) # 幂运算** # 2的10次方 print(2 ** 10) # 整除运算 // print(5 // 2) # 2 print(5.2 // 2) # 2.0 #... 阅读全文
posted @ 2018-02-12 15:28 delphiclub 阅读(951) 评论(0) 推荐(0) 编辑
摘要:一.python 变量赋值方式有三种; 1.直接赋值:age = 28 2.多个变量赋值 age, sex = 28, 1 #每个变量都必须要有个对应的值 3.特殊形式的赋值(链式赋值) a = b = 28 注意,变量使用之前必须赋值,这点和C++不同,因为python 变量前面没有类型修饰符,也 阅读全文
posted @ 2018-02-12 10:29 delphiclub 阅读(266) 评论(0) 推荐(0) 编辑
摘要:Python 注释分为三种: 1.单行注释:# 2.多行注释:前后3个单引号,或者三个双引号; 如:''' 多行注释 ''', """或者 多行注释 '""" 3.特殊注释: 如在linux 下面,在文件最前面加 #!/usr/bin/python ,代表 执行这个文件的时候,需要用这个程序来运行; 阅读全文
posted @ 2018-02-11 23:13 delphiclub 阅读(443) 评论(0) 推荐(0) 编辑