随笔分类 - python
摘要:>>> test1 = ["aaa","bbb","ccc","ddd"] >>> test2 = [111,222,333,444] >>> test3 = {} >>> for i in zip(test1,test2): test3[i[0]]=i[1] >>> test3 {'aaa': 1
阅读全文
摘要:>>> test1 = [100,300,500,1000] >>> test2 = [350,550,300,350] >>> for i in zip(test1,test2): i[0] + i[1] 450 850 800 1350
阅读全文
摘要:>>> test1 = dict(key1="xx",key2="yy",key3="aa",key4="bb",key5="cc",key6="dd") >>> type(test1) <class 'dict'> >>> len(test1) 6 >>> test2=["key3","key5"
阅读全文
摘要:>>> test1 = dict(key8="ccc",key3="ete",key2="iii",key4 = "wwww") >>> type(test1) <class 'dict'> >>> len(test1) 4 >>> for i,j in test1.items(): print(i
阅读全文
摘要:1、 >>> test1 = dict(key1="xxx",key2="aaa",key3=100,key="abc") >>> test1 {'key1': 'xxx', 'key2': 'aaa', 'key3': 100, 'key': 'abc'} >>> type(test1) <cla
阅读全文
摘要:>>> test1 = {"zhangsan":["java","c","python"],"lisi":["c++","golang"],"wangwu":["c","java","python","javascript"]} >>> type(test1) <class 'dict'> &g
阅读全文
摘要:1、 >>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","eee"] >>> test2 = [] >>> for i in test1: if i not in test2: test2.append(i) >>> test2 ['aaa
阅读全文
摘要:>>> test1 = {"key8":"aaa","key4":"bbb","key9":"ccc","key3":"ddd","key2":"eee"} >>> for i in test1.keys(): print(i) key8 key4 key9 key3 key2 >>> for i
阅读全文
摘要:>>> test1 = {"key1":"aa","key2":"bb","key3":"cc","key4":"dd","key5":"ee","key6":"ff","key7":"gg"} >>> type(test1) <class 'dict'>
阅读全文
摘要:>>> test1 = {"key1":"aa","key2":"bb","key3":"cc","key4":"dd","key5":"ee","key6":"ff","key7":"gg"} >>> type(test1) <class 'dict'>
阅读全文
摘要:>>> test1 = ["aaa","bbb","ccc","ddd","eee","fff","ggg"] >>> for i in test1: test1.remove(i) >>> test1 ['bbb', 'ddd', 'fff']
阅读全文
摘要:一、 >>> test1 = ["ccc","ddd","mmm"] >>> if test1: for i in test1: print(i) else: print("empty list") ccc ddd mmm >>> test1 = [] >>> if test1: for i in
阅读全文
摘要:1、条件成立执行 >>> a = 50 >>> if a > 10: print("xxx") xxx >>> if a < 10: print("yyy") >>> if a == 50: print("zzz") zzz score = int(input("score=")) if 100 >
阅读全文
摘要:zip()用于返回各个可迭代对象共同组成的元组。 >>> test1=["ccc","aaa","ddd","yyy","xxx"] >>> test2=(200,100,400,800,500) >>> test3="daceb" >>> for i in zip(test1,test2,test
阅读全文
摘要:用于生成二元组。 >>> test1 = ["xxx","yyy","ddd","ccc","aaa"] >>> enumerate(test1) <enumerate object at 0x000001C1224ED780> >>> test2=enumerate(test1) >>> type
阅读全文
摘要:>>> test1 = ["sss","ccc","aaa","ddd"] >>> test1.reverse() ## 就地反转 >>> test1 ['ddd', 'aaa', 'ccc', 'sss'] >>> test1.reverse() >>> test1 ['sss', 'ccc',
阅读全文
摘要:>>> test1 = ["ccc","aaa","aaa","ccc","bbb","aaa","ddd","aaa"] >>> test1.count("aaa") 4 >>> for i in range(test1.count("aaa")-1): test1.remove("aaa") >
阅读全文
摘要:1、求最大值和最小值 >>> test1 = [34,2,5,65,322,21,54] >>> temp = test1[0] >>> for i in test1: if i > temp: temp=i >>> temp 322 >>> for i in test1: if i < temp:
阅读全文
摘要:1、 + 号拼接 >>> test1 = "abcd" >>> test2 = "opqr" >>> test3 = "xyzh" >>> test1 + test2 'abcdopqr' >>> test2 + test3 'opqrxyzh' >>> test2 + test1 + test3
阅读全文
摘要:1、format()位置参数 >>> "abcdabdef".format() 'abcdabdef' >>> "abc{0}dabdef".format("YYYY","MMMM","OOOO") 'abcYYYYdabdef' >>> "abc{1}dabdef".format("YYYY","
阅读全文

浙公网安备 33010602011771号