w3 python Flashcards
py
What is a correct syntax to output “Hello World” in Python?
print(“Hello World”)
py
How do you insert COMMENTS in Python code?
#
py
Which one is NOT a legal variable name?
my-var
py
How do you create a variable with the numeric value 5?
x = int(5)
or
x = 5
py
What is the correct file extension for Python files?
.py
py
How do you create a variable with the floating number 2.8?
x = float(2.8)
or
x = 2.8
py
What is the correct syntax to output the type of a variable or object in Python?
print(type(x))
py
What is the correct way to create a function in Python?
def myFunction():
py
In Python, ‘Hello’, is the same as “Hello”
True
py
What is a correct syntax to return the first character in a string?
x = “Hello”[0]
py
Which method can be used to remove any whitespace from both the beginning and the end of a string?
strip()
py
Which method can be used to return a string in upper case letters?
upper()
py
Which method can be used to replace parts of a string?
replace()
py
Which operator is used to multiply numbers?
*
py
Which operator can be used to compare two values?
==