11 2021 档案

摘要:为了保证程序的健壮性与容错性,即在遇到错误时候程序不会崩溃,我们需要对异常进行处理, 1.如果错误发生的条件是可预知的,我们需要用if进行处理,在错误发生之前进行预防 AGE=10 while True: age=input('>>: ').strip() if age.isdigit(): #只有 阅读全文
posted @ 2021-11-26 16:10 小小程序员ol 阅读(188) 评论(0) 推荐(0) 编辑
摘要:普通方法 类方法(@classmethod) 静态方法(@staticmethod) 普通方法 创建普通的方法的方式有两种(class A() & class B()). class A(): def __init__(self, name, age): self.name = name self. 阅读全文
posted @ 2021-11-23 16:02 小小程序员ol 阅读(700) 评论(0) 推荐(0) 编辑
摘要:1. 使用while循环输出1 2 3 4 5 6 8 9 10 count=0 while count <10: count+=1 print(count) 2. 求1-100的所有数的和 count=0 total=0 #定义两个变量 while count <=100: total +=cou 阅读全文
posted @ 2021-11-15 21:32 小小程序员ol 阅读(1096) 评论(0) 推荐(0) 编辑
摘要:一. pprint美观打印数据结构 pprint模块包含一个“美观打印机”,用于生成数据结构的一个美观的视图。格式化工具会生成数据结构的一些表示,不仅能够由解释器正确地解析,还便于人阅读。输出会尽可能放在一行上,分解为多行时会缩进。 1.打印 from pprint import pprint da 阅读全文
posted @ 2021-11-11 21:22 小小程序员ol 阅读(674) 评论(0) 推荐(0) 编辑
摘要:1.使用 for key in dict 遍历字典 可以使用for key in dict遍历字典中所有的键 x = {'a': 'A', 'b': 'B'} for key in x: print(key) # 输出结果 a b 2.使用 for key in dict.keys () 遍历字典的 阅读全文
posted @ 2021-11-04 21:19 小小程序员ol 阅读(3465) 评论(0) 推荐(1) 编辑

点击右上角即可分享
微信分享提示