menu

Python Basics


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


2. Which of the following is the correct syntax for defining a function in Python?

function my_function():

def my_function():

define my_function():

func my_function():


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


4.

What is the output of the following code?

print(7 % 3)

2

3

1

7


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

==

>

<

+


6.

What is the output of the following code?

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

15

510

TypeError

None of the above


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

==

!=

<=

<>


8.

What is the result of the following code?

x = ["apple", "banana", "cherry"]
print(len(x))

3

5

6

p


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

x = 1

y = "Hello"

z = 3.14

2 = a


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

Integer

Float

Double

String