menu

Python Basics


1. Which of the following is the correct way to concatenate two lists in Python?

list1.add(list2)

list1.append(list2)

list1 + list2

list1.extend(list2)


2. Which of the following is the correct syntax for defining a function in Python?

function my_function():

def my_function():

define my_function():

func my_function():


3. Which of the following is the correct syntax for a while loop in Python?

while i in range(10):

while (i < 10)

while (i != 10)

while i = 10


4. Which of the following is the correct way to sort a list in descending order in Python?

list.sort(reverse=True)

list.sort(reverse=False)

list.reverse()

None of the above


5. Which of the following is a valid way to comment a single line of Python code?

// This is a comment

/* This is a comment */

# This is a comment

// This is a comment //


6. Which of the following is the correct way to open a file in Python?

open_file("example.txt")

open("example.txt")

file.open("example.txt")

with open("example.txt") as file:


7. Which of the following is the correct way to define a function in Python?

function_name(arguments):

def function_name(arguments):

function_name(arguments)

None of the above


8. Which of the following is NOT a valid way to declare a variable in Python?

x = 1

y = "Hello"

z = 3.14

2 = a


9. Which of the following is NOT a comparison operator in Python?

==

>

<

+


10.

What is the output of the following code?

print(7 % 3)

2

3

1

7