Python Assignment Solution
Date of Test: 9-Sept-2025 Date of Submission: 15-Sept-2025
Q1) Find and explain stepwise solution of following expressions if a=3, b=5,
c=10
(i) a & b << 2 // 5 ** 2 + c ^ b
Given: a=3, b=5, c=10
1) Operator precedence: ** → // → << → & → + → ^
2) 5**2 = 25
3) 2//25 = 0
4) So: 3 & 5 << 0 + 10 ^ 5
5) 5<<0 = 5 → 3 & 5 + 10 ^ 5
6) 5+10 = 15 → 3 & 15 ^ 5
7) 3&15 = 3 → 3 ^ 5
8) 3 ^ 5 = 6
Answer = 6
(ii) b >> a ** 2 << 2 >> b ** 2 ^ c ** 3
a**2=9, b**2=25, c**3=1000
5>>9<<2>>25^1000
5>>9=0 → 0<<2=0 → 0>>25=0
0 ^ 1000 = 1000
Answer = 1000
Q2) Differentiate between Python list and arrays
Basis List Array
Data types Can store different data types Stores same data type only
Module needed Built-in Need array or numpy module
Flexibility More flexible Less flexible
Performance Slower Faster
Syntax [1,"a",3] array('i',[1,2,3])
Q3) Consider the program:
Code:
X = ['hello', '12', 456]
X[0] *= 3
X[1][1] = 'bye'
X[0]*=3 → 'hello'*3 = 'hellohellohello' ■
Now list = ['hellohellohello', '12', 456]
X[1][1]='bye' → Error because strings are immutable
Error: TypeError: 'str' object does not support item assignment
Q4) Explain history and features of Python while comparing Python version 2
and 3
History:
- Developed by Guido van Rossum in 1991
- Open-source, interpreted and readable language
Feature Python 2 Python 3
Release Year 2000 2008
Print Statement print "Hello" print("Hello")
Unicode Not default Default UTF-8
Division 5/2=2 5/2=2.5
Support No support Active support
Q5) How are Python numeric data types declared and used
- int → whole numbers
Example: x = 10
- float → decimal numbers
Example: y = 3.14
- complex → real+imaginary
Example: z = 2+3j
They are used in arithmetic operations and checked using type() function.