Python quiz Dr.Seetan
How do you insert COMMENTS in Python code? #This is a comment /*This is a comment*/ //This is a comment
#This is a comment
Which of these collections defines a TUPLE? ("apple", "banana", "cherry") {"name": "apple", "color": "green"} ["apple", "banana", "cherry"] {"apple", "banana", "cherry"}
("apple", "banana", "cherry")
Which operator is used to multiply numbers? * % x #
*
How do you create a variable with the floating number 2.8? x = 2.8 x = float(2.8) Both the other answers are correct
Both the other answers are correct
How do you create a variable with the numeric value 5? x = 5 x = int(5) Both the other answers are correct
Both the other answers are correct
What is the correct file extension for Python files? .py .pyt .pyth .pt
.py
Which operator can be used to compare two values? = <> == ><
==
Which statement is used to stop a loop? break exit return stop
break
In Python, 'Hello', is the same as "Hello" True False
True
Which method can be used to return a string in upper case letters? upper() uppercase() upperCase() toUpperCase()
upper()
How do you start writing a while loop in Python? while x > y: while x > y { while (x > y) x > y while {
while x > y:
What is a correct syntax to return the first character in a string? x = "Hello"[0] x = "Hello".sub(0, 1) x = sub("Hello", 0, 1)
x = "Hello"[0]
Which of these collections defines a SET? {"apple", "banana", "cherry"} ["apple", "banana", "cherry"] {"name": "apple", "color": "green"} ("apple", "banana", "cherry")
{"apple", "banana", "cherry"}
Which collection is ordered, changeable, and allows duplicate members? TUPLE LIST DICTIONARY SET
List
What is the correct way to create a function in Python? def myFunction(): create myFunction(): function myfunction():
def myFunction():
How do you start writing a for loop in Python? for x in y: for x > y: for each x in y:
for x in y:
How do you start writing an if statement in Python? if x > y: if (x > y) if x > y then:
if x > y:
Which one is NOT a legal variable name? my-var my_var Myvar _myvar
my-var
What is a correct syntax to output "Hello World" in Python? print("Hello World") echo "Hello World" echo("Hello World"); p("Hello World")
print("Hello World")
What is the correct syntax to output the type of a variable or object in Python? print(type(x)) print(typeof(x)) print(typeOf(x)) print(typeof x)
print(type(x))
Which method can be used to replace parts of a string? replace() switch() repl() replaceString()
replace()
Which collection does not allow duplicate members? SET LIST TUPLE
set
Which of these collections defines a LIST? ["apple", "banana", "cherry"] ("apple", "banana", "cherry") {"name": "apple", "color": "green"} {"apple", "banana", "cherry"}
["apple", "banana", "cherry"]
Which method can be used to remove any whitespace from both the beginning and the end of a string? strip() trim() len() ptrim()
strip()
Which of these collections defines a DICTIONARY? {"name": "apple", "color": "green"} ["apple", "banana", "cherry"] ("apple", "banana", "cherry") {"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}