0% found this document useful (0 votes)
6 views23 pages

Python Question & Answers - Dec-2024 Question Paper

The document explains various Python concepts including arithmetic operators, data types, control structures like loops, functions, and string operations. It provides example code for each concept, demonstrating how to use division, floor division, modulus, and various data types such as integers, floats, strings, lists, and dictionaries. Additionally, it includes programs for checking donor eligibility, calculating acceleration, counting vowels and consonants, and using string functions and operators.

Uploaded by

Ayyanar Manickam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

Python Question & Answers - Dec-2024 Question Paper

The document explains various Python concepts including arithmetic operators, data types, control structures like loops, functions, and string operations. It provides example code for each concept, demonstrating how to use division, floor division, modulus, and various data types such as integers, floats, strings, lists, and dictionaries. Additionally, it includes programs for checking donor eligibility, calculating acceleration, counting vowels and consonants, and using string functions and operators.

Uploaded by

Ayyanar Manickam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Question :11 (a)

Explain about '\', '\\','%' operators in python arithmetic.

Division (/)
Divides the first number by the second and returns a floating-point result.
Example: 9 / 2 results in 4.5.
5. Floor Division (//)
Divides the first number by the second and returns the largest integer less than or equal to the
result.
Example: 9 // 2 results in 4.
6. Modulus (%)
Returns the remainder of the division.
Example: 9 % 2 results in 1.
Example Code:

a = 10
b=3

print(a / b) # Division: 3.333...


print(a // b) # Floor Division: 3
print(a % b) # Modulus: 1
These operators work seamlessly with integers, floats, and even complex numbers, making
Python a versatile language for arithmetic operations.

Question :11 (b)


Explain the basic data types available in python with examples

Python provides several built-in data types to handle different kinds of data.
Here's a concise explanation of the basic data types with examples:

1. Numeric Types

int: Represents integers (whole numbers).


float: Represents decimal or floating-point numbers.
complex: Represents complex numbers with real and imaginary parts.

Examples:

x = 10 # int
y = 3.14 # float
z = 2 + 3j # complex

2. Sequence Types

str: Represents text (string of characters).


list: Ordered, mutable collection of items.
tuple: Ordered, immutable collection of items.
Examples:

name = "Python" # str


fruits = ["apple", "banana"] # list
coordinates = (10, 20) # tuple

3. Mapping Type

dict: Represents key-value pairs.

Example:

person = {"name": "Alice", "age": 25} # dict

4. Set Types

set: Unordered collection of unique items.


frozenset: Immutable version of a set.

Examples:

unique_numbers = {1, 2, 3} # set


frozen_set = frozenset([1, 2, 3]) # frozenset

5. Boolean Type

bool: Represents True or False.

Example:

is_active = True # bool

6. Binary Types

bytes: Immutable sequence of bytes.


bytearray: Mutable sequence of bytes.
memoryview: Provides a view of binary data.

Examples:

data = b"hello" # bytes


mutable_data = bytearray(5) # bytearray
view = memoryview(data) # memoryview

7. None Type
NoneType: Represents the absence of a value.

Example:

result = None # NoneType

These data types allow Python to handle a wide variety of data efficiently. You can use
the type() function to check the type of any variable. For example:

print(type(10)) # Output: <class 'int'>

Question :12 (a)


Blood donation camp has a criterion for the donor eligibility as follows:
Eligibility
Gender
Age Height Weight
Male ˃ 20 ˃ 150 ˃ 60
Female ˃ 23 ˃ 140 ˃ 55
Write a python program for the given scenario: If the above conditions are satisfied,then
he/she is permitted to donate , else not permitted.

def check_donor_eligibility(gender, age, height, weight):


# Check eligibility based on gender and other conditions
if gender.lower() == "male":
if age > 20 and height > 150 and weight > 60:
return "Eligible to donate blood."
else:
return "Not eligible to donate blood."
elif gender.lower() == "female":
if age > 23 and height > 140 and weight > 55:
return "Eligible to donate blood."
else:
return "Not eligible to donate blood."
else:
return "Invalid gender input. Please enter 'male' or 'female'."

# Get input from the user


gender = input("Enter gender (male/female): ").strip()
age = int(input("Enter age: "))
height = int(input("Enter height in cm: "))
weight = int(input("Enter weight in kg: "))

# Check and display eligibility


result = check_donor_eligibility(gender, age, height, weight)
print(result)
How this works:
The program defines a function check_donor_eligibility() to check if the donor meets the
eligibility criteria.
The function compares the given values for age, height, and weight based on gender-specific
conditions.

The program prompts the user for input (gender, age, height, and weight) and calls the
eligibility function.

The result is printed based on whether the user is eligible or not.

Example Output:
mathematica
Copy
Edit
Enter gender (male/female): male
Enter age: 22
Enter height in cm: 160
Enter weight in kg: 65
Eligible to donate blood.
If the conditions aren’t met, it will print:

Not eligible to donate blood.

Question :12 (b)


Illustrate the usage of 'while' and 'for' statement with a sample python program.

Certainly! Both while and for loops are used for repetitive tasks in Python, but they work
differently. Here's a breakdown of how each loop works and a sample program that
demonstrates both:

1. while loop:

The while loop continues to execute as long as the given condition is True. Once the condition becomes
False, the loop terminates.

2. for loop:

The for loop iterates over a sequence (like a list, string, or range) and executes the block of
code for each item in that sequence.

Example Program:

python
CopyEdit
# Using 'while' loop
print("Using while loop:")
counter = 1
while counter <= 5: # The loop will run until counter becomes greater than 5
print(f"Iteration {counter}")
counter += 1 # Increment the counter to avoid an infinite loop
# Using 'for' loop
print("\nUsing for loop:")
# Using range() to create a sequence from 1 to 5
for i in range(1, 6): # Loop will run from 1 to 5 (inclusive of 1 and exclusive of 6)
print(f"Iteration {i}")

Explanation:

While loop:

Starts with counter = 1 and runs as long as counter <= 5.

Inside the loop, the counter is incremented by 1 on each iteration.

When counter becomes 6, the loop stops.

For loop:

The for loop uses range(1, 6) to create a sequence of numbers from 1 to 5 (since range
excludes the upper limit, 6 in this case).

It runs for each number in the range and prints the iteration number.

Output:
Using while loop:
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5

Using for loop:


Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5

Key Differences:

The while loop is typically used when you don't know how many iterations you need to run
beforehand, but you have a condition that will eventually stop the loop.

The for loop is used when you have a known sequence or range to iterate over.
Question :13 (a)
Newton's second law of motion is expressed as F = m x a ,where F is force , m is mass and a is
acceleration. Write a python program using calculate () function to calculate the acceleration
is mass of an object and the force on that object are given as input. Display the result to the
user.
Test case 1 2
Input Mass = 5,Force = 1050 Mass = 3,Force = 564
Output 210 188

You can write a Python program that uses the formula F=m×aF = m \times aF=m×a to calculate
acceleration (aaa) given the force (FFF) and mass (mmm) of an object. Rearranging the formula
to calculate
a=Fma acceleration, we get:
= \frac{F}{m}a=mF​
Now, I'll create a calculate() function to perform this calculation and display the result to the
user.
Python Program:

def calculate(mass, force):


# Formula to calculate acceleration: a = F / m
acceleration = force / mass
return acceleration

# Test case 1
mass1 = 5
force1 = 1050
result1 = calculate(mass1, force1)
print(f"For Mass = {mass1} kg and Force = {force1} N, Acceleration = {result1} m/s²")

# Test case 2
mass2 = 3
force2 = 564
result2 = calculate(mass2, force2)
print(f"For Mass = {mass2} kg and Force = {force2} N, Acceleration = {result2} m/s²")

Explanation:

The calculate() function takes two inputs: mass and force.

It calculates acceleration using the formula a=Fma = \frac{F}{m}a=mF​.

The result is returned and displayed for each test case.

Output:

For Mass = 5 kg and Force = 1050 N, Acceleration = 210.0 m/s²


For Mass = 3 kg and Force = 564 N, Acceleration = 188.0 m/s²

This code can be easily modified to take input from the user or handle multiple test cases
dynamically.
Question :13 (b)
Write a python program to find the sum of the cubes of the indvidual digits of a given integer
number.

Here's a Python program that calculates the sum of the cubes of the individual digits of a given
integer number:

def sum_of_cubes_of_digits(number):
# Ensure the number is positive
number = abs(number)

# Calculate the sum of cubes of digits


sum_cubes = sum(int(digit)**3 for digit in str(number))

return sum_cubes

# Example usage
num = int(input("Enter an integer: "))
result = sum_of_cubes_of_digits(num)
print("Sum of cubes of digits:", result)

Example:

If you input 123, the program will compute:

1³ + 2³ + 3³ = 1 + 8 + 27 = 36

Question :14 (a)


What is the function ? Explain different methods of passing parameters to a function with an
example.

What is a Function?

A function in Python is a reusable block of code that performs a specific task. It helps in
breaking down large programs into smaller, manageable pieces and promotes code reuse.

You define a function using the def keyword, and you can call it wherever needed.

🧠 Why Use Functions?


Organize code logically
Avoid repetition
Make code easier to understand and maintain

🔹 Function Syntax:
def function_name(parameters):
# Function body
return value

📦 Methods of Passing Parameters to a Function


There are four common ways to pass parameters to a function in Python:
1. Positional Arguments

Arguments are passed in the order they are defined.

python
CopyEdit
def greet(name, age):
print(f"Hello {name}, you are {age} years old.")

greet("Alice", 30)

Output:
Hello Alice, you are 30 years old.
2. Keyword Arguments

Arguments are passed using the parameter names.

greet(age=25, name="Bob")

Output:
Hello Bob, you are 25 years old.
3. Default Arguments

If a value is not provided, the default is used.

def greet(name, age=18):


print(f"Hello {name}, you are {age} years old.")

greet("Charlie") # Uses default age


greet("Dana", 22) # Overrides default age

Output:

Hello Charlie, you are 18 years old.


Hello Dana, you are 22 years old.

4. Variable-length Arguments

Used when you're not sure how many arguments will be passed.

a. *args – for non-keyworded variable arguments:

def total_sum(*numbers):
print("Sum:", sum(numbers))

total_sum(1, 2, 3, 4)

b. **kwargs – for keyworded variable arguments:


def print_info(**info):
for key, value in info.items():
print(f"{key}: {value}")

print_info(name="Eve", age=28, city="New York")

for key, value in info.items():


print(f"{key}: {value}")

print_info(name="Eve", age=28, city="New York")

Question :14 (b)


Write a python program to count the total number of vowels and consonants in a string.
Here's a simple Python program to count the total number of vowels and consonants in a string:

def count_vowels_and_consonants(text):
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0

for char in text:


if char.isalpha(): # Only consider alphabetic characters
if char in vowels:
vowel_count += 1
else:
consonant_count += 1

return vowel_count, consonant_count

# Example usage
user_input = input("Enter a string: ")
vowels, consonants = count_vowels_and_consonants(user_input)

print("Number of vowels:", vowels)


print("Number of consonants:", consonants)
✅ Example:

Input:

Enter a string: Hello World

Output:

Number of vowels: 3
Number of consonants: 7
Question :15 (a)
Describe any four string functions in python with sample program.
Here are four commonly used string functions in Python along with examples:

🔹 1. upper() – Convert to Uppercase

Description: Converts all characters in the string to uppercase.

text = "hello world"


print(text.upper())

Output:
HELLO WORLD
🔹 2. lower() – Convert to Lowercase

Description: Converts all characters in the string to lowercase.

text = "Python Programming"


print(text.lower())

Output:

python programming
🔹 3. replace(old, new) – Replace Substring

Description: Replaces all occurrences of a substring with another substring.

text = "I like Python"


print(text.replace("like", "love"))

Output:

I love Python
🔹 4. split(separator) – Split String

Description: Splits the string into a list based on the given separator (default is whitespace).

text = "apple,banana,grape"
fruits = text.split(",")
print(fruits)

Output:

['apple', 'banana', 'grape']


Question :15 (b)
Illustrate about the various string operators with examples.
In Python, string operators are used to perform operations on string data. Below are the
common string operators with clear explanations and examples:

🔹 1. Concatenation Operator (+)


Used to join two or more strings.

str1 = "Hello"
str2 = "World"
result = str1 + " " + str2
print(result)

Output:

Hello World

🔹 2. Repetition Operator (*)


Repeats the string a specified number of times.

str1 = "Hi! "


print(str1 * 3)

Output:

Hi! Hi! Hi!

🔹 3. Membership Operators (in, not in)


Checks if a substring exists within another string.

text = "Python Programming"

print("Python" in text) # True


print("Java" not in text) # True
Output:
TRUE
TRUE

🔹 4. Slicing Operator ([:])


Extracts a portion (substring) of the string.

text = "Programming"
print(text[0:6]) # First 6 characters
print(text[-3:]) # Last 3 characters

Output:

Progra
ing
🔹 5. Comparison Operators (==, !=, <, >, <=, >=)
Compares two strings lexicographically (alphabetical order based on Unicode values).

print("apple" == "apple") # True


print("apple" < "banana") # True
print("apple" > "Apple") # True (lowercase > uppercase in Unicode)

Output:

TRUE
TRUE
TRUE

Question :16
Construct a python program that uses a dictionary that contains 20 employee names and
employee ids.The program should ask the user to enter their employee name employee id. If
the employee name is not in the dictionary. The program should indicate that the person is
''not a valid employee'' of the industry. if the employee name is in the dictionary ,but the
user does not enter the right employee id, the program should say that the employee id ''is
valid''. If the employee id is correct , then the program should tell her the user that they are
now ''logged in'' to the onsite page of employee name to interact with the client/customer.

Here's a complete Python program that implements the behavior you described using a
dictionary of 20 employees and their IDs:

# Dictionary containing 20 employee names and their IDs


employees = {
"Alice": "E101",
"Bob": "E102",
"Charlie": "E103",
"David": "E104",
"Eve": "E105",
"Frank": "E106",
"Grace": "E107",
"Hannah": "E108",
"Ian": "E109",
"Jack": "E110",
"Karen": "E111",
"Leo": "E112",
"Mona": "E113",
"Nina": "E114",
"Oscar": "E115",
"Paul": "E116",
"Quincy": "E117",
"Rachel": "E118",
"Steve": "E119",
"Tina": "E120"
}

# Get input from user


name_input = input("Enter your employee name: ").strip()
id_input = input("Enter your employee ID: ").strip()

# Check if employee name exists


if name_input not in employees:
print("Not a valid employee of the industry.")
else:
# Check if ID matches
if employees[name_input] == id_input:
print(f"Logged in to the onsite page of {name_input} to interact with the client/customer.")
else:
print("Employee ID is invalid.")

✅ Sample Run:

Input:

Enter your employee name: Alice


Enter your employee ID: E101

Output:

Logged in to the onsite page of Alice to interact with the client/customer.

Another Input:

Enter your employee name: Alice


Enter your employee ID: E999

Output:

Employee ID is invalid.

Another Input:

Enter your employee name: Unknown


Enter your employee ID: E000

Output:
Not a valid employee of the industry.

Question :17 (a)


Discuss the following dictionary methods with an example. i)Get() ii)Keys() iii) Pop() iv) Update().
Here’s a clear explanation of the following dictionary methods in Python, with examples:

