Basics of Python - DPP 01
Basics of Python - DPP 01
DS&AI
Python for Data Science DPP: 1
Basics of Python
Q1 The output of below python code segment is
_________ (A) A-1, B-2, C-2, D-1
a = 5.5 (B) A-2, B-2, C-1, D-1
b = 2.0 (C) A-2, B-1, C-2, D-2
c=2 (D) A-2, B-1, C-1, D-2
d = –2.0
Q5 The output of below code segment is _________
e = a // b
a = 0° 63
f = d // c
b = a<<2
print (e + f)
c = a>>3
(A) 0 (B) 0.0
print(b+c)
(C) 1.0 (D) –1.0
Q6 What will be printed by below Python Code?
Q2 The ascending order Of Precedence of below
i=0xAE1
Operators is ________
j = i & 152
1. not in
k = j | 100
2. <<
print (k)
3. not
(A) 344 (B) 00344
4. ^
(C) 0xe4 (D) 228
(A) 3, 2, 1, 4 (B) 3, 1, 2, 4
(C) 3, 1, 4, 2 (D) 2, 4, 1, 3 Q7 What will be the value of result in the below
code?
Q3 The result after evaluating the below expression
x = 0b01010110
in Python is _________
y = 0x123
result = 14 & 4 + 5 << 2 ^ 19 + 3 // 7 – 3 >> 4
z = 42
Q4 Match The Following Operators with their result=x+y-z
associativity. (A) 517 in octal
(B) 517 in decimal
LIST-I LIST-II (C) 1f4 in hexa decimal
(D) 335 in in decimal
(A) ** (Exponentiation) 1. Left To Right
Q8 What will be the value of k in the below code?
i = –13.5
(B) & (Bitwise AND) 2. Right To Left
j=5
k=i%j
(C) is not (Identity)
print (k)
(A) 0.0 (B) 1.5
(D) = (Assignment)
(C) 3.5 (D) –1.5
1/5
GATE
Answer Key
Q1 (C) Q5 210
Q2 (C) Q6 (D)
Q3 5 Q7 (A, D)
Q4 (D) Q8 (B)
2/5
GATE
3/5
GATE
Conclusion
The result of the expression 14 & 4 + 5 << 2 ^
Q5 Text Solution:
19 + 3 // 7 - 3 >> 4 is 5.
Left Shift (a << 2):
Q4 Text Solution:
Operators and Their Associativity 63 << 2 means shifting the bits of 63
(which is 00111111 in binary) left by 2
1. Exponentiation (**)
positions.
Associativity: Right to Left Result: 11111100 in binary, which is 252 in
Explanation: Exponentiation in Python is decimal.
evaluated from right to left, meaning 2 **
Right Shift (a >> 3):
3 ** 2 is evaluated as 2 ** (3 ** 2).
63 >> 3 means shifting the bits of 63
2. Bitwise AND (&)
(which is 00111111 in binary) right by 3
Associativity: Left to Right positions.
Explanation: Bitwise AND is evaluated from Result: 00000111 in binary, which is 7 in
left to right, meaning a & b & c is decimal.
evaluated as (a & b) & c.
Q6 Text Solution:
3. Identity (is not)
1. Hexadecimal to Decimal Conversion
Associativity: Right to Left
Explanation: Identity operators like is not i = 0xAE1 represents a hexadecimal
are evaluated from left to right, but they number. Convert it to decimal:
4/5
GATE
5/5