Python core
1. REPL: Read, Evaluate, Print, Loop
2. int REPL, type _ to most recently printed value, only in REPL
3. 在REPL里输入多行:

4. PEPs: Python Enhancement Proposals

5. Zen of Python

6. import a library and use help to show the functions in the library, type q to quit the help and return to REPL

7. 给函数起个别名

8. / and //

9. type int: unlimited precision signed integer

int函数的第二个参数是进制,比如上面的例子,3表示3进制,10表示10进制
10. float type: IEEE-754 double-precision with 53-bits of binary precision, 15-16 significant digits in decimal

11. None value

12. Boolen value

13. Relational Operators

14. Control Flow

15. while and break

16. Augmented (增强) assignment operators: -=, +=
17. str

18. Universal Newlines: Python translates \n to the appropriate newline sequence for your platform
PEP 278
19. Escape character \


20. create a row string with prefix r

21. convert from int or float to str use str(), Strings in python are called sequence types

22. str functions

23. unicode

24. Bytes: 与str类似,但是是单字节的

25. Convert with encode and decode


26. list

27. dict, Map keys to values

28. for loop

29. example of read data from url

30. 执行一个python文件

import一个文件

31. define a function

32: dunder: instead of "underscore underscore name underscore underscore" we say "dunder name", __name__
33. import a module and run a function, 注意:import只会被执行一次

34. import a function only

35. __name__,可以区分modle是在被引用,还是被脚本执行



如果是在脚本中运行,就执行函数

36. import


37. use command argument


38. docstring




add more docstring


39. run .py file directly, which called Shebang in linux


40. id()


41.

42. == and is, == means same value


43. pass parameter to function, 感觉像传的引用






44. Default argument values

45. Default argument 的值没有变,因为default value只在def被执行时运行一次,所以不要使用会变的default value


46. Modifying Mutable Default values



workaround of above example

47. dynamic types

48.


49. Scopes in python

50. rebinding global names


51. everything is object

52. tuple: Immutable sequences of arbitrary objects

53. return a tuple

54. tuple unpacking



55. convert to tuple use tuple(), and test if element in the tuple

56. string

57. join


58. partition

有的系统里会使用_来保存分隔符,使用_的好处是可以避免variable not used的警告

59. string format

60. f-string


61. range

62


63. list

64. copy list, all of these techniques perform shallow copies. 对象里的子对象还是只是copy了引用



65. 复制list中的子项

66. index

67. delete element from list

68. insert element

69. 一些操作

70. reverse and sort


71. reverse and sort with copy

72. Dictionaries


73. create dictionary

74. copy dictionary

75. dictionary update

76. dictionary iteration

by value

by key

每个item都是一个tuple

77. in and out

78. delete element

79. update element

80. 使用pprint更好的显示

81. set


set会删除冗余项

82. set 中item的顺序是任意的

83. in and not in also working for set

84. add and update set

85. remove and discard

86. copy a set

87. Set Algebra




88. 没有同时出现在两个set里

89. subset, superset or 没有交集

90. Protocols


91. exception


92. example to cause exception


93. add exception handling


another exception

make update


updated version

因为block不允许为空,所以可以用pass作为占位符

update again


94. Re-raising Exceptions




95. example to calculate sqrt


96. cause a exception and handle it


97.



98. Exceptions and protocols

99. common exception



100. LBYL vs. EAFP


use EAFP

101. use finally:


102: 捕获每一次按键和平台相关



浙公网安备 33010602011771号