Unit II: Python Fundamentals
1. Python Program Execution Environment:
- Python is an interpreted language.
- Programs are written in .py files and executed using the Python interpreter.
- Interactive and script modes of execution.
- Environment includes IDEs like PyCharm, Jupyter Notebook, or text editors like VS Code.
2. Statement:
- A statement is an instruction that the Python interpreter can execute.
- Examples include assignment statements, conditional statements, loop statements, etc.
- Statements can be simple (e.g., x = 5) or compound (e.g., if...else).
3. Expression:
- An expression is a combination of values, variables, operators, and function calls.
- Evaluates to a single value.
- Example: 3 + 4 * 2 returns 11.
4. Flow of Control Statements:
- Conditional Statements:
* if, if-else, if-elif-else constructs to control execution.
- Looping Statements:
* for and while loops to perform repetitive tasks.
- Loop Control:
* break, continue, and pass to control loop execution.
5. Functions:
- Defined using the 'def' keyword.
- Can take parameters and return results.
- Support for built-in and user-defined functions.
- Example:
def greet(name):
return "Hello " + name
6. Scope of Variables:
- Refers to the part of the program where a variable is accessible.
- Local Scope:
* Variables defined inside a function.
- Global Scope:
* Variables defined outside all functions.
- Nonlocal and global keywords can be used to modify scope behavior.
These fundamentals are crucial for understanding how Python programs are structured and
executed.