w3 python Flashcards
(33 cards)
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?
==
py
Which set of characters are used to define a LIST?
[“apple”, “banana”, “cherry”]
LISTs use brackets.
py
Which of these collections defines a TUPLE?
(“apple”, “banana”, “cherry”)
TUPLEs use parentheses
py
Which of these collections defines a SET?
{“apple”, “banana”, “cherry”}
SETs use curly braces
py
Which of these collections defines a DICTIONARY?
{“name”: “apple”, “color”: “green”}
DICTIONARIES have the first term colon construction.
py
Which collection is ordered, changeable, and allows duplicate members?
LIST
py
Which collection does not allow duplicate members?
SET
py
How do you start writing an if statement in Python?
if x > y:
py
How do you start writing a while loop in Python?
while x > y:
py
How do you start writing a for loop in Python?
for x in y: