摘要: names = ['old_driver','rain','jack','shanshan','peiqi','black_girl'] #创建一个空列表,添加元素 names.insert(-1,'alex') #在black_girl 前插入一个 alex print(names) names[3] = '姗姗' #把shanshan改成中文 print(names) names... 阅读全文
posted @ 2018-01-20 21:10 善行无辙 阅读(143) 评论(0) 推荐(0)
摘要: name = ['a','b','*','c','d','e','%'] name2 = [1,2,3,4,5,6] name = name + name2 print(name) name.extend(name2) print(name) 阅读全文
posted @ 2018-01-20 21:09 善行无辙 阅读(116) 评论(0) 推荐(0)
摘要: name = ['a','b','*','c','d','e','%'] name.sort() #sort()按照ASCII码表排序 print(name) name.reverse() #reverse()倒序 print(name) 阅读全文
posted @ 2018-01-20 21:04 善行无辙 阅读(95) 评论(0) 推荐(0)
摘要: name = ['ludongjun','dahuangya','qq',8,9,1,'ludongjun',8,9,4,5,6,'ludongjun',7,3,0,1,2,4] # print('for循环:') # # for gad in name: #for循环 # print(gad) range(10) for i in range(10): print(i) ... 阅读全文
posted @ 2018-01-20 21:03 善行无辙 阅读(169) 评论(0) 推荐(0)
摘要: name = ['ludongjun','dahuangya','qq',8,9,1,'ludongjun',8,9,4,5,6,'ludongjun',7,3,0,1,2,4] print(name,'\n') print('删除:') name.pop() #删除最后一个 print(name) name.remove('ludongjun') print(name) #删除从左往右... 阅读全文
posted @ 2018-01-20 21:00 善行无辙 阅读(113) 评论(0) 推荐(0)
摘要: name = ['ludongjun','dahuangya','qq',8,9,1,'ludongjun',8,9,4,5,6,'ludongjun',7,3,0,1,2,4] print(name,'\n') print('增加:') name.append('bigdog') # apend在中文表示配齐,在程序中表示追加 print(name,'\n') print('插入:')... 阅读全文
posted @ 2018-01-20 20:59 善行无辙 阅读(118) 评论(0) 推荐(0)
摘要: name = ['ludongjun','dahuangya','qq',8,9,1,'ludongjun',8,9,4,5,6,'ludongjun',7,3,0,1,2,4] print(name) print('查询方法:') print(name[2],'通过索引值查找元素') #通过索引取值 print(name[-1],'通过索引值从列表的右边开始查找元素') print(name... 阅读全文
posted @ 2018-01-20 20:57 善行无辙 阅读(239) 评论(0) 推荐(0)
摘要: count = 0 while count <= 5: # if count == 3: #如果有break终止,就不执行,while后面else, # print('33333') # break print(count) count += 1 else: print('循环正常执行完了') pr... 阅读全文
posted @ 2018-01-20 20:52 善行无辙 阅读(158) 评论(0) 推荐(0)
摘要: count = 0 while count < 3: age = int(input('输入猜的年龄:'))#输入的结构必须在循环体内,否则一直循环第一次输入的值 if age == 5: print('恭喜你,猜对了')#猜对了也可以继续玩下去 # b = input('是否要继续玩下去?,y/n:') # if b == 'y... 阅读全文
posted @ 2018-01-20 20:50 善行无辙 阅读(122) 评论(0) 推荐(0)
摘要: count = 0 while count < 3: age = int(input('输入猜的年龄:'))#输入的结构必须在循环体内,否则一直循环第一次输入的值 if age == 5: print('恭喜你,猜对了') break elif age < 5: print('往大了猜') else: ... 阅读全文
posted @ 2018-01-20 20:49 善行无辙 阅读(121) 评论(0) 推荐(0)
摘要: while True: s = input('Enter something : ') if s == 'quit': break if len(s) < 3: print('Too small') continue print('Input is of sufficient length') # 自此处起继续进行其它任何处... 阅读全文
posted @ 2018-01-20 20:48 善行无辙 阅读(130) 评论(0) 推荐(0)
摘要: while count <= 100: print(count) if count == 5: break count += 1 print('loop over') 阅读全文
posted @ 2018-01-20 20:43 善行无辙 阅读(127) 评论(0) 推荐(0)
摘要: #从简明Python搬来 number = 23 # 将23赋值给number的变量 running = True # 在while语句运行前,将running变量设置为ture while running: # 先检查变量running是否为ture,然后再运行相应的块 guess = int(input('Enter an integer : ')) if gu... 阅读全文
posted @ 2018-01-20 20:42 善行无辙 阅读(171) 评论(0) 推荐(0)
摘要: print('and') print("1.",True and True) print("2.",False and False) print('3.',True and False,'\n') print('or') print('4.',True or True) print('5.',True or False) print('6.',False or False,'\n') pri... 阅读全文
posted @ 2018-01-20 20:41 善行无辙 阅读(257) 评论(0) 推荐(0)
摘要: name = input("Name:") age = int(input("Age:")) job = input("Job:") salary = input("Salary:") if salary.isdigit(): #长的像不像数字,比如200d , '200' salary = int(salary) # else: # #print() # exit("... 阅读全文
posted @ 2018-01-20 20:38 善行无辙 阅读(97) 评论(0) 推荐(0)
摘要: #Python字符串的拼接,以及单双引号的运用print('abc','efg') print("abc","efg") print('abc'+'efg') print('"abc"') print("'abc'") #字符串的多行输出 print('''abc''') print('''a b c d''') print( 阅读全文
posted @ 2018-01-20 20:35 善行无辙 阅读(157) 评论(0) 推荐(0)