1/24
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
1. What is the correct way to comment a single line in Python?
# This is a comment
// This is a comment
/* This is a comment */
<!-- This is a comment -->
# This is a comment
2. Which Python function is used to get the length of a list?
len()
count()
size()
length()
3. What is a correct syntax to output "Hello World" in Python?
echo("Hello World")
echo "Hello World"
print("Hello World")
p("Hello World")
print("Hello World")
4. Which one is NOT a legal variable name?
my_var
Myvar
_myvar
my-var
5. How do you create a variable with the numeric value 5?
x = int(5)
x = 5
Both the other answers are correct
x = int(5)
x = 5
6. What is the correct file extension for Python files?
.pt
.pyth
.py
.pyt
7. How do you create a variable with the floating number 2.8?
Both the other answers are correct
x = 2.8
x = float(2.8)
x = 2.8
x = float(2.8)
8. What is the correct syntax to output the type of a variable or object in Python?
print(typeOf(x))
print(typeof(x))
print(type(x))
print(typeof x)
9. In Python, 'Hello', is the same as "Hello"
False
True
10. What is a correct syntax to return the first character in a string?
x = sub("Hello", 0, 1)
x = "Hello".sub(0, 1)
x = "Hello"[0]
Note: In the code x = "Hello"[0], "Hello" is a string, and [0] is used to access the first character of that string, which is "H". So, x will be assigned the value "H".
11. Which method can be used to remove any whitespace from both the beginning and the end of a string?
trim()
len()
ptrim()
strip()
12. Which method can be used to return a string in upper case letters?
toUpperCase()
upper()
uppercase()
upperCase()
13. Which method can be used to replace parts of a string?
replaceString()
repl()
replace()
switch()
14. Which operator is used to multiply numbers?
*
#
%
X
15. Which operator can be used to compare two values?
><
==
<>
=
==
16. Which of these collections defines a LIST?
["apple", "banana", "cherry"]
("apple", "banana", "cherry")
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
17. Which of these collections defines a TUPLE?
("apple", "banana", "cherry")
{"apple", "banana", "cherry"}
["apple", "banana", "cherry"]
{"name": "apple", "color": "green"}
18. Which of these collections defines a SET?
{"apple", "banana", "cherry"}
["apple", "banana", "cherry"]
("apple", "banana", "cherry")
{"name": "apple", "color": "green"}
19. Which of these collections defines a DICTIONARY?
{"name": "apple", "color": "green"}
["apple", "banana", "cherry"]
("apple", "banana", "cherry")
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
20. Which collection is ordered, changeable, and allows duplicate members?
SET
LIST
TUPLE
DICTIONARY
LIST
21. Which collection does not allow duplicate members?
TUPLE
SET
LIST
SET
22. How do you start writing an if statement in Python?
if x > y then:
if (x > y)
if x > y:
23. How do you start writing a while loop in Python?
x > y while {
while (x > y)
while x > y:
while x > y {
24. How do you start writing a for loop in Python?
for x > y:
for each x in y:
for x in y:
25. Which statement is used to stop a loop?
Break
Return
Exit
stop
Break