摘要: 索引: msg='hello world' 正向取 a=msg[1] 反向取 b=msg[ 1] ps:只能取不能改 切片: msg='hello world' res=msg[0:5](hello) 切片的步长: res=msg[0:5:2](hlo) 反向步长: res=msg "5:0: 1" 阅读全文
posted @ 2020-03-10 19:29 江湖有梦 阅读(706) 评论(0) 推荐(0) 编辑
摘要: int:将数字类型转化为整型 float:将数字类型转化为浮点型 str:可以将任意类型转化为字符串 使用方法: int(x) float(x) str() 阅读全文
posted @ 2020-03-10 19:25 江湖有梦 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Markdown在线编辑器 www.MdEditor.com 1.什么是for循环for循环就是重复的去做某件事情,for循环是python中的第二种循环机制。2.为何要有for循环从理论上出发for循环可以做的事,while训话你都可以完成。但是for循环的循环取值(遍历取值)要比while循环更 阅读全文
posted @ 2020-03-10 19:06 江湖有梦 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 作业(必做题): 1. 使用while循环输出1 2 3 4 5 6 8 9 10 n = 1 while n < 11: if n == 7: n += 1 continue else: print(n) n += 1 2. 求1 100的所有数的和 sum = 0 n = 1 while n < 阅读全文
posted @ 2020-03-09 19:46 江湖有梦 阅读(258) 评论(0) 推荐(0) 编辑
摘要: while 条件: 代码一 代码二 条件可以为显式布尔值,也可以为隐式布尔值。 死循环: 没有io的纯计算死循环会导致致命的效率问题 退出循环的两种方式tag,break 例: tag=True while tag: if : print(' ') tag=0 tag方式可以一次性结束多个循环。 例 阅读全文
posted @ 2020-03-09 18:37 江湖有梦 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 需求:想拷贝原列表,产生一个新的列表,而且想让两个列表完全区分开,互不影响,针对改操作,而不是读操作。 浅copy: list1=['jake','rose',[1,2]] list2=list1.copy() list1和list2的内存地址不同 但是list1[0]与list2[0]的内存地址是 阅读全文
posted @ 2020-03-09 17:43 江湖有梦 阅读(96) 评论(0) 推荐(0) 编辑
摘要: if 条件1: 代码1 elif 条件2: 代码2 else: 代码3 阅读全文
posted @ 2020-03-06 19:15 江湖有梦 阅读(151) 评论(0) 推荐(0) 编辑
摘要: in:用来判断是否存在 例: 'a'in'abcd' (True) 1 in [1,2,3,4,5] (True) name in{name:'jake',age:18} (True) ps:字典中我们只能判断key的存在 not in:用法类似in is:用于判断id是否相等 阅读全文
posted @ 2020-03-06 19:12 江湖有梦 阅读(252) 评论(0) 推荐(0) 编辑
摘要: not,and,or not:将紧跟其后的那个值取反 例:not 31 (True) 2==1 and 5 1 (false) True and false (false) 35 and True and 5==5 (false) ps:两侧都为真的情况下是真,任意一侧为假即为假。(同真为真,一假为 阅读全文
posted @ 2020-03-06 19:07 江湖有梦 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 可变类型:值改变了,id不变。 不可变类型:值变了,id也变了。 int,str,float都是不可变类型 list,dic都是可变类型 ps:在字典中,key必须是不可变类型,value可以是不可变类型,也可以是可变类型。 阅读全文
posted @ 2020-03-06 18:31 江湖有梦 阅读(158) 评论(0) 推荐(0) 编辑