Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
110 views

Python Cheat Sheet: by Via

This document is a Python cheat sheet that provides an overview of various Python topics in a condensed format. It includes summaries of Python sys variables, classes, lists, strings, files, datetimes, and date formatting. The cheat sheet is intended to provide essential information about key Python concepts in a concise reference guide.

Uploaded by

maria diana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Python Cheat Sheet: by Via

This document is a Python cheat sheet that provides an overview of various Python topics in a condensed format. It includes summaries of Python sys variables, classes, lists, strings, files, datetimes, and date formatting. The cheat sheet is intended to provide essential information about key Python concepts in a concise reference guide.

Uploaded by

maria diana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/19/

Python sys Variables Python Class Special Methods Python String Methods (cont)

argv Command line args __new_​_(cls) __lt__​(self, other) istitle() * title() *


builti​n_m​odu​le_​‐ Linked C modules __init​__(​self, args) __le__​(self, other) isupper() * transl​ate​(table)
names __del_​_(self) __gt__​(self, other) join() upper() *
byteorder Native byte order __repr​__(​self) __ge__​(self, other) ljust(​width) zfill(​width)
check_​int​erval Signal check __str_​_(self) __eq__​(self, other) lower() *
frequency
__cmp_​_(self, other) __ne__​(self, other) Methods marked * are locale dependant for
exec_p​refix Root directory
__inde​x__​(self) __nonz​ero​__(​self) 8-bit strings.
executable Name of executable
__hash​__(​self)
exitfunc Exit function name Python File Methods
__geta​ttr​__(​self, name)
modules Loaded modules close() readli​nes​(size)
__geta​ttr​ibu​te_​_(self, name)
path Search path flush() seek(o​ffset)
__seta​ttr​__(​self, name, attr)
platform Current platform fileno() tell()
__dela​ttr​__(​self, name)
stdin, stdout, stderr File objects for I/O isatty() trunca​te(​size)
__call​__(​self, args, kwargs)
versio​n_info Python version info next() write(​string)
winver Version number Python List Methods read(size) writel​ine​s(list)

append​(item) pop(po​sition) readli​ne(​size)


Python sys.argv
count(​item) remove​(item)
sys.ar​gv[0] foo.py Python Indexes and Slices
extend​(list) reverse()
sys.ar​gv[1] bar len(a) 6
index(​item) sort()
sys.ar​gv[2] -c a[0] 0
insert​(po​sition, item)
sys.ar​gv[3] qux a[5] 5
sys.ar​gv[4] --h Python String Methods a[-1] 5

sys.argv for the command: capita​lize() * lstrip() a[-2] 4


$ python foo.py bar -c qux --h center​(width) partit​ion​(sep) a[1:] [1,2,3​,4,5]

count(sub, start, replac​e(old, new) a[:5] [0,1,2​,3,4]


Python os Variables
end) a[:-2] [0,1,2,3]
altsep Altern​ative sep
decode() rfind(sub, start ,end) a[1:3] [1,2]
curdir Current dir string
encode() rindex​(sub, start, a[1:-1] [1,2,3,4]
defpath Default search path end)
b=a[:] Shallow copy of a
devnull Path of null device endswi​th(sub) rjust(​width)
Indexes and Slices of a=[0,1​,2,​3,4,5]
extsep Extension separator expand​tabs() rparti​tio​n(sep)
linesep Line separator find(sub, start, end) rsplit​(sep) Python Datetime Methods
name Name of OS index(sub, start, rstrip() today() fromor​din​al(​ord​inal)
pardir Parent dir string end)
now(ti​mez​one​info) combin​e(date, time)
pathsep Patch separator isalnum() * split(sep)
utcnow() strpti​me(​date, format)
sep Path separator isalpha() * splitl​ines()
fromti​mes​tam​p(t​ime​stamp)
Registered OS names: "​pos​ix", "​nt", isdigit() * starts​wit​h(sub)
utcfro​mti​mes​tam​p(t​ime​stamp)
"​mac​", "​os2​", "​ce", "​jav​a", "​ris​cos​" islower() * strip()
isspace() * swapcase() *

By Dave Child (DaveChild) Published 19th October, 2011. Sponsored by CrosswordCheats.com


cheatography.com/davechild/ Last updated 12th May, 2016. Learn to solve cryptic crosswords!
aloneonahill.com Page 1 of 2. http://crosswordcheats.com
Python Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/19/

Python Time Methods

replace() utcoff​set()
isofor​mat() dst()
__str__() tzname()
strfti​me(​format)

Python Date Formatting

%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.

By Dave Child (DaveChild) Published 19th October, 2011. Sponsored by CrosswordCheats.com


cheatography.com/davechild/ Last updated 12th May, 2016. Learn to solve cryptic crosswords!
aloneonahill.com Page 2 of 2. http://crosswordcheats.com

You might also like