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 way to remove an element from a list in Python?

list.remove(element)

list.pop(element)

del list[element]

All of the above


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

x = 1

y = "Hello"

z = 3.14

2 = a


4.

What is Python?

A high-level programming language

A database management system

A low-level programming language

A markup language


5.

What is the output of the following code?

x = 2
y = 5
z = x + y
print("The sum of", x, "and", y, "is", z)

The sum of 2 and 5 is 7

The sum of x and y is z

The sum of x and y is 7

None of the above


6.

What is the output of the following code?

x = 3
if x > 5:print("x is greater than 5")
elif x > 2:print("x is greater than 2")
else:print("x is less than or equal to 2")

x is greater than 5

x is greater than 2

x is less than or equal to 2

None of the above


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

class my_class():

define class my_class:

def my_class():

class my_class:


8.

What is the output of the following code?

print("Hello" + " World")

Hello

World

Hello World

Type Error


9. Which of the following is the correct way to check if a key is in a dictionary in Python?

dict.contains(key)

dict.has_key(key)

key in dict

dict.get(key)


10. 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