Class 12 Computer Science - Review of Python Basics
1. Python Introduction
- High-level, interpreted, general-purpose programming language.
- Focuses on code readability with clean syntax and indentation.
2. Tokens in Python
- Keywords: Reserved words (e.g., if, else, def).
- Identifiers: Names for variables/functions, case-sensitive.
- Literals: Fixed values like 'Hello', 123, 3.14.
- Operators: Arithmetic, Relational, Logical, etc.
- Delimiters: Symbols like (), {}, [], :, ,.
3. Variables and Data Types
- Variables refer to values, dynamically typed.
- Basic types: int, float, bool, str, NoneType.
- Type conversion: int(), str(), float(), etc.
4. Operators and Expressions
- Arithmetic: +, -, *, /, //, %, **
- Relational: <, <=, >, >=, ==, !=
- Logical: and, or, not
- Assignment: =, +=, -=
- Membership: in, not in
- Identity: is, is not
5. Input and Output
- Input: input() returns string.
- Output: print(), supports formatting with f-strings.
6. Conditional Statements
- if, if-else, if-elif-else structures for decision making.
7. Loops in Python
- while and for loops for iteration.
- break: exits loop, continue: skips iteration, pass: does nothing.
8. Functions
- Defined using def keyword.
- Support arguments, return values, default/keyword/variable-length arguments.
9. Built-in Functions
- Examples: len(), max(), min(), sum(), type(), range().
10. Data Structures Overview
- Strings: Immutable.
- Lists: Mutable sequence.
- Tuples: Immutable sequence.
- Dictionaries: Key-value pairs.
- Sets: Unique, unordered elements.
11. Errors and Exceptions
- Syntax Error: Incorrect code structure.
- Runtime Error: Occurs during execution.
- Handled using try-except-finally blocks.
12. Best Practices
- Meaningful variable names, proper indentation.
- Use comments, avoid deep nesting.