🔹 i) get() Method
Description:
Returns the value for the specified key. If the key is not found, it returns a default value (None if not specified).

employee = {"name": "Alice", "id": "E101"}

# Using get()
print(employee.get("name")) # Output: Alice
print(employee.get("age")) # Output: None
print(employee.get("age", "N/A")) # Output: N/A

🔹 ii) keys() Method


Description:
Returns a view object that displays all the keys in the dictionary.

employee = {"name": "Bob", "id": "E102"}

# Using keys()
print(employee.keys()) # Output: dict_keys(['name', 'id'])

# You can convert it to a list


print(list(employee.keys())) # Output: ['name', 'id']

🔹 iii) pop() Method


Description:
Removes the specified key and returns the corresponding value. Raises a KeyError if the key is
not found (unless a default is provided).

employee = {"name": "Charlie", "id": "E103", "dept": "IT"}

# Using pop()
removed_value = employee.pop("dept")
print(removed_value) # Output: IT
print(employee) # Output: {'name': 'Charlie', 'id': 'E103'}

🔹 iv) update() Method


Description:
Updates the dictionary with key-value pairs from another dictionary or from keyword
arguments.

employee = {"name": "David", "id": "E104"}

# Using update() with another dictionary


employee.update({"dept": "HR", "location": "New York"})

