1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
1. What is a correct command line syntax for checking if python is installed on your computer?
(and to check the Python version also)
python --version
python ##version
python version
python --version
2. What is a correct syntax to exit the Python command line interface?
exit()
stop()
end()
exit()
3. True or False: Indentation in Python is for readability only.
True
False
False
4. What is the missing part of the code below to output “Hello World”? ________("Hello World")
run
output
5. Complete the code block, print "YES" if 5 is larger than 2.
if 5 > 2:
print “YES”
print("YES")
print (YES)
print("YES")
6. What is a correct way to declare a Python variable?
var x = 5
#x = 5
$x = 5
x = 5
x = 5
7. True or False: You can declare string variables with single or double quotes. Example:
x = "John"
# is the same as
x = 'John'
True
False
True
8. True or False: Variable names are not case-sensitive. Example:
a = 5
# is the same as
A = 5
True
False
False
9. What is a correct syntax to add the value 'Hello World', to 3 variables in one statement?
x, y, z = 'Hello World'
x = y = z = 'Hello World'
x|y|z = 'Hello World'
x = y = z = 'Hello World'
10. Consider the following code:
print('Hello', 'World')
What will be the printed result?
Hello, World
Hello World
HelloWorld
Hello World
11. Consider the following code:
a = 'Hello'
b = 'World'
print(a + b)
What will be the printed result?
a + b
Hello World
HelloWorld
HelloWorld
12. Consider the following code:
a = 4
b = 5
print(a + b)
What will be the printed result?
45
9
4 + 5
9
13. Consider the following code:
x = 'awesome'
def myfunc():
x = 'fantastic'
myfunc()
print('Python is ' + x)
What will be the printed result?
Python is awesome
Python is fantastic
Python is awesome
14. Which is NOT a legal numeric data type in Python:
int
long
float
long
15. What will be the result of the following code:
x = 'Welcome'
print(x[3])
Wel
c
Welcome Welcome Welcome
c
16. Use the len function to print the length of the string.
x = "Hello World"
print(len(x))
print(lenx)
print(len x)
print(len(x))
17. Get the first character of the string txt.
txt = "Hello World"
x = 0
x = txt[0]
x = text(0)
x = txt[0]
18. Select the correct keyword to check if the word 'free' is present in the text:
txt = 'The best things in life are free!'
if 'free' __________ txt:
print('Yes, free is present in the text.')
contains
present
in
match
in
19. What is a correct syntax to print a string in upper case letters?
'Welcome'.upper()
'Welcome'.toUpper()
'Welcome'.toUpperCase()
'Welcome'.upper()
20. Return the string without any whitespace at the beginning or the end.
txt = " Hello World "
x = txt.strip()
x = txt.strip
x = txt.strip(0)
x = txt.strip()