Python 综合手册

MicroPython相关代码、库、软件、工具
回复
头像
shaoziyang
帖子: 3973
注册时间: 2019年 10月 21日 13:48

Python 综合手册

#1

帖子 shaoziyang »

图片


Main

代码: 全选

if __name__ == '__main__': # Runs main() if file wasn't imported.
main()
 List

代码: 全选

<list> = <list>[<slice>] # Or: <list>[from_inclusive : to_exclusive : ±step

代码: 全选

<list>.append(<el>;) # Or: <list> += [<el>]
<list>.extend(<collection>;) # Or: <list> += <collection>

代码: 全选

<list>.sort() # Sorts in ascending order.
<list>.reverse() # Reverses the list in-place.
<list> = sorted(<collection>;) # Returns a new sorted list.
<iter> = reversed(<list>;) # Returns reversed iterator.

代码: 全选

sum_of_elements = sum(<collection>;)
elementwise_sum = [sum(pair) for pair in zip(list_a, list_b)]
sorted_by_second = sorted(<collection>, key=lambda el: el[1])
sorted_by_both = sorted(<collection>, key=lambda el: (el[1], el[0]))
flatter_list = list(itertools.chain.from_iterable(<list>;))
product_of_elems = functools.reduce(lambda out, el: out * el, <collection>;)
list_of_chars = list(<str>;)
  • For details about sorted(), min() and max() see sortable.
  • Module operator provides functions itemgetter() and mul() that offer the same functionality as lambda expressions above.
 完整内容:

https://gto76.github.io/python-cheatsheet
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章