摘要:
1、 >>> a = ("aaa","bbb","ccc","ddd","eee","fff") >>> type(a) <class 'tuple'> >>> id(a) 1360669254176 >>> a[2] = "xxx" Traceback (most recent call last 阅读全文
摘要:
>>> a = ["aaa","bbb","ccc","ddd"] >>> a[1] = "xxx" ## 修改第二个元素 >>> a ['aaa', 'xxx', 'ccc', 'ddd'] >>> a[2:4] = ["mmm","nnn"] ## 修改第三和第四个元素 >>> a ['aaa 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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'] >>> 阅读全文
摘要:
1、 >>> a = ["aaa","bbb","ccc","ddd"] >>> b = ["ccc","ddd","eee","fff"] >>> c = a + b >>> c ['aaa', 'bbb', 'ccc', 'ddd', 'ccc', 'ddd', 阅读全文
摘要:
>>> a = ["aa","bb","aa","cc","aa","dd","bb","aa","cc"] >>> a ['aa', 'bb', 'aa', 'cc', 'aa', 'dd', 'bb', 'aa', 'cc'] > 阅读全文
摘要:
>>> 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 >>> 阅读全文
摘要:
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 >> 阅读全文
摘要:
1、 >>> a = ["cc","aa","bb","cc","aa","dd","aa","cc","ee","dd"] >>> sorted(set(a)) ['aa', 'bb', 'cc', 'dd', 'ee'] >>> b = sorted(set(a 阅读全文
摘要:
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 阅读全文
摘要:
>>> a = ["aa","aa","bb","cc","bb","aa","dd","cc","aa","aa","aa"] >>> a ['aa', 'aa', 'bb', 'cc', 'bb', 'aa', 'dd', 阅读全文
摘要:
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"] 阅读全文
摘要:
>>> 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 阅读全文
摘要:
>>> a = ["aa","bb","cc","aa","dd","ee","aa","aa","ff","aa"] >>> a ['aa', 'bb', 'cc', 'aa', 'dd', 'ee', 'aa', 'aa', 阅读全文
摘要:
>>> 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 & 阅读全文
摘要:
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 > 阅读全文
摘要:
>>> a = ["ee","cc","aa","ff","aa","cc","dd","ee","dd","ee","aa","aa","bb"] ##生成列表 >>> a ['ee', 'cc', 'aa', 'ff', 'aa 阅读全文
摘要:
1、 >>> a = ["aa","cc","aa","bb","bb","aa","dd","ee"] >>> a ['aa', 'cc', 'aa', 'bb', 'bb', 'aa', 'dd', 'ee'] >>> "aa" in 阅读全文
摘要:
>>> a = ["dd","cc","aa","bb"] >>> a ['dd', 'cc', 'aa', 'bb'] >>> b = sorted(a) ## 排序并赋值给b >>> b ['aa', 'bb', 'cc', 'dd'] >>> a ['dd', 'cc 阅读全文