Python/CheatSheet: Difference between revisions
< Python
No edit summary |
|||
Line 52: | Line 52: | ||
string = 'Hello World' | string = 'Hello World' | ||
string[4] | string[4] # = 'o' | ||
string.split(' ') # ['Hello', 'World'] | |||
</pre> | </pre> | ||
</blockquote> | </blockquote> | ||
Line 59: | Line 60: | ||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
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() | |||
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) | |||
</pre> | </pre> | ||
</blockquote> | </blockquote> | ||
Line 68: | Line 105: | ||
</pre> | </pre> | ||
</blockquote> | </blockquote> | ||
= Functions = | = Functions = |
Revision as of 11:47, 18 September 2017
Variables
Tuples
Lists
Dictionaries
Flow Control
If Then Else
if x < 0: print('Negative') elif x == 0: print('Zero') else: print('More')
For loops
for x in ['cat', 'dog', 'bird']: print (w)
While loops
while test: print (answer)
while True: print (answer) if answer == '2': break
Strings
string = "Hello World" string = 'Hello World' string[4] # = 'o' string.split(' ') # ['Hello', 'World']
String functions
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() 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)
Functions
datetime
today() now(timezoneinfo) utcnow() fromordinal(ordinal) combine(date,time) strptime(date,format) fromtimestamp(timestamp) utcfromtimestamp(timestamp)
time
replace() utcoffset() isoformat() __str__() dst() tzname() strftime(format)
strftime & strptime format