An ordered set of instructions or commands to be executed by a computer is called a program . The language used to specify those set of instructions to the computer is called a programming language (e.g., Python, C, C++, Java, etc.).
Python is a highly popular, easy-to-learn, high-level, interpreter-based programming language created by Guido van Rossum in 1991 . It is widely used in software development, web development, scientific computing, big data, and Artificial Intelligence.
To write and run Python programs, a Python interpreter must be installed, or an online interpreter can be used. The interpreter is also referred to as the Python shell . The symbol >>> is the Python prompt , indicating that the interpreter is ready to receive commands.
Technical Profile: IDLE (Integrated Development and Learning Environment)
Python supports two primary execution modes:
Interactive Mode Example:
>>> 1 + 2
3
>>> 4 - 2
2
>>> "Hello" + "World"
'HelloWorld'
Keywords are reserved words with specific meanings for the Python interpreter. Because Python is case-sensitive, keywords must be written exactly as defined.
| Keyword | Keyword | Keyword | Keyword | Keyword |
|---|---|---|---|---|
| False | class | finally | is | return |
| None | continue | for | lambda | try |
| True | def | from | nonlocal | while |
| and | del | global | not | with |
| as | elif | if | or | yield |
| assert | else | import | pass | |
| break | except | in | raise |
Identifiers are user-defined names used to identify variables, functions, classes, or other entities in a program.
Rules for naming identifiers in Python:
A variable is an identifier whose value can change during program execution. Variables must be assigned a value before they are used, otherwise a runtime error occurs.
gender = 'M'
message = "Keep Smiling"
price = 987.9
Comments are non-executable notes added to the source code to make it easier for humans to understand. In Python, a single-line comment starts with the hash sign ( # ).
# This is a comment
# Program to find the sum of two numbers
num1 = 10
num2 = 20
result = num1 + num2
print(result) # Output: 30
Every value in Python belongs to a specific data type, which determines the operations that can be performed on it.
Stores numerical values. It is classified into three types:
| Type/Class | Description | Examples |
|---|---|---|
| int | integer numbers | -12, -3, 0, 123, 2 |
| float | floating point numbers | -2.04, 4.0, 14.23 |
| complex | complex numbers | 3 + 4j, 2 - 2j |
An ordered collection of items where each item is indexed by an integer:
An unordered data type that stores data in key-value pairs enclosed in curly brackets {} . Keys must be unique and are typically strings, while values can be of any data type.
>>> dict1 = {'Fruit':'Apple', 'Climate':'Cold', 'Price(kg)':120}
>>> print(dict1['Price(kg)'])
120
Used to perform mathematical calculations.
| Operator | Operation | Description | Example |
|---|---|---|---|
| + | Addition | Adds values on either side of the operator. Also concatenates strings. | 5 + 6 = 11 |
| - | Subtraction | Subtracts right operand from left operand. | 5 - 6 = -1 |
| * | Multiplication | Multiplies values. Also repeats strings if one operand is an integer. | 5 * 6 = 30 |
| / | Division | Divides left operand by right operand; returns a float. | 5 / 2 = 2.5 |
| % | Modulus | Divides left operand by right operand; returns the remainder. | 13 % 5 = 3 |
| // | Floor Division | Divides and returns the quotient as an integer (removes decimal part). | 5 // 2 = 2 |
| ** | Exponent | Raises the base to the power of the exponent. | 3 ** 4 = 81 |
Compares values and returns either True or False .
| Operator | Operation | Description | Example (num1=10, num2=0) |
|---|---|---|---|
| == | Equals to | True if values are equal. | num1 == num2 (False) |
| != | Not equal to | True if values are not equal. | num1 != num2 (True) |
| > | Greater than | True if left operand is greater than right. | num1 > num2 (True) |
| < | Less than | True if left operand is less than right. | num1 < num2 (False) |
| >= | Greater than or equal to | True if left operand is greater than or equal to right. | num1 >= num2 (True) |
| <= | Less than or equal to | True if left operand is less than or equal to right. | num1 <= num2 (False) |
Assignment Operators: Used to assign values to variables (e.g., = , += , -= , *= , /= ).
Logical Operators: Used to combine conditional statements. Written in lowercase: and , or , not .
Membership Operators: Used to test if a value is present in a sequence (string, list, tuple): in , not in .
Determines the order of evaluation in expressions containing multiple operators. Parentheses () have the highest precedence and can override default evaluation orders.
# Precedence of * is higher than +
20 + 30 * 40 # Evaluates to 20 + 1200 = 1220
# Parentheses force addition first
(20 + 30) * 40 # Evaluates to 50 * 40 = 2000
input(): Prompts the user for input and returns it as a string. Type conversion functions like int() or float() must be used to convert the input to numeric types.
age = int(input("Enter your age: "))
print(): Evaluates and displays expressions on the screen.
print("Hello")
print(10 * 2.5) # Output: 25.0
The process of identifying and removing errors from a program is called debugging . Errors are categorized into three types:
A function is a named, reusable block of statements that performs a specific task. Python provides built-in functions (e.g., print() , input() , type() , len() ) and allows importing functions from modules using the import statement.
Used to execute different blocks of code based on conditional outcomes:
# Example of if..elif..else
number = int(input("Enter a number: "))
if number > 0:
print("Positive")
elif number < 0:
print("Negative")
else:
print("Zero")
for Loop: Used to iterate over a sequence (range, list, tuple, string).
# Print even numbers
numbers = [1, 2, 3, 4, 5]
for num in numbers:
if num % 2 == 0:
print(num, "is even")
range() Function: Generates a sequence of numbers. Syntax: range([start], stop[, step]) .
>>> list(range(2, 10, 2))
[2, 4, 6, 8]
Nested Loops: A loop inside another loop.
for i in range(3):
for j in range(2):
print(i, j)
"Schools use 'Student Management Information System' (SMIS) to manage student related data. This system provides facilities for: Recording and maintaining personal details of students, maintaining marks scored in assessments and computing results of students, keeping track of student attendance, and managing many other student-related data in the school."
Socio-Technical Analysis & Core Systemic Impact: The automation of student records via an SMIS represents a critical transition from manual ledger-keeping to digital database management. Systemic considerations include:
- Data Privacy & Security: Storing sensitive personal details (contact numbers, addresses, parent details) requires strict access control protocols to prevent unauthorized data exposure.
- Data Integrity: Automated computation of assessment marks and attendance reduces human calculation errors but introduces vulnerabilities to software bugs or incorrect formula implementations.
- System Redundancy: Regular database backups are essential to mitigate the risk of data loss from hardware failures or system crashes.