Font size
WorksheetsPython
Total questions: 35
Worksheet time: 22mins
How do we define a variable in Python?
variable : 10
variable 10
variable == 10
variable = 10
Which of the following is a correct way to check if two variables are equal in Python?
var1 = var2
var1 == var2
var1 === var2
var1 = = var2
What is the correct way to declare a list in Python?
list = [1, 2, 3]
list : [1, 2, 3]
list (1, 2, 3)
list == [1, 2, 3]
What is the correct way to add an element to the end of a list in Python?
list.add(4)
list.append(4)
list.insert(4)
list.extend(4)
What is the correct way to remove an element from a list in Python?
list.remove(3)
list.delete(3)
list.pop(3)
list.discard(3)
How to initiate an empty list to variable "myList" in python
(a)
How do you define a for loop in that iterates over the numbers from 0 to 10?
(a)
What is the correct way to iterate over a list in Python?
for i in list:
for i in range(len(list)):
for i in range(list):
for i in list(range):
What is the correct way to get the length of a list in Python?
len(list)
list.length()
list.size()
list.count()
How to access an element at index i in Python list?
How do we check if boolean variables var1 and var2 are both in Python?
How do we define an if statement in Python?
What is the correct way to insert an element at a specific index in a Python list?
list.add(index, element)
list.insert(index, element)
list.place(index, element)
list.update(index, element)
What is the correct way to convert a string to uppercase in Python?
str.upper()
str.toUpper()
str.convertUpper()
str.caseUpper()
What will be the output of the following code?
myList = []
for i in range(2,8):
myList.append(i)
print(myList)
name = 'Dave'
print (name)
print(3+4)
print("3+4")
Which of these is a string?
42
True
"This one!"
No, this one
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
numbers = [5, 14 ,9, 17]
for number in numbers:
if number >= 9:
print (number)
The output will be?
17
9
14
9
17
14
17
word= "computer"
for num in range(1,6):
print(word)
Which of the following for loops would print the following numbers?
3 5 7 9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What would be the output of the following code:
for i in range(3):
print(5)
0 1 2
3 3 3 3 3
5 5 5
0 1 2 3 4
What is the correct way to check if a number is even in Python?
number % 2 == 0
number % 2 = 0
number / 2 == 0
number / 2 = 0
What is the correct way to check if a variable is equal to a specific value in Python?
var1 = var2
var1 == var2
var1 === var2
var1 = = var2
Which of the following is a boolean data type in Python?
int
string
bool
float
What will be the output of the following code?
myList = [1, 2, 3]
for i in myList:
print(i * 2)
1 2 3
2 4 6
3 6 9
4 8 12
How do we loop over a list in Python using the range function?
for i in range(my_list): print(my_list[i])
How do we get a string input in Python?
How do we get an integer as an input in Python?
number = input()
number = int(input())
number = input(integer())
number = input(int("Give me an integer"))
