摘要: bool 判断True或是False bool值为0的有 None, 0, 0.0, 空字符串,空空列表, 空元组, 空集合, 空字典 print(2 and 2) # 2 print(bool(2 and 2)) # True and,or and 有假为假 or 有真为真 and 优先级高于or 阅读全文
posted @ 2022-06-10 00:57 淫鬻 阅读(46) 评论(0) 推荐(0) 编辑
摘要: dict中的get函数 dict.get('值',None) get函数需要有一个变量接受 一般用来判断值是否存在,若不存在则返回None None可以自定义为字符串,数字 dic = {"amd": "yes", "intel": "yyds"} ret = dic.get('amd', None 阅读全文
posted @ 2022-06-10 00:45 淫鬻 阅读(98) 评论(0) 推荐(0) 编辑
摘要: python 列表中的items函数 用来遍历字典中的键值对 使用for i in dict.items时,遍历出来的i是tuple类型 使用for m,n in dict.items时,遍历出来的m,n为str类型 dic = {"amd": "yes", "intel": "yyds"} for 阅读全文
posted @ 2022-06-10 00:41 淫鬻 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 使用脚本,复制start.txt内容,粘贴到end.txt中 from sys import argv from os.path import exists script, from_file, to_file = argv print("Copying from %s to %s." % (fro 阅读全文
posted @ 2022-06-10 00:30 淫鬻 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 对txt文件进行写入 写入之前需要对文件内容进行truncate擦除 input 要写入的内容 write进行写入操作 from sys import argv # script是py文件,用于对txt文件 script, filename = argv # 提示擦除filename里面的内容, p 阅读全文
posted @ 2022-06-10 00:26 淫鬻 阅读(19) 评论(0) 推荐(0) 编辑
摘要: # 导入argvfrom sys import argv script, filename = argv # 打开文件 txt = open(filename) print("Here's your file %r" % filename) # 打印出文件内容 print(txt.read()) c 阅读全文
posted @ 2022-06-10 00:23 淫鬻 阅读(25) 评论(0) 推荐(0) 编辑