menu

Python Basics


1.

What is the output of the following code?

x = "Hello World"
print(x[4])

H

e

l

o


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


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

==

>

<

+


4.

What is the output of the following code?

x = [1, 2, 3]
y = x
y[0] = 4
print(x)

[1, 2, 3]

[4, 2, 3]

[1, 4, 3]

[1, 2, 4]


5. Which of the following is the correct way to convert a string to an integer in Python?

int(string)

str(int)

string.int()

All 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 an advantage of using Python?

Easy to learn and use

Low-level access to system resources

Better performance than other programming languages

Limited library support


8. Which of the following is NOT a data type in Python?

Integer

Float

Double

String


9.

Which of the following is a valid variable name in Python?

123var

_variable

class

2_for_1


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

Integer

Float

String

List