Write a statement to print the imaginary component of c
print(c.imag)
Dictionaries are indexed by ____________ and lists are indexed by _____________
keys
integers
The function fabs() belongs to which module:
math
Namespace resolution in Python is done by _____________ order
LEGB
Name the augmented operator of Python
+=
-=
*=
What is the output of the following code?
i=5
def change(i):
i=i+1
return i
for i in (1,2,3)
change(i)
print(i)
1
2
3
>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
>>>max(a[2:4])
qux
…………..function returns the smallest integer greater than the given floating point number.
ceil()
d={}
def f(i):
d[i]=i
for i in range(4):
f(i)
print(d)
{0: 0, 1: 1, 2: 2, 3: 3}
Rahul has created the a tuple containing some numbers as
>>>t=(10,20,30,40)
He wants to add an element 60 to it
How does he do it
def change(i = 1, j = 2):
i=i+j
j=j+1
print(i, j)
change(j = 1, i = 2)
3 2
d={4:2,9:3}
d2=d.copy()
print(d is d2)
False
What will be the output of the following Python function? all([2,4,0,6])
False
def f1():
global x
x+=x
print(x)
x=12
f1()
print("x")
24
x
import random
a=[4,1,9,6]
print(a.shuffle())
None
def foo(x):
x = ['def', 'abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
False
x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']
Write a statement to print zb from x
print(x[1][2][1][::-2])
Write a statement to generate a random number between 15.5 and 40.5
random.uniform(15.5,40.5)
#What is the output of the code shown?
#The output of code shown below is: x=5
def f1():
global x
x=4
def f2(a,b):
global x
return a+b+x
f1()
total = f2(1,2)
print(total)
7
Find the output
a=input('Enter a number')
for i in range(1,4):
a=a*i
print(a)
#Input entered is 12.2
12.212.212.212.212.212.2
Find the output
def foo(i, x=[]):
x.append(x.append(i))
return x
for i in range(3):
y = foo(i)
print(y)
[0, None, 1, None, 2, None]
D = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'}
print(D[D[D[1][2]]])
E
print(len(str(round(4.673))))
1
x = 10
print('x is ',x)
def outer():
x = 20
print('x is ',x)
def inner():
x = 30
print('x is ',x)
print(len(str(x))
inner()
outer()
Name the variables showing
local scope
enclosed scope
built in scope
Local
x=30
Enclosed
x=20
Global
x=10
Built in
len(str(x))