Basics of Python Programming:
- Introduction to Python: High-level, interpreted, easy-to-read language.
- Setting up the environment: Install Python, use IDE like VS Code, PyCharm.
- Variables: Store data; dynamically typed.
- Data Types: int, float, str, bool, list, tuple, dict, set.
- Operators: Symbols like +, -, *, ==, etc.
- Comments: Use # to explain code.
- Basic syntax: Uses indentation for blocks.
Python Input/Output:
- input(): Takes user input as string.
- print(): Displays output.
- Formatting output: Use f-strings or .format().
Python Data Types:
- Numbers: int, float.
- Strings: Text data.
- Booleans: True or False.
- Lists: Ordered, mutable.
- Tuples: Ordered, immutable.
- Sets: Unordered, unique.
- Dictionaries: Key-value pairs.
Python Operators:
- Arithmetic: +, -, *, /, //, %, **
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -=, etc.
- Bitwise: &, |, ^, ~, <<, >>
- Membership: in, not in
- Identity: is, is not
Python Conditional Statements:
- if, elif, else: Decision making.
- Nested conditions: if within if.
Python Loops:
- for: Iterates over sequences.
- while: Repeats while condition is true.
- break: Exits loop.
- continue: Skips to next iteration.
- pass: Does nothing (placeholder).
Lists and List Comprehensions:
- Creating: [1, 2, 3]
- Accessing: list[0]
- Operations: append, insert, remove, pop, slicing.
- Comprehensions: [x for x in range(5) if x % 2 == 0]
Strings and String Manipulation:
- Operations: +, slicing, split.
- Methods: lower, upper, replace, find, strip.
Dictionaries and Sets:
- Creating: {'a': 1}, {1, 2, 3}
- Accessing: dict['a']
- Operations: get, update, keys, values; add, remove for sets.
Python Functions:
- Defining: def func():
- Calling: func()
- Arguments: positional, keyword, default.
- Return: return value.
- Scope: local vs global.
Python File Handling:
- Opening: open('file.txt', 'r')
- Reading/Writing: read, readline, write
- Modes: r, w, a, b
- Closing: close() or with open(...) as file