CheatSheet:Python快速参考

简介: CheatSheet:Python快速参考

Python sys Variables

a12.1.png


Python sys.argv

sys.argv for the command:

$ python foo.py bar -c qux --h

a12.2.png


Python os Variablesa12.3.png

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

Python Class Special Methods

a12.4.png

Python List Methods

a12.6.png

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)

6

a[0]

0

a[5]

5

a[-1]

5

a[-2]

4

a[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 Method

操作

结果

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()

 

utcoffset()

 

isoformat()

 

dst()

 

str()

 

tzname()

 

strftime(format)


Python Date Formattin

字符

说明

%a

Abbrev­iated weekday (Sun)

%A

Weekday (Sunday)

%b

Abbrev­iated month name (Jan)

%B

Month name (January)

%c

Date and time

%d

Day (leading zeros) (01 to 31)

%H

24 hour (leading zeros) (00 to 23)

%I

12 hour (leading zeros) (01 to 12)

%j

Day of year (001 to 366)

%m

Month (01 to 12)

%M

Minute (00 to 59)

%p

AM or PM

%S

Second (00 to 61⁴)

%U

Week number¹ (00 to 53)

%w

Weekday² (0 to 6)

%W

Week number³ (00 to 53)

%x

Date

%X

Time

%y

Year without century (00 to 99)

%Y

Year (2008)

%Z

Time 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 速查表
相关文章
|
9月前
|
XML JSON API
淘宝商品详情API的调用流程(python请求示例以及json数据示例返回参考)
JSON数据示例:需要提供一个结构化的示例,展示商品详情可能包含的字段,如商品标题、价格、库存、描述、图片链接、卖家信息等。考虑到稳定性,示例应基于淘宝开放平台的标准响应格式。
|
5月前
|
JSON 数据安全/隐私保护 数据格式
拼多多批量下单软件,拼多多无限账号下单软件,python框架仅供学习参考
完整的拼多多自动化下单框架,包含登录、搜索商品、获取商品列表、下单等功能。
|
存储 IDE 开发工具
编写Python参考手册速查软件(一)
编写Python参考手册速查软件(一)
160 1
|
Python
编写Python参考手册速查软件(二)
编写Python参考手册速查软件(二)
116 0
|
机器学习/深度学习 设计模式 数据可视化
【干货】Python参考书籍
【干货】Python参考书籍
Python官方发布的《Python标准库参考》,共2018页,建议收藏!
Python之所以牛,其中很大一部分原因就是因为它是一种“内置电池”的编程语言。它的标准库功能强大,开箱即用,省去了很多安装工具、配置环境的时间。 如果你想精通Python,对标准库熟悉是必要的一步。那如何能尽快熟悉标准库呢?把《Python标准库参考手册》常备身边是最好的办法。没事的时候随便翻翻,就能获得意想不到的收获和进步。
小白入门必备!计科教授的Python精要参考PDF开放下载!
随着互联网产业的高速发展,在网络上早已积累了极其丰富的Python学习资料,任何人都可以基于这些资源,自学掌握 Python。 但实际上,网络上充斥的资源太多、太杂且不成体系,在没有足够的编程/工程经验之前,仅靠“看”线上资源自学,的确是一件非常困难的事。
|
数据处理 Python
Python官方发布的《Python标准库参考》,共2018页,建议收藏!
Python之所以牛,其中很大一部分原因就是因为它是一种“内置电池”的编程语言。它的标准库功能强大,开箱即用,省去了很多安装工具、配置环境的时间。 如果你想精通Python,对标准库熟悉是必要的一步。那如何能尽快熟悉标准库呢?把《Python标准库参考手册》常备身边是最好的办法。没事的时候随便翻翻,就能获得意想不到的收获和进步。
|
存储 Python
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
小白入门必备!计算机科学教程的Python精要参考PDF开放下载!
随着互联网产业的高速发展,在网络上早已积累了极其丰富的Python学习资料,任何人都可以基于这些资源,自学掌握 Python。 但实际上,网络上充斥的资源太多、太杂且不成体系,在没有足够的编程/工程经验之前,仅靠“看”线上资源自学,的确是一件非常困难的事。

推荐镜像

更多