0% found this document useful (0 votes)
10 views

Here are 10 Python multiple-1

Uploaded by

Prajwal HC
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Here are 10 Python multiple-1

Uploaded by

Prajwal HC
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Here are 10 Python multiple-choice questions:

1. What is the correct way to create a function in Python?


a) function myFunction():
b) def myFunction:
c) def myFunction():
d) create myFunction():
Answer: c) def myFunction():

2. What is the output of the following code?


x=5
y = "5"
print(x + int(y))
a) 55
b) 10
c) TypeError
d) 5
Answer: b) 10

3. Which of the following data types is immutable?


a) List
b) Set
c) Dictionary
d) Tuple
Answer: d) Tuple

4. How do you insert an element at index 3 in a Python list my_list?


a) my_list.add(3, element)
b) my_list.insert(3, element)
c) my_list.push(3, element)
d) my_list.append(3, element)
Answer: b) my_list.insert(3, element)

5. What is the correct way to open a file for reading in Python?


a) open("file.txt", "r")
b) open("file.txt", "read")
c) open("file.txt", "w")
d) open("file.txt")
Answer: a) open("file.txt", "r")

6. Which of the following is NOT a valid Python keyword?


a) pass
b) eval
c) async
d) yield
Answer: b) eval

7. What is the output of the following code?


my_list = [1, 2, 3, 4, 5]
print(my_list[-2])
a) 3
b) 4
c) 5
d) IndexError
Answer: b) 4

8. What will be the output of this code snippet?


x = 10
y = 20
x, y = y, x
print(x, y)
a) 10 20
b) 20 10
c) Error
d) None
Answer: b) 20 10

9. Which of the following methods can be used to get the length of a dictionary?
a) len()
b) size()
c) count()
d) length()
Answer: a) len()
10. What is the purpose of the self keyword in Python classes?
a) It is used to initialize the class.
b) It refers to the instance of the class.
c) It is a placeholder for a variable.
d) It is used to call a function inside the class.
Answer: b) It refers to the instance of the class.

Let me know if you need more questions!

You might also like