Python Syntax
- 格式化输出 –
format
函数的使用Python format 函数的详细用法 | cnblogs
(C++ Syntax:printf 详解 | CSDN)
-
别名,浅拷贝与深拷贝:
Using equal sign & function argument pass between mutable objects creates aliases.
Shallow copy creates a copy of a list, not just a shared pointer, but only at the top level of the list.
But if we change an element in one of the sub-structures, they are shared!
Unless your elements are not mutable, then this is not a problem.
Usedeepcopy when your list might have mutable elements to ensure every structure at every level is copied
- 函数的参数
In the function definition, default parameters must go at the end.
Positional arguments shall precede keyword arguments to locate themselves.
- 原码,反码,补码:原码、反码、补码 – 知乎
-
try & except & else & finally & raise & assertion: 见 SI 100B Lecture 09 page 45-47
try: # some code except: # do this if some error occurred # maybe print("Error!") # or you can raise Errortype("Some error information") # Errortype can be TypeError,NameError,etc. else: # do this if no error occurred # maybe print("Success!") finally: # do this no matter what happened, even a return or break or continue was executed # this is another way of defensive coding: assert <statement that should be true>, "message if not true"
- dictionary: Assume there is no order to keys or values! Keys must be unique!
- Dunder Methods(类似于重载运算符,指重设一些本来就存在的函数使其具有新的意义)
orz