# Using update() with keyword arguments


employee.update(role="Manager")

print(employee)
# Output: {'name': 'David', 'id': 'E104', 'dept': 'HR', 'location': 'New York', 'role': 'Manager'}

Question :17 (b)


What is the difference between lists ,tuples and dictionaries? Give an example for their
usage.

Here’s a clear comparison between Lists, Tuples, and Dictionaries in Python, along with
examples:
🔸 1. List
✅ Characteristics:

Ordered

Mutable (can be changed)

Allows duplicate values

Uses square brackets []

📌 Example:

fruits = ["apple", "banana", "cherry"]


fruits.append("orange")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'orange']

🔧 Use Case:

When you need a collection of items that may change (e.g., a shopping cart).
🔸 2. Tuple
✅ Characteristics:

Ordered

Immutable (cannot be changed)

Allows duplicate values

Uses parentheses ()

📌 Example:

coordinates = (10.5, 20.7)


print(coordinates[0]) # Output: 10.5

🔧 Use Case:
When you need a fixed set of values that shouldn't change (e.g., geographic coordinates).

🔸 3. Dictionary
✅ Characteristics:

Unordered (as of Python 3.6+ insertion order is preserved)

Mutable

Stores key-value pairs

Uses curly braces {}

📌 Example:

employee = {"name": "Alice", "id": "E101", "dept": "HR"}


