menu

Python Basics


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


2.

What is the output of the following code?

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

15

510

TypeError

None of the above


3.

What is the output of the following code?

print(7 % 3)

2

3

1

7


4.

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

123var

_variable

class

2_for_1


5. 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:


6.

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


7.

What is the output of the following code?

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

H

e

l

o


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 the correct way to convert a string to an integer in Python?

int(string)

str(int)

string.int()

All of the above


10. Which of the following is the correct way to define a multi-line string in Python?

This is a multi-line string

'''This is a multi-line string'''

"This is a multi-line string"

All of the above