python 笔记
python判断变量是否为数字
>>> a = "03523" >>> a.isdigit() True >>> b = "963spam" >>> b.isdigit() False
https://www.decalage.info/en/python/print_list key 在dict 判断 if 'key1' in dict: print "blah" else: print "boo" python 文件读写 file = open(“testfile.txt”,”w”) file.write(“Hello World”) Convert a List Into a Set fruit = [ banana, orange, pineapple ] set(fruit) >>> a = set(["Blah", "Hello"]) >>> a = list(a) # You probably wrote a = list(a()) here or list = set() above >>> a ['Blah', 'Hello'] set 遍历 weekdays = set(['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']) for d in weekdays: print (d)
isset
# 判断是否在dict中 d = {} d["a"] = 11 d["b"] = 22 if "a" in d : print "sss" sst = set([2,3,4] ) # 遍历set for e in sst : print e # 判断是否在set if 20 in sst: print"20 in sst " else: print " 20 not in sst"
浙公网安备 33010602011771号