print(employee["name"]) # Output: Alice

🔧 Use Case:
When you need to associate keys with values (e.g., employee records, configuration settings).

🧠 Summary Table:

Feature List Tuple Dictionary


{key:
Syntax [] ()
value}

Ordered ✅ ✅ (Python
3.6+)
Mutable ✅ ❌ ✅
❌ (Keys
Duplicates ✅ ✅ must be
unique)
Indexed ✅ (via
✅ ✅
Access keys)

Collections Key-value
Use Case Fixed data
that change mappings

Question :18
Expalin in detail python files , its types and operations that can be performed on files with
examples.
Python Files: Explanation, Types, and Operations
🔹 What is a File in Python?
A file is a named location on disk to store data permanently. In Python, you can create, read,
write, and append files using built-in functions.
🔹 Types of Files

1. Text Files (.txt, .csv, .py, etc.)


Stores data in human-readable format.

Example: sample.txt

2. Binary Files (.jpg, .exe, .dat, etc.)


Stores data in binary format (not human-readable).

Example: image.jpg
🔹 File Operations in Python

Python provides a built-in function open() for file handling.

Basic Syntax:
file = open("filename", "mode")

Modes:

Mode Description

'r' Read (default mode)

'w' Write (overwrites if exists)

'a' Append (adds to the end)

