Comprehensive notes, MCQs, and Short Questions for Chapter 2 Python Programming. Covers Python basics, variables, data types, operators, input/output, and control structures.
Definition: Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum and released in 1991.
Key Features:
- Easy to Learn: Simple syntax that reads like English.
- Interpreted: Code is executed line-by-line.
- Versatile: Used for web development, data science, AI, and automation.
- Open Source: Free to use and modify.
IDLE (Integrated Development and Learning Environment): The default IDE that comes with Python. It provides a text editor and a shell window.
Modes:
- Interactive Mode: Type commands one by one in the shell.
- Script Mode: Write code in a file (.py) and run it.
Variables: Containers for storing data values. Rules for naming:
- Must start with a letter or underscore.
- Cannot start with a number.
- Case-sensitive (age vs Age).
- No spaces or special characters allowed.
Data Types:
- int: Whole numbers (e.g., 10, -5).
- float: Decimal numbers (e.g., 3.14, -0.01).
- str: Text enclosed in quotes (e.g., 'Hello').
- bool: True or False.
Arithmetic: +, -, *, /, // (floor division), % (modulus), ** (exponent).
Comparison: ==, !=, >, <, >=, <=.
Logical: and, or, not.
Assignment: =, +=, -=, etc.
Output: print() function displays data to the screen.
Example: print('Hello World')
Input: input() function takes data from the user (always as a string).
Example: name = input('Enter name: ')
Conditional Statements: if, elif, else used for decision making.
Loops:
- for loop: Iterates over a sequence (e.g., a range of numbers).
- while loop: Repeats as long as a condition is true.