1) List any 2 main features of python?
1. Easy-to-Read Syntax-
- Python’s syntax is clean and intuitive, often resembling plain English.
-Beginner friendly and great for rapid development.
2. Extensive Standard Library
- Python comes with a rich set of built-in modules and functions.
- It saves time and effort by providing ready-to-use tools.
2)Mention two real world applications of python
1. Artificial Intelligence & Machine Learning
- Python is the go-to language for AI and ML thanks to libraries like
TensorFlow, PyTorch, and scikit-learn.
2. Web Development
- Frameworks like Django and Flask make building websites fast and scalable.
- Companies like Instagram, Spotify, and Reddit use Python to win backend
logic, user authentication, and data management.
3) define variables in python with 1 eg.
A variable in Python is a named storage location used to hold data.
It acts like a container that stores a value, which you can use and change
later in your program.
Eg.
Age = 25
age is the variable name.
- 25 is the value assigned to it.
- Now, whenever you use age in your code, Python knows you’re referring to
the number 25.
4) name two types of python operator
1. Arithmetic Operators
Used to perform mathematical operations like addition, subtraction,
multiplication, etc.
Example:
python
X = 10
Y=3
Print(x + y) # Output: 13
2. Comparison Operators
Used to compare values and return a Boolean result (True or False).
python
A=5
B=7
Print(a < b) # Output: True
5) difference between implicit and explicit type conversation
Implicit Type Conversion
Implicit = Python decides for you.
- Done automatically by Python.
- Happens when mixing data types in expressions.
- Python converts the smaller type to a larger type to avoid data loss.
Example:
X = 10 # Integer
Y = 2.5 # Float
Result = x + y # Python converts x to float
Print(result) # Output: 12.5
Explicit Type Conversion
Explicit = You decide for Python.
- Done manually by the programmer.
- Uses built-in functions like int(), float(), str(), etc.
- Useful when you want precise control over data types.
Example:
python
A = “100”
B = int(a) # Convert string to integer
Print(b + 50) # Output: 150
6) write a program to swap 2 numbers using 3rd variables
7) write a program to check whether a program is even or odd
8) write a program to print the multiplication table of a number
9) count the vowels in the string python programming
10)write a program to calculate the sum of the digits of number
UNIT-2
1) create a list of integers from 1 to 5
List of integers from 1 to 5 using the range() function like this:
numbers = list(range(1, 6))
This generates the list [1, 2, 3, 4, 5]. The range() function includes the start
value (1) but excludes the end value (6), so it stops at 5.
2) Differentiate between a tuple and list in python?
List
- Definition: An ordered, mutable (changeable) collection of items.
- Syntax: Square brackets []
-When to use: When you need a collection that can change — add, remove,
or modify elements.
- Example:
My_list = [1, 2, 3, 4]
My_list[0] = 10 # ✅ Allowed (mutable)
Print(my_list) # [10, 2, 3, 4]
Tuple
- Definition: An ordered, immutable (unchangeable) collection of
items.
- Syntax: Parentheses ()
- When to use: When you want data to remain constant and
protected from modification.
- Example:
My_tuple = (1, 2, 3, 4)
My_tuple[0] = 10 # ❌ Error: ‘tuple’ object does not support item
assignment
Print(my_tuple) # (1, 2, 3, 4)
3) how do you remove duplicate values from a list using a set? Write
a one-line example
Uniquelist = list(set(mylist))
This works because sets in Python automatically remove duplicate values.
Uniquelist = list(dict.fromkeys(mylist))
4) output of the code
my_set={1,2,2,3,4}
Print=(my_set)
Output:
{1, 2, 3, 4}
5) what does the following code return?
Dict(enumerate([ ‘a’,’b’,’c’]))
Output:-
{0: ‘a’, 1: ‘b’, 2: ‘c’}
6)define a lambda function . write an eg that returns the square of number.
A lambda function in Python is a small, anonymous function defined using
the keyword lambda instead of def.
Square = lambda x: x**2
Print(square(5)) # Output: 25
7) Differentiate between positional arguments and keyword arguments
Positional Arguments
Passed to a function in the exact order the parameters are defined.
- The position of each value determines which parameter it is assigned to.
- You cannot skip parameters in between.
- Less explicit — you must remember the parameter order.
- Example:
Def greet(name, age):
Print(f”Hello {name}, you are {age} years old.”)
Greet(“Alice”, 25) # Order matters
Keyword Arguments
- Passed to a function by explicitly naming the parameter.
- Order does not matter as long as the names match.
- More readable and self-explanatory.
- Allows skipping optional parameters.
- Example:
Def greet(name, age):
Print(f”Hello {name}, you are {age} years old.”)
Greet(age=25, name=”Alice”) # Order doesn’t matter
8) write the output of
List(zip([1,2,3],[‘a’,b’,’c’]))
Output:–
[(1, ‘a’), (2, ‘b’), (3, ‘c’)]
9) write one line dictionary comprehension to create {1:1,2:4,3:9}
Squares = {x: x**2 for x in range(1, 4)}
10) what will be the result of the following code
From functools import reduce
Reduce(lambda x,y:x+y,[1,2,3,4])
Output:-10