Question: 1 -
Please select the correct expression to reassign a global variable “x” to 20 inside a function fun1()
x = 50
def fun1():
# your code to assign global x = 20
fun1()
print(x) # it should print 20
-
global x x = 20
-
global.x = 20
-
global x =20
-
global var x x = 20
Answer:
global x
x = 20
Solution not available.
Question: 2 -
What is the data type of the followingaTuple = (1, 'Jhon', 1+3j)
print(type(aTuple[2:3]))
-
complex
-
int
-
list
-
tuple
Answer:
tuple
Solution:
When we access a tuple using the subscript atuple[start : end]
operator, it will always return a tuple. We also call it tuple slicing. (taking a subset of a tuple using the range of indexes).
When we access a tuple using the subscript atuple[start : end]
operator, it will always return a tuple. We also call it tuple slicing. (taking a subset of a tuple using the range of indexes).
Question: 3 -
What is the data type of print(type(0xFF))
-
hex
-
int
-
hexint
-
number
Answer:
0b
or0B
for Binary and base is 20o
or0O
for Octal and base is 80x
or0X
for Hexadecimal and base is 16
int
Solution:
We can represent integers in binary, octal and hexadecimal formats.
We can represent integers in binary, octal and hexadecimal formats.
Question: 4 -
What is the output of the following codedef func1():
x = 50
return x
func1()
print(x)
-
0
-
50
-
None
-
NameError
Answer:
NameError
Solution:
You will get a NameError: name 'x' is not defined
. To access the function’s return value we must accept it using an assignment operator like this
def myfunc():
x = 50
return x
x = myfunc()
print(x)
You will get a NameError: name 'x' is not defined
. To access the function’s return value we must accept it using an assignment operator like this
def myfunc():
x = 50
return x
x = myfunc()
print(x)
Question: 5 -
In Python 3, what is the output of type(range(5))
. (What data type it will return).
-
None
-
range
-
list
-
int
Answer:
range