Font size
WorksheetsPython Basic II
Total questions: 20
Worksheet time: 20mins
In Python, a variable must be declared before it is assigned a value:
False
True
Which of the following statements assigns the value 100 to the variable x in Python:
let x = 100
x = 100
x << 100
x ← 100
x := 100
In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:
False
True
Consider the following sequence of statements:
n = 300
m = n
Following execution of these statements, Python has created how many objects and how many references?
One object, one reference
Two objects, one reference
Two objects, two references
One object, two references
What is the output of the following code:
x = 5
y = "John"
print(x + y)
5 John
x John
Error because x and y are from two different type of data
Error because 5 does not have quotation mark
Which of the following are valid Python variable names:
home_address
route66
4square
ver1.3
Age
You are reading Python code, and these statements appear scattered in different locations throughout the code:
employeenumber = 4398
.
.
.
EmployeeNumber = 4398
.
.
.
employeeNumber = 4398
These statements refer to different variables.
These statements refer to the same variable.
Create a variable named carname and assign the value Volvo to it.
Volvo = carname
Volvo = "carname"
carname = "Volvo"
carname = 'Volvo"
carname = Volvo
Create a variable named x and assign the value 50 to it. The value, 50 is in string type.
x = 50
50 = "x"
x = "50"
x (50)
What symbol is used to access elements of the string?
Curly bracket { }
Round bracket ( )
Square bracket [ ]
What is the output of the following code?
a = "I am cute
print(a[3)
c
m
space
cute
What is the output of the following code:
b = "Programming is fun!"
print(b[2:7)
ogram
ogramm
gram
gramm
a = "Good Morning!"
print(len(a))
13
12
11
14
a = "Hello, World!"
print(a.lower())
hello, World!
HELLO, WORLD!
hello, world!
Error
a = "Hello, World!"
print(a.replace("H", "J"))
Jello, World!
jello, World!
JELLO, WORLD!
jello, world!
a = "Hello, World!"
b = a.split(",")
print(b)
{'Hello, World!'}
('Hello, World!')
['Hello', ' World!']
['Hello'],['World']
x = 7
y = 2
print(x % y)
3
7
4
1
x = 3
y = 3
print(x ** y
27
9
0
81
x = 23
y = 3
print(x // y)
7
7.6666
7.7
Error
What is the output of the following code:
age = 36
txt = "My name is John, I am " + age
print(txt)
My name is John, I am
My name is John, I am 36
Error
