Cheatography
https://cheatography.com
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.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Basic Syntax
Comments
Single line: Use #
symbol
Multi-line: Use triple quotes """ or '''
Inline comments: Add #
at end of line
Print Function
Basic output: print()
function displays text
Multiple values: Separate with commas
String formatting: Use f-strings, format(), or %
formatting.
Indentation
Critical in Python - Defines code blocks
Use 4 spaces - Standard convention
Consistent indentation - All lines in same block must have same indentation |
Data Types
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 |
Data types include numeric, text, boolean, and collections.
Formatting
f-strings |
|
format() |
"Hello {}".format(name)
|
% style |
|
|
|
Variable Declaration
No keyword needed |
Just assign |
Dynamic typing |
Auto-determined |
Case sensitive |
|
Multiple assignment |
One line |
Naming Rules
Start |
Letter or underscore |
Characters |
alphanumeric + underscore |
No reserved words |
|
Convention |
|
Strings (Creation Methods)
Single quotes |
|
Double quotes |
|
Triple quotes |
Multi Line |
Raw strings |
|
String Operations
Concatenation |
|
Repetition |
|
Length |
|
Indexing |
[0] zero-based |
Slicing |
[start:end:step] |
String Methods
Case |
upper(), lower(), title()
|
Search |
|
Check |
startswith(), endswith()
|
Modify |
replace(), strip(), split()
|
|