menu

Python Basics


1.

What is Python?

A high-level programming language

A database management system

A low-level programming language

A markup language


2. Which of the following is the correct way to concatenate two strings in Python?

string1.join(string2)

string1.concat(string2)

string1 + string2

All of the above


3.

What is the output of the following code?

print("Hello" + " World")

Hello

World

Hello World

Type Error


4. Which of the following is an example of a mutable data type in Python?

Integer

Float

String

List


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

file = open(filename, "r")

file = open("r", filename)

file = open(filename, "w")

None of the above


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


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


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


9. Which of the following is the correct way to read a line from a file in Python?

file.readline()

file.read(line)

read(file, line)

file.read()


10.

What is the output of the following code?

x = 5
y = "10"
print(x + y)

15

510

TypeError

None of the above