上一页 1 ··· 327 328 329 330 331 332 333 334 335 ··· 375 下一页
摘要: 1、>>> a = ["aa","bb","cc","dd"] ## 生成列表 >>> a ['aa', 'bb', 'cc', 'dd'] >>> a = [] ## 清空列表 >>> a []2、 >>> a = ["aa","bb","cc","dd"] ## 生成列表 > 阅读全文
posted @ 2021-02-23 22:25 小鲨鱼2018 阅读(449) 评论(0) 推荐(0) 编辑
摘要: >>> a = list(range(1,21)) ## 生成列表 >>> a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> a[::2] ## 提取第奇数元素 [1, 3, 5, 7, 9, 阅读全文
posted @ 2021-02-23 22:22 小鲨鱼2018 阅读(7872) 评论(0) 推荐(0) 编辑
摘要: >>> a = list(range(1,21)) ##生成列表 >>> a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> a[:10] ## 提取前10个元素 [1, 2, 3, 4, 5, 阅读全文
posted @ 2021-02-23 22:19 小鲨鱼2018 阅读(17605) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aaa","bbb","ccc","ddd"] >>> b = reversed(a) >>> c = [] >>> for i in b: c.append(i) >>> c ['ddd', 'ccc', 'bbb', 'aaa'] 2、 >>> a = ["aaa"," 阅读全文
posted @ 2021-02-22 17:54 小鲨鱼2018 阅读(457) 评论(0) 推荐(0) 编辑
摘要: 1、 aaa = "123" answer = input("please input the answer:") while True: if answer == aaa: break answer = input("please input the answer,again:") print(" 阅读全文
posted @ 2021-02-16 19:38 小鲨鱼2018 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 1、for 循环 >>> sum = 0 >>> for i in range(101): sum += i >>> print(sum) 5050 2、while循环 >>> sum = 0 >>> i = 0 >>> while i <= 100: sum += i i += 1 >>> pri 阅读全文
posted @ 2021-02-15 22:07 小鲨鱼2018 阅读(5122) 评论(0) 推荐(0) 编辑
摘要: 1、 # prize test age = 20 score = "A" if age < 18: if score == "A": print("congratulations!!!") else: print("score not A!!!") else: print("age excess 1 阅读全文
posted @ 2021-02-06 23:06 小鲨鱼2018 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 1、assert可以植入程序中进行程序检查 >>> a = 5 >>> b = 3 >>> assert a > 0 >>> assert a < 0 Traceback (most recent call last): File "<pyshell#279>", line 1, in <modul 阅读全文
posted @ 2021-02-06 23:02 小鲨鱼2018 阅读(354) 评论(0) 推荐(0) 编辑
摘要: 1、 #guess integer game import random secret = random.randint(1,10) temp = input("please input an integer:") guess = int(temp) times = 1 while (guess ! 阅读全文
posted @ 2021-02-06 20:38 小鲨鱼2018 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> import random >>> random.randint(1,5) 1 >>> random.randint(1,5) 4 >>> random.randint(1,5) 3 >>> random.randint(1,5) 2 >>> random.randint(10,20) 阅读全文
posted @ 2021-02-06 20:03 小鲨鱼2018 阅读(389) 评论(0) 推荐(0) 编辑
上一页 1 ··· 327 328 329 330 331 332 333 334 335 ··· 375 下一页