Finding the first missing positive integer
Given the list [3, 4, -1, 1], what is the first missing positive integer in the list?
- 2
- 0
- 3
- 4
- 1
Python list slicing
What is the output of the following code: my_list = [10, 20, 30, 40]; print(my_list[1:3])?
- [20, 30]
- [10, 20]
- [20, 30, 40]
- [10, 20, 30]
- [30, 40]
String immutability
Which statement about Python strings is correct?
- Strings are immutable
- Strings are mutable
- Strings can be changed in place
- Strings can contain only numbers
- Strings must be declared before use
Variable assignment typo
Which of the following is the correct way to assign the value 5 to a variable named x in Python?
- x = 5
- x := 5
- x == 5
- x =u003E 5
- x equals 5
Function definition
Which line correctly defines a function that takes no arguments and prints 'Hello'?
- def greet(): print('Hello')
- function greet(): print('Hello')
- def greet[]: print('Hello')
- greet() = print('Hello')
- define greet(): print('Hello')
Type conversion
Which function converts the string '123' into an integer in Python?
- int('123')
- str('123')
- float('123')
- list('123')
- number('123')
List element access
If my_list = [9, 8, 7], what does my_list[0] return?
- 9
- 8
- 7
- 0
- my_list
Loop typo
Which of these is the correct syntax for a for loop that iterates over numbers 0 to 2 in Python?
- for i in range(3):
- for(i=0; iu003C3; i++):
- foreach i in range(3):
- for i to 3:
- for i in [0,1,2]
Boolean values
Which of these are valid Boolean values in Python?
- True and False
- Yes and No
- TRUE and FALSE
- true and false
- On and Off
Error handling
Which keyword is used in Python to catch exceptions?
- except
- catch
- error
- handle
- rescue