'b' Binary mode


Create a new file (error if
'x'
exists)
'r+' Read and write

🔹 Common File Operations

✅ 1. Creating and Writing to a File

file = open("example.txt", "w")


file.write("Hello, this is a Python file.")
file.close()

✅ 2. Reading from a File


file = open("example.txt", "r")
content = file.read()
print(content)
file.close()
✅ 3. Appending to a File

file = open("example.txt", "a")


file.write("\nAdding a new line.")
file.close()

✅ 4. Using with Statement (Best Practice)

Automatically handles closing the file.

with open("example.txt", "r") as file:


print(file.read())
🔹 File Methods in Python

Method Description

.read() Reads entire content

.readline() Reads one line

.readlines(
Reads all lines into a list
)

.write() Writes string to file

.writelines( Writes a list of strings to


) file
.seek(offs
Moves the file pointer
et)
Returns current position
.tell()
of pointer
.close() Closes the file
🔹 Example: Full Usage

# Create and write


with open("employee.txt", "w") as f:
f.write("Name: Alice\nID: E101")

# Append
with open("employee.txt", "a") as f:
f.write("\nDepartment: HR")

# Read
with open("employee.txt", "r") as f:
data = f.read()
print(data)
✅ Summary
Feature Text File Binary File
Human- Machine-
Format
readable readable
Mode 'r', 'w', 'a' 'rb', 'wb', etc

