本文共 2330 字,大约阅读时间需要 7 分钟。
Python ????????????????????????????????Python ????????????????????????????????????????? Python ?????????????????????
??? Python ????????????? else ?? if ????????else ???? for??????for-else ????????????????????
for i in [1,2,3,4]: print(i, "??else")else: print("??else")
?????1 ??else2 ??else3 ??else4 ??else??else
????????????????????????break?????else???
???????? Python ???????? (*) ????????????? (**) ????????????????
def multi_sum(*args): s = 0 for item in args: s += item return smulti_sum(3,4,5) # ??12
???????????????????????????????????????
def do_something(name, age, gender='?', *args, **kwds): print("??? %s????%d????%s" % (name, age, gender)) print(args) print(kwds)
?????? Python ???????????????????????expression if condition else expression
????
y = 5print("y?????" if y < 0 else "y??????")
?????y??????
??????????????????????????
with ??????????????????? with ??????????????????????
with open(r"D:\CSDN\Column\temp\mpmap.py", 'r') as fp: contents = fp.readlines()
???????? try-finally ??????????????
?????????????????????????????????????????????
a = [1,2,3,4,5]result = [i*i for i in a]
???????? for ????????????????
Python ????????????????????????????
a = [0,1,2,3,4,5]a[2:4] # [2,3]a[3:] # [3,4,5]a[1:] # [1,2,3,4,5]a[:] # [0,1,2,3,4,5]
??????????????????????????????
lambda ??????????????????????
lambda x, y: x + y
???????????????????????????????
yield ???????????????????????????????????
def get_square(n): for i in range(n): yield pow(i,2)
???????????????????????????
????????????????????????????????????
import timedef timer(func): def wrapper(*args, **kwds): t0 = time.time() func(*args, **kwds) t1 = time.time() print('??%0.3f' % (t1-t0,)) return wrapper
???????????????????????????
?? assert ??????????????????
def i_want_to_sleep(delay): assert isinstance(delay, (int, float)), '?????????????' print('????') time.sleep(delay) print('???')
?????????????????????????????
Python ?????????????????????????????????????????????????????????????????????????? Python ??????????????????????????
转载地址:http://qesy.baihongyu.com/