What will be the output of the following code?
L = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’]
print(L[2:5])
a, b, c
a, b, c, d
c, d, e
c, d, e, f
Which of the following is a valid way to declare a dictionary in Python?
{1: "one", 2: "two", 3: "three"}
[1: "one", 2: "two", 3: "three"]
(1: "one", 2: "two", 3: "three")
<1: "one", 2: "two", 3: "three">
Which of the following method is correct to add an element at a specific position?
insert()
add()
append()
index()
What is the correct syntax to add an item to the end of a list in Python?
list.add(item)
list.append(item)
list.insert(item)
list.extend(item)
Which of the following is not a valid data type in Python?
integer
string
float
character
What is the output of the following code?
for i in range(1, 21):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Prints numbers from 1 to 20
Prints Fizz for multiples of 3 and Buzz for multiples of 5
Prints FizzBuzz for multiples of 3 and 5
None of the above
What is the output of the following code?
a = 5
b = 2
print(a // b)
2
2.5
3
2.0
What is the output of the following code?
s = "hello"
print(s[::-1])
"hello"
"olleh"
"hlo"
"leh"
What is the output of the following code?
a = 10
b = 5
c = a % b
print(c)
2
5
0
1
What is the output of the following code?
s = "python"
print(s[1:4])
"pyt"
"yth"
"tho"
"hon"