A detailed Python cheat sheet covering beginner to advanced topics. Python is a popular programming language that can be used on a server to create web applications and this cheat sheet will cover all essential concepts.
# symbol""" or ''' # at end of line print() function displays textf-strings, format(), or % formatting.|
int
|
Whole numbers
|
|
float
|
Decimal Numbers
|
|
complex
|
Real + imaginary
|
|
str
|
Character strings
|
|
Immutable
|
Can't change chars
|
|
Unicode
|
International support
|
|
bool
|
True/False Values
|
|
list
|
Ordered, mutable
|
|
tuple
|
Ordered, immutable
|
|
dict
|
Key-value pairs
|
|
set
|
Unique elements only
|
|
Start
|
Letter or underscore
|
|
Characters
|
alphanumeric + underscore
|
|
No reserved words
|
if, for, class
|
|
Convention
|
snake_case
|
|
No keyword needed
|
Just assign
|
|
Dynamic typing
|
Auto-determined
|
|
Case sensitive
|
myvar ≠ MyVar
|
|
Multiple assignment
|
One line
|
|
f-strings
|
f"Hello {name}" |
|
format()
|
"Hello {}".format(name) |
|
% style
|
"Hello %s" % name |
|
Case
|
upper(), lower(), title()
|
|
Search
|
find(), index(), count()
|
|
Check
|
startswith(), endswith()
|
|
Modify
|
replace(), strip(), split()
|
|
Concatenation
|
+ operator
|
|
Repetition
|
* operator
|
|
Length
|
`en() function
|
|
Indexing
|
[0] zero-based
|
|
Slicing
|
[start:end:step]
|
|
Single quotes
|
'Hello'
|
|
Double quotes
|
"Hello"
|
|
Triple quotes
|
Multi Line
|
|
Raw strings
|
r 'literal'
|
|
if
|
Basic condition check
|
|
elif
|
Additional conditions
|
|
else
|
Default
|
|
Operators
|
==, !=, <, >
|
|
Logic
|
and, or, not
|
|
For
|
Iterate sequences
|
|
While
|
Condition-based
|
|
range()
|
Number Sequence
|
|
enumerate()
|
Index + Value
|
|
zip()
|
Multiple sequence
|
|
break
|
Exit loop
|
|
continue
|
Skip iteration
|
|
else
|
Normal completion
|
|
pass
|
Empty placeholder
|
</div><div style="flex: 1;">|
try
|
Code that may fail
|
|
except
|
Handle exceptions
|
|
else
|
No exception occured
|
|
finally
|
Always excute
|
|
rise
|
Trigger exception
|
|
SyntaxError
|
Invalid syntax
|
|
NameError
|
Undefined variable
|
|
TypeError
|
Wrong data type
|
|
ValueError
|
Wrong Value
|
|
IndexError
|
List index error
|
|
KeyError
|
Dict key missing
|
append(), insert(), remove()sort(), reverse()count(), index()get(), keys(), values()add(), remove(), union()No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.