41-字符串格式化 "%s is %s years old" % ('bob', 23) # 常用"%s is %d years old" % ('bob', 23) # 常用"%s is %d years old" % ('bob', 23.5) # %d是整数 常用"%s is %f years old" % ('bob', 23.5)"%s is %5.2f years ol
21-while-break break是结束循环,break之后、循环体内代码不再执行。 while True:yn = input('Continue(y/n): ')if yn in ['n', 'N']:breakprint('running...') 22-while-continue 计算100以内偶数之和。 continue是跳过本次循环剩余部分,回到循环条件处。 sum
11-条件表达式、三元运算符 a = 10b = 20if a < b:smaller = aelse:smaller = bprint(smaller)s = a if a < b else b # 和上面的if-else语句等价print(s) 12-判断练习:用户名和密码是否正确 import getpass # 导入模块username = input('username: