Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability with its clean and easy-to-learn syntax.
🔑 Python Keywords
| Keyword | Description |
|---|---|
| False | Boolean false value |
| None | Represents null value |
| True | Boolean true value |
| and | Logical AND |
| as | Create an alias |
| assert | Debugging check |
| async | Declare async function |
| await | Await result from coroutine |
| break | Exit the loop |
| class | Define a class |
| continue | Skip iteration |
| def | Define a function |
| del | Delete variable/object |
| elif | Else if condition |
| else | Else condition |
| except | Exception handling |
| finally | Always run after try |
| for | For loop |
| from | Import specific parts |
| global | Declare global variable |
| if | If condition |
| import | Import module |
| in | Membership test |
| is | Object identity test |
| lambda | Anonymous function |
| nonlocal | Use outer variable in nested function |
| not | Logical NOT |
| or | Logical OR |
| pass | Do nothing |
| raise | Raise exception |
| return | Return from function |
| try | Try block |
| while | While loop |
| with | Context manager |
| yield | Return generator |
🧪 Python Data Types
| Data Type | Description | Example |
|---|---|---|
| int | Integer numbers | x = 10 |
| float | Decimal numbers | x = 3.14 |
| complex | Complex numbers | x = 2 + 3j |
| bool | Boolean values | True or False |
| str | Text / Strings | "Hello" |
| list | Ordered, mutable list | [1, 2, 3] |
| tuple | Ordered, immutable list | (1, 2, 3) |
| set | Unordered, unique elements | {1, 2, 3} |
| dict | Key-value pairs | {'a': 1, 'b': 2} |
| bytes | Immutable byte sequences | b'hello' |
| bytearray | Mutable byte sequences | bytearray(5) |
| NoneType | Represents a null value | None |
⚙️ Python Operators
| Operator Type | Operators | Example |
|---|---|---|
| Arithmetic | + - * / % // ** | a + b |
| Assignment | = += -= *= /= %= //= **= | x += 1 |
| Comparison | == != > < >= <= | a == b |
| Logical | and or not | a and b |
| Membership | in not in | "a" in "abc" |
| Identity | is is not | a is b |
| Bitwise | & | ^ ~ << >> | a & b |
🧰 Python Built-in Functions
| Function | Description |
|---|---|
| print() | Prints output |
| input() | Takes user input |
| len() | Returns length |
| type() | Returns data type |
| range() | Returns a range of values |
| int() | Converts to integer |
| float() | Converts to float |
| str() | Converts to string |
| list() | Converts to list |
| dict() | Creates dictionary |
| set() | Creates set |
| tuple() | Creates tuple |
| sum() | Sums iterable |
| min() | Minimum value |
| max() | Maximum value |
| sorted() | Returns sorted list |
| abs() | Absolute value |
| round() | Rounds number |
| enumerate() | Returns index and item |
| zip() | Combines iterables into tuples |
🧱 Python Common Tags & Constructs
| Construct | Purpose | Example |
|---|---|---|
| if-else | Conditional logic | if x > 5: print("Yes") |
| for loop | Loop over sequence | for i in list: |
| while loop | Loop while condition is true | while x < 5: |
| def | Function definition | def greet(): |
| class | Define class | class Person: |
| try-except | Error handling | try: x = 1/0 except: |
| with | Context management | with open("file.txt") as f: |
| import | Import module | import math |
| lambda | Anonymous function | lambda x: x + 1 |
| return | Return value from function | return x |
| yield | Generate values | yield x |
Click to go back on notes page.