随笔分类 - python
摘要:import re x=re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') print(x)
阅读全文
摘要:def scope_test(): def do_local(): spam = "local spam" def do_nonlocal(): nonlocal spam spam = "nonlocal spam" def do_global(): global spam spam...
阅读全文
摘要:import os with os.scandir(r"C:\Users\macname\Desktop") as it: for entry in it: if entry.name.startswith('Auto') and entry.is_file(): print(entry.name)
阅读全文
摘要:import os with os.scandir(r"C:\Users\macname\Desktop") as it: for entry in it: if not entry.name.startswith('Auto') and entry.is_file(): print(entry.name)
阅读全文
摘要:打印所有以.txt为结尾的文件名称
阅读全文
摘要:import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转化为字符串 # json_str = json.dumps(data) # fw.write(json_str) # 上面...
阅读全文
摘要:提示说是解码错误 可以用下面的方法判断json文件是否为空 但是在非空情况下会报错!!! 已解决!!!https://www.cnblogs.com/sea-stream/p/10011699.html
阅读全文
摘要:from datetime import date a = date(2001,2,18) b = date(2001,2,28) print(b-a)
阅读全文
摘要:d1 = {'a': 100, 'b': 200} d2 = {'x': 300, 'y': 200} d = d1.copy() d.update(d2) print(d)
阅读全文
摘要:my_dict = {'data1':100,'data2':-54,'data3':247} print(sum(my_dict.values()))
阅读全文
摘要:color_dict = {'red':'#FF0000', 'green':'#008000', 'black':'#000000', 'white':'#FFFFFF'} for key in sorted(color_dict): print("%s: %s" % (key, color_di...
阅读全文
摘要:myDict = {'a':1,'b':2,'c':3,'d':4} print(myDict) if 'a' in myDict: del myDict['a'] print(myDict)
阅读全文
摘要:def is_vowel(char): all_vowels = 'aeiou' return char in all_vowels print(is_vowel('c')) print(is_vowel('e'))
阅读全文
摘要:# Python program to convert decimal number into binary, octal and hexadecimal number system # Change this line for a different result dec = 344 print("The decimal value of",dec,"is:") print(bin(d...
阅读全文