您当前的位置: 首页 >  Python

CheatSheet:Python快速参考

彭世瑜 发布时间:2018-05-18 19:31:30 ,浏览量:3

Python sys Variables 变量说明argvCommand line argsbuilti­n_m­odu­le_­namesLinked C modulesbyteorderNative byte orderexec_p­refixRoot directoryexecutableName of executablemodulesLoaded modulespathSearch pathplatformCurrent platformstdin, stdout, stderrFile objects for I/Oversio­n_infoPython version infoversionVersion number Python sys.argv

sys.argv for the command:

$ python foo.py bar -c qux --h
变量值sys.ar­gv[0]foo.pysys.ar­gv[1]barsys.ar­gv[2]-csys.ar­gv[3]quxsys.ar­gv[4]–h Python os Variables 方法说明altsepAltern­ative sepcurdirCurrent dir stringdefpathDefault search pathdevnullPath of null deviceextsepExtension separatorlinesepLine separatornameName of OSpardirParent dir stringpathsepPatch separatorsepPath separator

Registered OS names: “­pos­ix”, “­nt”, “­mac­”, “­os2­”, “­ce”, “­jav­a”, “­ris­cos­”

Python Class Special Methods 方法说明_new­_(cls)init­(­self, args)_del­_(self)_str­_(self)repr­(­self)lt­(self, other)le­(self, other)gt­(self, other)ge­(self, other)eq­(self, other)ne­(self, other)_cmp­_(self, other)inde­x­(self)nonz­ero­(­self)hash­(­self)geta­ttr­(­self, name)_geta­ttr­ibu­te­_(self, name)seta­ttr­(­self, name, attr)dela­ttr­(­self, name)call­(­self, args, kwargs) Python List Methods 方法说明append­(item)pop(po­sition)count(­item)remove­(item)extend­(list)reverse()index(­item)sort()insert­(po­sition, item) Python String Methods 方法说明decode()encode()count(sub, start, end)index(sub, start, end)rindex­(sub, start, end)find(sub, start, end)rfind(sub, start ,end)starts­wit­h(sub)endswi­th(sub)center­(width)rjust(­width)ljust(­width)zfill(­width)expand­tabs()strip()lstrip()rstrip()split(sep)rsplit­(sep)splitl­ines()partit­ion­(sep)rparti­tio­n(sep)join()swapcase() *capita­lize() *title() *transl­ate­(table)lower() *upper() *replac­e(old, new)isdigit() *isalnum() *isspace() *istitle() *islower() *isupper() *isalpha() *

Methods marked * are locale dependant for 8-bit strings.

Python File Methods 方法说明close()readli­nes­(size)flush()seek(o­ffset)fileno()tell()isatty()trunca­te(­size)next()write(­string)read(size)writel­ine­s(list)readli­ne(­size) Python Indexes and Slices
Indexes and Slices of a=[0,1­,2,­3,4,5]
操作结果len(a)6a[0]0a[5]5a[-1]5a[-2]4a[1:][1,2,3­,4,5]a[:5][0,1,2­,3,4]a[:-2][0,1,2,3]a[1:3][1,2]a[1:-1][1,2,3,4]b=a[:]Shallow copy of a Python Datetime Methods 操作结果today()fromor­din­al(­ord­inal)now(ti­mez­one­info)combin­e(date, time)utcnow()strpti­me(­date, format)fromti­mes­tam­p(t­ime­stamp)utcfro­mti­mes­tam­p(t­ime­stamp) Python Time Methods 操作结果replace()utcoff­set()isofor­mat()dst()str()tzname()strfti­me(­format) Python Date Formatting 字符说明%aAbbrev­iated weekday (Sun)%AWeekday (Sunday)%bAbbrev­iated month name (Jan)%BMonth name (January)%cDate and time%dDay (leading zeros) (01 to 31)%H24 hour (leading zeros) (00 to 23)%I12 hour (leading zeros) (01 to 12)%jDay of year (001 to 366)%mMonth (01 to 12)%MMinute (00 to 59)%pAM or PM%SSecond (00 to 61⁴)%UWeek number¹ (00 to 53)%wWeekday² (0 to 6)%WWeek number³ (00 to 53)%xDate%XTime%yYear without century (00 to 99)%YYear (2008)%ZTime zone (GMT)%%A literal “­%” character (%)

¹ Sunday as start of week. All days in a new year preceding the first Sunday are considered to be in week 0. ² 0 is Sunday, 6 is Saturday. ³ Monday as start of week. All days in a new year preceding the first Monday are considered to be in week 0. ⁴ This is not a mistake. Range takes account of leap and double­-leap seconds.

pdf下载

参考

  1. 原文 - Python Cheat Sheet by DaveChild
  2. Python 速查表
关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.2955s