menu

Python Basics


1.

What is the output of the following code?

x = 5
print("x =", x)

x = 5

x

5

x, 5


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


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

==

!=

<=

<>


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


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

Integer

Float

Double

String


6.

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


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


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


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

==

>

<

+


10. Which of the following is a valid Python variable name?

1_name

my_variable

$test

class