Documents, Images,
Use Case
Logs Videos

Question :19 (a)


Explain about the different types of Exceptions in python.

What is an Exception?

An exception is a runtime error that disrupts the normal flow of a program. Python provides a
powerful and flexible way to handle such errors using try, except, else, and finally blocks.

🔸 Common Types of Exceptions in Python

Exception
Description
Type
ZeroDivisi
Raised when dividing by zero.
onError

TypeError Raised when an operation is performed on the wrong data type.

ValueError Raised when a function receives the correct type but inappropriate value.

IndexError Raised when accessing an invalid index in a list or tuple.

KeyError Raised when a key is not found in a dictionary.

FileNotFo
Raised when a file operation fails due to file not existing.
undError
ImportErro
Raised when importing a module fails.
r
AttributeEr
Raised when an invalid attribute is accessed.
ror
NameErro
Raised when a variable is not defined.
r
Indentatio
Raised when indentation is not correct.
nError

🔸 Examples of Common Exceptions


✅ ZeroDivisionError
try:
result = 10 / 0
except ZeroDivisionError:
print("You can't divide by zero!")

✅ TypeError

try:
num = "2" + 3
except TypeError:
print("Cannot add string and integer.")

✅ ValueError

try:
age = int("twenty")
except ValueError:
print("Invalid input: expected a number.")

✅ IndexError

list1 = [1, 2, 3]
try:
print(list1[5])
except IndexError:
print("Index out of range.")

✅ KeyError

employee = {"name": "Alice"}


try:
print(employee["id"])
except KeyError:
print("Key not found in dictionary.")

🔸 Catching Multiple Exceptions


try:
num = int("ten")
result = 10 / num
except ValueError:
print("Invalid number format.")
except ZeroDivisionError:
print("Cannot divide by zero.")
🔸 finally Block
Used for cleanup actions (always runs).

try:
f = open("file.txt", "r")
except FileNotFoundError:
print("File not found.")
finally:
print("Closing file or cleaning up.")

✅ Summary
Exceptions help make your program more robust and user-friendly.

Use try, except, else, and finally to manage errors.

You can also raise your own exceptions using raise.

Question :19 (b)


Describe about handling Exceptions in detail with examples.

Handling Exceptions in Python – A Detailed Guide

Exception handling in Python is a mechanism to deal with runtime errors and ensure the
program doesn’t crash unexpectedly.
🔹 Why Handle Exceptions?

To prevent the program from crashing


To provide user-friendly error messages
To allow the program to continue or gracefully exit
🔹 Python Exception Handling Keywords

Keyword Description
try Code that might cause an exception

except Code to handle the exception

else Executes if no exception occurs

finally Executes regardless of an exception

🔸 1. Basic Exception Handling


try:
num = int(input("Enter a number: "))
result = 10 / num
print("Result:", result)
except ZeroDivisionError:
print("Error: Cannot divide by zero.")
except ValueError:
print("Error: Invalid input. Please enter a number.")

🔸 2. Using else and finally


try:
num = int(input("Enter a number: "))
result = 10 / num
except ZeroDivisionError:
print("Division by zero error.")
else:
print("Division successful. Result:", result)
finally:
print("This block always executes (cleanup).")

🔸 3. Handling Multiple Exceptions Together

try:
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
print(a / b)
except (ValueError, ZeroDivisionError) as e:
print("Error:", e)

🔸 4. Generic Exception Catching (Not Recommended Always)

try:
x = int("abc")
except Exception as e:
print("An error occurred:", e)

✅ Note: Use general Exception only when you're unsure of the exact error, but it’s better to
catch specific exceptions when possible.

🔸 5. Raising Custom Exceptions


def check_age(age):
if age < 18:
raise ValueError("Age must be 18 or older.")
else:
print("Age is valid.")

try:
check_age(16)
except ValueError as ve:
print("Exception:", ve)

✅ Summary
Block Purpose
try To wrap code that may cause an exception

except To handle specific or general exceptions


else Executes if no exceptions were raised

finally Executes no matter what (used for cleanup)

You might also like