Question 1
EasyWhat is the output of this code?
x = [1, 2, 3]
y = x
y.append()
((x))
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this code?
x = [1, 2, 3]
y = x
y.append()
((x))
3
4
Error
None
Answer: B
y = x does not copy the list; both names refer to the same list object. Appending through y changes the list that x refers to, so its length is 4.
What is the output of this program?
print(type([1, 2, 3]))
<class 'tuple'>
<class 'set'>
<class 'list'>
<class 'dict'>
Answer: C
Square brackets create a list.
What is the output of this program?
print(7 / 2)
3.5
4
3
3.0
Answer: A
/ is true division in Python 3 and always returns a float.
What is the output of this program?
print(7 // 2)
3.5
3.0
4
3
Answer: D
// is floor division: 7 // 2 = 3.
Which of these Python types is immutable?
dict
set
list
tuple
Answer: D
Tuples can't be changed after creation; lists, dicts and sets can.
What is the output of this program?
print([x * x for x in range(4)])
[0, 1, 2, 3]
[1, 4, 9, 16]
[0, 2, 4, 6]
[0, 1, 4, 9]
Answer: D
The list comprehension squares each number from 0 to 3.
What is the output of this program?
print(2 ** 3)
6
8
9
5
Answer: B
** is exponentiation: 2³ = 8.
What is the output of this program?
name = "Asha"
print(f"Hello, {name}!")
Error
Hello, {name}!
Hello, Asha!
Hello, name!
Answer: C
An f-string substitutes the value of name into the braces.
What is the output of this program?
print(type(3.0).__name__)
float
int
str
double
Answer: A
3.0 has a decimal point, so it's a float.
What is the output of this program?
print(7 // 2, 7 % 2)
3.5 1
3 0
4 1
3 1
Answer: D
// is floor division (3) and % is the remainder (1).