随笔分类 - python
摘要:1、以字符串为中心进行补充 >>> test1="ab" >>> len(test1) 2 >>> test1.center(10," ") ' ab ' >>> test2=test1.center(10," ") >>> len(test2) 10 >>> test2=test1.center(
阅读全文
摘要:>>> test1 = ("aaa","bbb","ccc","ddd","eee","fff","ggg") >>> type(test1) <class 'tuple'> >>> test2 = test1[:4] >>> test2 ('aaa', 'bbb', 'ccc', 'ddd')
阅读全文
摘要:>>> test1 = [3,5,1,9,2,7,4] >>> type(test1) <class 'list'> >>> len(test1) 7 >>> min(test1) 1 >>> max(test1) 9 >>> sum(test1) 31 >>> sum(test1) / len(t
阅读全文
摘要:>>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(1,10)) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(1,11)) [1, 2, 3, 4, 5, 6, 7, 8, 9,
阅读全文
摘要:1、永久排序 >>> test1 = ["ccc","ddd","aaa","bbb"] >>> test2 = test1[:] >>> test1 ['ccc', 'ddd', 'aaa', 'bbb'] >>> test2 ['ccc', 'ddd', 'aaa', 'bbb'] >>> te
阅读全文
摘要:>>> test1 = ["aaa","bbb","aaa","ccc","aaa","aaa","ddd","aaa","ccc"] >>> test1.index("aaa") ## 返回元素的首个索引 0 >>> test1.index("bbb") 1 >>> test1.index("c
阅读全文
摘要:>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","aaa","ddd","eee","ddd"] >>> test1.count("aaa") ## 统计指定元素出现的次数 4 >>> test1.count("bbb")
阅读全文
摘要:>>> test1 = ["aaa","bbb","ccc","ddd","eee","fff"] >>> test2 = ["ddd","eee","fff","ggg","hhh","iii"] >>> test3 = test1 + test2 >>> test3 ['aa
阅读全文
摘要:>>> test1 = ["aaa","bbb","ccc","aaa","aaa","bbb","ddd","eee"] >>> test2 = [] >>> for i in test1: if i not in test2: test2.append(i) >>> test2 ['aaa',
阅读全文
摘要:>>> test1 ['aaa', 'bbb', 'ccc'] >>> "aaa" in test1 True >>> "ddd" in test1 False >>> "ccc" in test1 True >>> "ddd" not in test1 True >>> "aaa" not in
阅读全文
摘要:1、基本用法 >>> test1 = ["aa","bb","cc","dd","ee","ff"] >>> type(test1) <class 'list'> >>> len(test1) 6 >>> test1[0:3] ## 不包含索引为3的元素 ['aa', 'bb', 'cc'] >>>
阅读全文
摘要:1、循环 >>> test1 = ["aa","bb","cc","dd","ee","ff","gg"] >>> test1 ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg'] >>> test2 = [] >>> test2 [] >
阅读全文
摘要:1、for循环 >>> test1 = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn"] >>> type(test1) <class 'list'> >&
阅读全文
摘要:>>> test = ["aaa","bbb","ccc","ddd"] >>> type(test) <class 'list'> >>> len(test) 4 >>> test.pop() ## pop弹出 'ddd' >>> test ['aaa', 'bbb', 'ccc'] >>> te
阅读全文
摘要:>>> prizes = ["aaa","bbb","ccc","ddd","eee"] >>> import random >>> for i in range(1,11,1): ## 设计抽十次 print(f"The {i}th prize is {random.choice(prizes)}
阅读全文
摘要:>>> range(10) range(0, 10) >>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(0,10,2)) [0, 2, 4, 6, 8] >>> list(range(0,10,3)) [0, 3, 6
阅读全文
摘要:>>> test1 = ["aaa","bbb","ccc","ddd"] >>> type(test1) <class 'list'> >>> len(test1) 4 >>> test1[0] ## 查看第一个元素 'aaa' >>> test1[2] 'ccc' >>> test1[-1] #
阅读全文
摘要:>>> test1 = ["aaa","bbb","ccc"] >>> type(test1) <class 'list'> >>> len(test1) 3 >>> test1.append("xxx") ## 追加 >>> test1 ['aaa', 'bbb', 'ccc', 'xxx'] >
阅读全文
摘要:>>> 5 > 3 and 5 > 4 True >>> 5 > 3 and 5 > 6 False >>> 5 > 3 or 5 < 4 True >>> 5 > 7 or 5 > 6 False >>> not 0 True >>> not 1 False >>> not 2 False >>>
阅读全文
摘要:>>> 3 > 5 False >>> 3 >= 5 False >>> 3 < 5 True >>> 3 == 5 False >>> 3 != 5 True >>> 3 <= 5 True
阅读全文

浙公网安备 33010602011771号