Python Tutorial
Fundamentals of Loops in Python:
For Loops
• Initialization of counter variable
• Condition check for continuation of loop
• Increment/decrement of counter variable
While Loops
• Initialization of condition variable
• Evaluation of condition in while statement
• Updation of condition variable
List Operations
• Creating lists using square brackets
• Accessing list elements using indexing
• Modifying list elements
Nested Loops
• Loop inside a loop
• Outer loop controls the number of times inner loop is executed
Factorial Calculation
• Implementing the formula using loops
Conditional Statements
• Checking for a given condition
• Executing a block of code based on the condition
,Error Handling
• Detecting various errors in the program
• Handling the errors using try and except blocks
Understanding Variables
• Storing values in variables
• Understanding data types of variables
• Rules for naming variables in Python
Functions and Modules
• Defining a function
• Calling a function
• Importing modules in Python programs
Working with Numbers:
Even, Odd, and Prime Number Identification (Python Classes
and Objects)
Understanding Variables and Data Types in Programming
Before diving into number identification, it's important to
understand variables and data types in programming, including:
• Scalar data types (int, float, bool, str)
• Compound data types (list, tuple, dictionary, set)
• Assigning values to variables
Even, Odd, and Prime Number Identification
Even Numbers
, • Even numbers can be identified by checking if the remainder of
the number divided by 2 is 0.
if num % 2 == 0:
print(f"{num} is an even number.")
Odd Numbers
• Odd numbers can be identified by checking if the remainder of
the number divided by 2 is not 0.
if num % 2 != 0:
print(f"{num} is an odd number.")
Prime Numbers
• Prime numbers are numbers greater than 1 that have only 2
factors: 1 and itself.
def is_prime(num):
if num < 2:
return False
for i in range(2, num):
if num % i == 0:
return False
return True
if is_prime(num):
print(f"{num} is a prime number.")
File Input and Output Operations
• Useful for reading and writing data to external files.
# Reading from a file
Fundamentals of Loops in Python:
For Loops
• Initialization of counter variable
• Condition check for continuation of loop
• Increment/decrement of counter variable
While Loops
• Initialization of condition variable
• Evaluation of condition in while statement
• Updation of condition variable
List Operations
• Creating lists using square brackets
• Accessing list elements using indexing
• Modifying list elements
Nested Loops
• Loop inside a loop
• Outer loop controls the number of times inner loop is executed
Factorial Calculation
• Implementing the formula using loops
Conditional Statements
• Checking for a given condition
• Executing a block of code based on the condition
,Error Handling
• Detecting various errors in the program
• Handling the errors using try and except blocks
Understanding Variables
• Storing values in variables
• Understanding data types of variables
• Rules for naming variables in Python
Functions and Modules
• Defining a function
• Calling a function
• Importing modules in Python programs
Working with Numbers:
Even, Odd, and Prime Number Identification (Python Classes
and Objects)
Understanding Variables and Data Types in Programming
Before diving into number identification, it's important to
understand variables and data types in programming, including:
• Scalar data types (int, float, bool, str)
• Compound data types (list, tuple, dictionary, set)
• Assigning values to variables
Even, Odd, and Prime Number Identification
Even Numbers
, • Even numbers can be identified by checking if the remainder of
the number divided by 2 is 0.
if num % 2 == 0:
print(f"{num} is an even number.")
Odd Numbers
• Odd numbers can be identified by checking if the remainder of
the number divided by 2 is not 0.
if num % 2 != 0:
print(f"{num} is an odd number.")
Prime Numbers
• Prime numbers are numbers greater than 1 that have only 2
factors: 1 and itself.
def is_prime(num):
if num < 2:
return False
for i in range(2, num):
if num % i == 0:
return False
return True
if is_prime(num):
print(f"{num} is a prime number.")
File Input and Output Operations
• Useful for reading and writing data to external files.
# Reading from a file