摘要: 狗的年龄计算判断 age = int(input("请输入你家狗狗的年龄:>>>")) print("") if age 2: s = 22 + (age - 2) * 5 print("对应的人类的年龄是>>>", s) # 退出提示 input("点击 enter 键退出") 数字猜谜游戏 a = 7 b = -1 while b != a: b = int(... 阅读全文
posted @ 2018-08-27 11:34 principles 阅读(180) 评论(0) 推荐(0)
摘要: 模块 我们脚本上是用 python 解释器来编程,如果你从 Python 解释器退出再进入,那么你定义的所有的方法和变量就都消失了。 为此 Python 提供了一个办法,把这些定义存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件被称为模块。 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py。模块可以被别的程序引入,以使用该模块中的函数等功能。 这也是使用 python 标... 阅读全文
posted @ 2018-08-27 11:33 principles 阅读(122) 评论(0) 推荐(0)
摘要: 数据结构 list.append(x) 把一个元素添加到列表的结尾,相当于 a[len(a):] = [x]。 list.extend(L) 通过添加指定列表的所有元素来扩充列表,相当于 a[len(a):] = L。 list.insert(i, x) 在指定位置插入一个元素。第一个参数是准备插入到其前面的那个元素的索引,例如 a.insert(0, x) 会插入到整个列表之... 阅读全文
posted @ 2018-08-27 11:32 principles 阅读(123) 评论(0) 推荐(0)
摘要: while循环 aa = 100 bb = 0 cc = 1 while cc >>")) print("你输入的数字是>>>",b) print("good bye!") while 循环使用else语句 count = 0 while count >>",wo) a = 100 while a > 0: print("当前变量为>>>",a) a = a - ... 阅读全文
posted @ 2018-08-27 11:31 principles 阅读(88) 评论(0) 推荐(0)
摘要: 数学函数 函数 返回值 ( 描述 ) abs(x) 返回数字的绝对值,如abs(-10) 返回 10 ceil(x) 返回数字的上入整数,如math.ceil(4.1) 返回 5 cmp(x, y) 如果 x y 返回 1。 Python 3 已废弃 。使用 使用 (x>y)-(x<y) 替换。 exp(x) 返回e的x次幂(ex),如math.exp(1) 返回2.7... 阅读全文
posted @ 2018-08-27 11:30 principles 阅读(108) 评论(0) 推荐(0)
摘要: Python列表函数&方法 len(list) 列表元素个数 max(list) 返回列表元素最大值 min(list) 返回列表元素最小值 list(seq) 将元组转换为列表 list.append(obj) 在列表末尾添加新的对象 list.count(obj) 统计某个元素在列表中出现的次数 list.extend(seq) 在列表末尾一次性追加另一个序列中的多个值(用新列... 阅读全文
posted @ 2018-08-27 11:29 principles 阅读(108) 评论(0) 推荐(0)
摘要: 转义字符 在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符。如下表: \(在行尾时) 续行符 \\ 反斜杠符号 \' 单引号 \" 双引号 \a 响铃 \b 退格(Backspace) \e 转义 \000 空 \n 换行 \v 纵向制表符 \t 横向制表符 \r 回车 \f 换页 \oyy 八进... 阅读全文
posted @ 2018-08-27 11:29 principles 阅读(112) 评论(0) 推荐(0)
摘要: 元组内置函数 len(tuple) 计算元组元素个数。 >>> tuple1 = ('Google', 'Runoob', 'Taobao') >>> len(tuple1) 3 max(tuple) 返回元组中元素最大值。 >>> tuple2 = ('5', '4', '8') >>> max(tuple2) '8' min(tuple) 返回元组中元素最小值。 >>> tuple2 = ( 阅读全文
posted @ 2018-08-27 11:28 principles 阅读(110) 评论(0) 推荐(0)
摘要: int 整数,只有一种整型类型,长整型 bool 布尔,如:true float 浮点、小数 complex 复数,如:1+2j、1.1+2.2j 字符串(string) 转移符:“\” 反斜杠可以用来转义,加入r可以让反斜杠不发生转义,如:r"this is line with"\n 则\n会显示,不会换行 python中有两种索引方式,从做到右从0开始,从右到左从-1开始 python字符... 阅读全文
posted @ 2018-08-27 11:27 principles 阅读(126) 评论(0) 推荐(0)
摘要: 多个变量赋值:a , b , c = 1 标准数据类型 number(数字)、string(字符串)、list(列表)、tuple(元组)、set(集合)、dictionary(字典) 可变类型: list(列表)、set(集合)、dictionary(字典) 不可变类型: number(数字)、string(字符串)、tuple(元组) 内置type() 函数可以用来查询变量所... 阅读全文
posted @ 2018-08-27 11:26 principles 阅读(134) 评论(0) 推荐(0)