learn the python the hard way习题26~30总结

考试试题26错误总结:

  1. 漏写字母,括号
  2. 写错字母
  3. write(),read()的使用:只能打开使用了 open() 后返回的文件对象(file object),而不能直接使用文件名
  4. if 语句中,条件后有冒号

逻辑关系表达式注意的点

  1. != 和 <> 的意义是相同的,!=是主流用法。
  2. Python 中有短路逻辑
  3. 如果被操作被操作对象中含有 True 或者 False 之外的字符串,那么,布尔表达式返回两个被操作对象的一个,例如:"test" and "test" 返回 "test";1 and 1返回1

if语句,else语句,elif语句

格式:if people>dogs:
print("There are too many dogs")
注意:

  • 在条件后有冒号
  • 在代码块前有4个空格的缩进
  • else,elif, 语句用于二分支和多分支的情况





原文地址:https://www.cnblogs.com/FBsharl/p/10170978.html