Python Basics Summary
1. Keywords and Identifiers
Keywords are reserved words used by Python to define the syntax. Examples: if, else, while, def.
Identifiers are names for variables, functions, classes, etc. They cannot start with a digit or use special
characters.
2. Variables and Datatypes
Variables store data values. Python datatypes include:
- int: Integer numbers
- float: Decimal numbers
- str: Text
- list: Mutable sequence
- tuple: Immutable sequence
- set: Unordered, unique items
- dict: Key-value pairs
- None: Represents no value
3. Python Operators
- Arithmetic: +, -, *, /, //, %, **
- Comparison: ==, !=, <, >, <=, >=
- Logical: and, or, not
- Assignment: =, +=, -=, *=, /=
4. Input/Output
Use input() to take user input and print() to display output.
Example: name = input('Enter name: ')
5. Type Conversion
Implicit: Python auto-converts types.
Explicit: Use int(), float(), str(), etc. to convert between types.
Python Basics Summary
6. Strings
Strings are ordered sequences of characters. Enclosed in single or double quotes. Supports indexing, slicing,
and methods like .upper(), .lower(), .replace().
7. Lists
Lists are mutable, ordered collections. Syntax: [1, 2, 3]
Methods: append(), insert(), remove(), pop(), extend(), sort(), reverse().
8. Tuples
Tuples are immutable, ordered collections. Syntax: (1, 2, 3)
Use indexing to access elements. Cannot modify after creation.
9. Dictionaries
Dictionaries are unordered collections of key-value pairs. Syntax: {key: value}
Access with keys, e.g., d['name'] = 'John'.
10. Sets
Sets are unordered collections with no duplicate items. Syntax: {1, 2, 3}
Support set operations like union, intersection, difference.