This keyword allows you to exit a loop before the condition becomes false.
What is break?
This type of error occurs when you violate Python’s grammar rules, such as missing a colon.
What is a syntax error?
This module in Python is used for working with regular expressions.
what is re?
This data structure is a fixed-length, mutable collection of elements, not native to Python.
What is an array?
This is the part of a recursive function that stops the function from making further recursive calls.
What is the base case?
In Python, this keyword skips the current iteration of the loop and proceeds to the next iteration.
What is continue?
An error caused by incorrect logic or a mistake in the design of your program, resulting in an unexpected outcome, is called this.
What is a semantic error?
This regular expression function returns all occurrences of a pattern in a string.
What is re.findall()?
This function returns the length of an array.
What is len()?
This term refers to the memory structure where function calls are placed during recursion.
What is the call stack?
Write a while loop that prints numbers from 1 to 5.
i = 1
while i <= 5:
print(i)
i += 1
This block of code handles exceptions that may be raised during execution.
What is try/except?
Write a regular expression pattern to match any string containing digits.
pattern = r'\d+'
In an array, this index is used to access the last element.
len(array) - 1
This is the time complexity of binary search.
What is O(log n)?
This function can be used to generate a sequence of numbers within a for loop.
What is range()?
Unit test have these three steps.
What is setup, invoke & analyze?
This character is used in a regular expression to indicate "zero or more" occurrences of the preceding element.
What is asterisk * ?
Write a Python statement to access the third element in an array, and set it equal to the value 7
array[2] = 7
Write Python code for a linear search that returns the index of a target value in a list lst, or None if not found.
def linear_search(lst, target):
for i in range(len(lst)):
if lst[i] == target:
return i
return None
Write a for loop that iterates over a string and prints each character. It stops if it prints a 'p'
word = "example"
for char in word:
print(char)
if char == 'p':
break
Write code that raises a TypeError if the variable x is not an integer.
x = "hello"
if not type(x) is int:
raise TypeError("Only integers are allowed")
Write a regular expression pattern to match any lowercase letter, followed by any uppercase letter in a string.
pattern = r"[a-z][A-Z]"
Write Python code to initialize an array of 5 integers, with each value equal to it's index + 10.
import array
arr = arrays.Array(5)
for i in range(5):
arr[i] = i + 10
Write Python code for a binary search that returns the index of a target value in a sorted list lst, or None if not found.
def binary_search(lst, target):
low = 0
high = len(lst) - 1
while low <= high:
mid = (low + high) // 2
if lst[mid] == target:
return mid
elif lst[mid] < target:
low = mid + 1
else:
high = mid - 1
return None