摘要: 1、 >>> a = ("aaa","bbb","ccc","ddd","eee","fff") >>> type(a) <class 'tuple'> >>> id(a) 1360669254176 >>> a[2] = "xxx" Traceback (most recent call last 阅读全文
posted @ 2021-02-24 22:54 小鲨鱼2018 阅读(2292) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["aaa","bbb","ccc","ddd"] >>> a[1] = "xxx" ## 修改第二个元素 >>> a ['aaa', 'xxx', 'ccc', 'ddd'] >>> a[2:4] = ["mmm","nnn"] ## 修改第三和第四个元素 >>> a ['aaa 阅读全文
posted @ 2021-02-24 22:13 小鲨鱼2018 阅读(4469) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = 100 >>> b = 200 >>> print(a,b) 100 200 >>> print("the score is:",a) the score is: 100 >>> print(f"the score is:{a}") the score is:100 阅读全文
posted @ 2021-02-24 22:04 小鲨鱼2018 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aaa","bbb","aaa","aaa","bbb","aaa","ccc","ddd","ddd"] >>> b = [] >>> for i in a: if i not in b: b.append(i) >>> b ## for循环去重复 ['aaa', 'bb 阅读全文
posted @ 2021-02-24 21:59 小鲨鱼2018 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aaa","bbb","ccc","ddd"] >>> b = ["ccc","ddd","eee","fff"] >>> c = [] >>> for i in a: if i not in b: c.append(i) >>> c ['aaa', 'bbb'] >>> 阅读全文
posted @ 2021-02-24 21:45 小鲨鱼2018 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aaa","bbb","ccc","ddd"] >>> b = ["ccc","ddd","eee","fff"] >>> c = a + b >>> c ['aaa', 'bbb', 'ccc', 'ddd', 'ccc', 'ddd', &# 阅读全文
posted @ 2021-02-24 21:38 小鲨鱼2018 阅读(1180) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["aa","bb","aa","cc","aa","dd","bb","aa","cc"] >>> a ['aa', 'bb', 'aa', 'cc', 'aa', 'dd', 'bb', 'aa', 'cc'] > 阅读全文
posted @ 2021-02-24 10:51 小鲨鱼2018 阅读(2456) 评论(0) 推荐(0) 编辑
摘要: >>> sum = 0 >>> for i in range(1,101): ## 利用for循环 sum += i >>> print(sum) 5050 >>> del sum >>> sum(list(range(1,101))) ## 利用sum函数 5050 >>> sum = 0 >>> 阅读全文
posted @ 2021-02-24 10:44 小鲨鱼2018 阅读(3344) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = [20,10,50,40,30] >>> max = a[0] >>> for i in a: if i > max: max = i >>> print(max) 50 >>> min = a[0] >>> for i in a: if i < min: min = i >> 阅读全文
posted @ 2021-02-24 10:37 小鲨鱼2018 阅读(674) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["cc","aa","bb","cc","aa","dd","aa","cc","ee","dd"] >>> sorted(set(a)) ['aa', 'bb', 'cc', 'dd', 'ee'] >>> b = sorted(set(a 阅读全文
posted @ 2021-02-24 10:19 小鲨鱼2018 阅读(346) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = [34,28,187,22,128] >>> max = a[0] >>> for i in a: ## 求最大值 if i > max: max = i >>> print(max) 187 >>> min = a[0] >>> for i in a: ## 求最小值 if 阅读全文
posted @ 2021-02-24 10:11 小鲨鱼2018 阅读(5149) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["aa","aa","bb","cc","bb","aa","dd","cc","aa","aa","aa"] >>> a ['aa', 'aa', 'bb', 'cc', 'bb', 'aa', 'dd', &# 阅读全文
posted @ 2021-02-24 09:58 小鲨鱼2018 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = [] >>> b = ["aa","bb","cc"] >>> if len(a) == 0: print("empty!") empty! >>> if len(b) == 0: print("empty!") 2、 >>> a = ["aa","bb","cc","dd"] 阅读全文
posted @ 2021-02-24 09:37 小鲨鱼2018 阅读(4597) 评论(0) 推荐(0) 编辑
摘要: >>> import random >>> random.randint(1,10) ## 随机抽取1-10的数字 1 >>> random.randint(1,10) 4 >>> random.randint(1,10) 9 >>> random.randint(1,100) 67 >>> ran 阅读全文
posted @ 2021-02-24 09:26 小鲨鱼2018 阅读(61) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["aa","bb","cc","aa","dd","ee","aa","aa","ff","aa"] >>> a ['aa', 'bb', 'cc', 'aa', 'dd', 'ee', 'aa', 'aa',  阅读全文
posted @ 2021-02-24 09:22 小鲨鱼2018 阅读(892) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["aa","bb","cc","dd","ee"] >>> a ['aa', 'bb', 'cc', 'dd', 'ee'] >>> "aa" in a True >>> "dd" in a True >>> "aa" not in a False & 阅读全文
posted @ 2021-02-24 09:15 小鲨鱼2018 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aa","bb","cc","dd","ee"] >>> temp = a[1] ## 引入变量 >>> temp 'bb' >>> a[1] = a[3] >>> a ['aa', 'dd', 'cc', 'dd', 'ee'] >>> a[3] = temp > 阅读全文
posted @ 2021-02-24 09:13 小鲨鱼2018 阅读(4077) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["ee","cc","aa","ff","aa","cc","dd","ee","dd","ee","aa","aa","bb"] ##生成列表 >>> a ['ee', 'cc', 'aa', 'ff', 'aa 阅读全文
posted @ 2021-02-24 08:31 小鲨鱼2018 阅读(377) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = ["aa","cc","aa","bb","bb","aa","dd","ee"] >>> a ['aa', 'cc', 'aa', 'bb', 'bb', 'aa', 'dd', 'ee'] >>> "aa" in 阅读全文
posted @ 2021-02-24 08:22 小鲨鱼2018 阅读(119) 评论(0) 推荐(0) 编辑
摘要: >>> a = ["dd","cc","aa","bb"] >>> a ['dd', 'cc', 'aa', 'bb'] >>> b = sorted(a) ## 排序并赋值给b >>> b ['aa', 'bb', 'cc', 'dd'] >>> a ['dd', 'cc&# 阅读全文
posted @ 2021-02-24 08:18 小鲨鱼2018 阅读(233) 评论(0) 推荐(0) 编辑