当前位置: 首页 > 科技观察

7921星!是Python学习的必备法宝,随时查看和使用非常方便

时间:2023-03-13 05:37:10 科技观察

大多数备忘单都是简单的语法规则列表。近日,一个名为Python-cheatsheet的项目在HackerNews、Reddit、Github等网站上成功吸引了程序员的关注。Python-cheatsheet是一个超级全面的Python备忘单。最大的特点是无需安装和配置即可在线使用。内容非常全面。目前python-cheatsheet在Github上获得了7885个Stars和1572个Fork(Github地址:https://github.com/gto76/python-cheatsheet)榜首,整理了这部分内容。可以看到内容涵盖了:容器、类型、语法、系统、数据、库和高级Python等。只要点击相关知识点,就会跳转至相关详情页面。以Main和List为例Mainif__name__=='__main__':#Runsmain()iffilewasn'timported.main()List=[from_inclusive:to_exclusive:±step_size].append()#Or:+=[].extend()#Or:+=.sort().reverse()=sorted()=reversed()sum_of_elements=sum()elementwise_sum=[sum(pair)forpairinzip(list_a,list_b)]sorted_by_second=sorted(,key=lambdael:el[1])sorted_by_both=sorted(,key=lambdael:(el[1],el[0]))flatter_list=list(itertools.chain.from_iterable())product_of_elems=functools.reduce(lambdaout,x:out*x,)list_of_chars=list()index=.index()#ReturnsindexoffistroccurrenceorraisesValueError..insert(index,)#插入站点索引和movestheresttotherright。=.pop([index])#Removesandreturnssitematindexorfromtheend..remove()#RemovesfirstoccurrenceofitemorraisesValueError..clear()#Removesallitems.Alsoworksondictandset.整个文档基本上都是代码,只是个别内容会加上一些简短的文字说明。为了减轻用户的负担,用法创建者只给出最常用的用法,用最简洁的方式给你最需要的用法。如果不想在线使用本文档,也可以下载正文,下载地址:https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md项目地址:https://github.com/gto76/python-备忘单