
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
date formatting in python
Typology: Cheat Sheet
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Class Special Methods
new(cls) init(self, args) del(self) repr(self) str(self) cmp(self, other) index(self) hash(self) getattr(self, name) getattribute(self, name) setattr(self, name, attr) delattr(self, name) call(self, args, kwargs)
String Methods
capitalize() * center(width) count(sub, start, end) decode() encode() endswith(sub) expandtabs() find(sub, start, end) index(sub, start, end) isalnum() * isalpha() * isdigit() * islower() * isspace() * istitle() * isupper() * join() ljust(width) lower() *
sys Variables
argv builtin_module_names byteorder check_interval exec_prefix executable exitfunc modules path platform stdin, stdout, stderr version_info winver
os Variables
altsep curdir defpath devnull extsep linesep name pardir pathsep sep
Indexes and Slices (of a=[0,1,2,3,4,5])
len(a) a[0] a[5] a[-1] a[-2] a[1:] a[:5] a[:-2] a[1:3] a[1:-1] b=a[:]
Shallow copy of a
Date Formatting (strftime and strptime)
%a %A %b %B %c %d %H %I %j %m %M %p %S %U %w %W %x %X %y %Y %Z %%
Abbreviated weekday (Sun) Weekday (Sunday) Abbreviated month name (Jan) Month name (January) Date and time Day (leading zeros) (01 to 31) 24 hour (leading zeros) (00 to 23) 12 hour (leading zeros) (01 to 12) Day of year (001 to 366) Month (01 to 12) Minute (00 to 59) AM or PM Second (00 to 61 4 ) Week number 1 (00 to 53) Weekday 2 (0 to 6) Week number 3 (00 to 53) Date Time Year without century (00 to 99) Year (2008) 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.
lstrip() partition(sep) replace(old, new) rfind(sub, start ,end) rindex(sub, start, end) rjust(width) rpartition(sep) rsplit(sep) rstrip() split(sep) splitlines() startswith(sub) strip() swapcase() * title() * translate(table) upper() * zfill(width)
Methods marked * are locale Note dependant for 8-bit strings.
lt(self, other) le(self, other) gt(self, other) ge(self, other) eq(self, other) ne(self, other) nonzero(self)
sys.argv for $ python foo.py bar qux
sys.argv[0] sys.argv[1] sys.argv[2]
foo.py bar qux
Alternative sep Current dir string Default search path Path of null device Extension separator Line separator Name of OS Parent dir string Patch separator Path separator
Registered OS names: “posix”, “nt”, Note “mac”, “os2”, “ce”, “java”, “riscos”
Command line args Linked C modules Native byte order Signal check frequency Root directory Name of executable Exit function name Loaded modules Search path Current platform File objects for I/O Python version info Version number
File Methods
close() flush() fileno() isatty() next() read(size) readline(size)
readlines(size) seek(offset) tell() truncate(size) write(string) writelines(list)
Time Methods
replace() isoformat() str() strftime(format)
utcoffset() dst() tzname()
Datetime Methods
today() now(timezoneinfo) utcnow() fromtimestamp(timestamp) utcfromtimestamp(timestamp)
fromordinal(ordinal) combine(date, time) strptime(date, format)
List Methods
append(item) count(item) extend(list) index(item) insert(position, item)
pop(position) remove(item) reverse() sort()