Cheatography
https://cheatography.com
Python IDLE Shell1. Press the Windows Key
2. Type "Python IDLE" |
How to create a new Python file1. In the Python Shell, click File Tab
2. Click New File |
Print Statementsprint("Hello")
Hello
print(4+5)
9
|
Function Definitiondef name (arg1, arg2, ...):
statements
return expr |
Boolean Operatorsx is y | x not y | x and y | x or y |
List Operationslist.append(a) | Append a to list | list.insert(i, a) | Insert a before ith item in list | list.sort() | Sort list | list.pop(i) | Remove i th item in list |
| | Data TypesInteger | -256, 15 | String | "Hello", "apple" | Boolean | True, False | List | [ value, ... ] | Tuple | ( value, ... ) |
Conversion Functionsint(expr) Converts expr to integer | str(expr) Converts expr to string |
Arithmetic Operatorsx + y | add | x - y | subtract | x * y | multiply | x / y | divide | x % y | modulus | x ** y | xy |
Comparatorsx < y | Less | x <= y | Less or equal | x > y | Greater | x >= y | Greater or equal | x == y | Equal | x != y | Not equal |
| | String / List / Tuple Operationslen(s) | length of s | s[i] | ith item in s (starts from 0) | s[start : end : step ] | slice s from start (included) to end (excluded) with increment step | s + t | concatenate s with t |
StatementsIf Statement
if expr :
statements
elif expr :
statements
else:
statements
While Loop
while expr :
statements
For Loop
for var in collection :
statements
Counting For Loop
for i in range(start, end, step):
statements |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets