Value In Brief
All You Need To Know Explained In Brief

Python Cheatsheet

Python programming languages scripting languages

Python sys Variables

variable meaning
argv Command line args
builti­n_m­odu­le_­names Linked C modules
byteorder Native byte order
check_­int­erval Signal check frequency
exec_p­refix Root directory
executable Name of executable
exitfunc Exit function name
modules Loaded modules
path Search path
platform Current platform
stdin, stdout, stderr File objects for I/O
versio­n_info Python version info
winver Version number

Python sys.argv

sys.argv for the command:

python bar -c qux --h
sys.argv part of the command­gv[0]­gv[1] bar­gv[2] -c­gv[3] qux­gv[4] –h

Python os Variables

OS Variable meaning
altsep Altern­ative sep
curdir Current dir string
defpath Default search path
devnull Path of null device
extsep Extension separator
linesep Line separator
name Name of OS
pardir Parent dir string
pathsep Patch separator
sep Path separator

Python Class Special Methods

Python List Methods

Python String Methods

Python File Methods

Python Indexes and Slices

Indexes and Slices of a=[0,1­,2,­3,4,5].

slices meaning
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 Methods

Python Time Methods

Python Date Formatting

Format Meaning
%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 (%)

That’s it. Hope it helps.