1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a syntax error in Python?
An error in the structure of the code, such as a missing colon or unmatched parentheses.
What does the try-except block do?
It handles runtime errors and prevents the program from crashing.
What does the .lower() method do to a string?
It converts all characters in the string to lowercase.
What is the purpose of the len() function?
It returns the number of characters in a string or items in a list.
What is a list in Python?
A collection of items stored in a single variable, defined using square brackets.
What does the append() method do?
It adds an item to the end of a list.
What is a function in Python?
A reusable block of code that performs a specific task.
What is the difference between = and ==?
'=' assigns a value to a variable, '==' compares two values for equality.
What does the input() function do?
It allows the user to enter data into the program.
What is a logic error?
An error where the program runs but produces incorrect results.
What is the output of: print('Hello'[1])
'e'
What is the output of: print('abc'.upper())
'ABC'
What is the output of: print(len('Python'))
6
What does this code do?
for i in range(3):
print(i)
Prints 0, 1, 2 each on a new line.
What is the output of:
name = 'Naomi'
print(f'Hi {name}')
'Hi Naomi'
What does this code do?
nums = [1, 2, 3]
nums.reverse()
print(nums)
Prints [3, 2, 1]
What is the output of:
print('hello world'.title())
'Hello World'
What does this code do?
def add(a, b):
return a + b
print(add(2, 3))
Defines a function and prints 5.
What is the output of:
print('abc def'.split())
['abc', 'def']
What does this code do?
while True:
break
Starts an infinite loop but breaks immediately.