Python Mcq Easy Level Series -1

Python Easy Level MCQs (1-20)

1. What is Python?

  • A) A type of snake
  • B) A high-level programming language
  • C) A popular web browser
  • D) A database management system

Answer: B) A high-level programming language

  • Explanation: Python is a high-level programming language widely used for various applications, including web development, data analysis, and automation.

2. Which symbol is used to indicate a comment in Python?

  • A) % (percent)
  • B) // (double forward slash)
  • C) # (hash)
  • D) @ (at symbol)

Answer: C) # (hash)

  • Explanation: In Python, the # symbol is used to indicate single-line comments. Comments are not executed by the Python interpreter and are used for documentation and code explanations.

3. How do you print “Hello, World!” to the console in Python?

  • A) output("Hello, World!")
  • B) print("Hello, World!")
  • C) display("Hello, World!")
  • D) show("Hello, World!")

Answer: B) print("Hello, World!")

  • Explanation: The print function in Python is used to display output to the console. In this case, it will print “Hello, World!”.

4. Which data type is used to store a sequence of characters in Python?

  • A) int
  • B) float
  • C) str
  • D) bool

Answer: C) str (string)

  • Explanation: The str data type in Python is used to store a sequence of characters, such as text.

5. What is the result of the expression 5 + 3 * 2 in Python?

  • A) 16
  • B) 11
  • C) 13
  • D) 26

Answer: B) 11

  • Explanation: In Python, multiplication (*) takes precedence over addition (+). So, the expression is evaluated as 5 + (3 * 2), which equals 11.

6. How do you create a single-line comment in Python?

  • A) /* This is a comment */
  • B) <!– This is a comment –>
  • C) // This is a comment
  • D) # This is a comment

Answer: D) # This is a comment

  • Explanation: In Python, single-line comments are created using the # symbol.

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

  • A) 123variable
  • B) _variable
  • C) variable-name
  • D) variable name

Answer: B) _variable

  • Explanation: Variable names in Python can start with an underscore (_) or a letter and can contain letters, numbers, and underscores.

8. What is the Python operator for exponentiation?

  • A) ^
  • B) **
  • C) %
  • D) //

**Answer: B) **

  • Explanation: The ** operator is used for exponentiation in Python. For example, 2 ** 3 represents 2 raised to the power of 3, which is 8.

9. Which of the following is a valid way to create an empty list in Python?

  • A) list()
  • B) [ ]
  • C) {}
  • D) tuple()

Answer: A) list()

  • Explanation: You can create an empty list in Python using the list() constructor.

10. What is the output of the following code?

python

x = 5 y = 3 print(x > y)

  • A) True
  • B) False
  • C) 5
  • D) 3

Answer: A) True

  • Explanation: The code compares x (which is 5) and y (which is 3) using the > operator. Since 5 is greater than 3, the result is True.

11. Which of the following data types is mutable in Python?

diff

- A) int - B) float - C) str - D) list

Answer: D) list

  • Explanation: Lists are mutable in Python, which means you can change their contents after creation.

12. How do you declare a variable in Python?

css

- A) Using the `var` keyword - B) Using the `let` keyword - C) By assigning a value to a name - D) By declaring its type

Answer: C) By assigning a value to a name

  • Explanation: In Python, you declare a variable by assigning a value to a name. The variable’s type is determined dynamically.

13. What is the output of the following code?

python

my_list = [1, 2, 3] my_list.append(4) print(my_list)

  • A) [1, 2, 3]
  • B) [4]
  • C) [1, 2, 3, 4]
  • D) [1, 2, 3, [4]]

Answer: C) [1, 2, 3, 4]

  • Explanation: The append method is used to add an element to the end of a list. In this case, it appends the value 4 to the list, resulting in [1, 2, 3, 4].

14. What is the purpose of a Python function’s return statement?

vbnet

- A) To print output to the console - B) To terminate the program - C) To specify the function's name - D) To return a value from the function

Answer: D) To return a value from the function

  • Explanation: The return statement in a Python function is used to specify the value that the function should return when it is called.

15. What is the output of the following code?

python

x = "Hello" y = "World" print(x + y)

  • A) Hello World
  • B) HelloWorld
  • C) “Hello” + “World”
  • D) Error

Answer: A) Hello World

  • Explanation: The + operator is used for string concatenation in Python. It combines the strings x and y into “HelloWorld”.

16. Which of the following is not a valid way to comment out multiple lines of code in Python?

markdown

- A) Using triple single-quotes (`'''`) - B) Using triple double-quotes (`"""`) - C) Using `//` at the beginning of each line - D) Using `#` at the beginning of each line

Answer: C) Using // at the beginning of each line

  • Explanation: In Python, // is used for integer division, not for commenting out lines.

17. Which of the following Python data structures stores key-value pairs?

diff

- A) List - B) Tuple - C) Set - D) Dictionary

Answer: D) Dictionary

  • Explanation: A dictionary in Python stores key-value pairs, allowing you to map keys to corresponding values.

18. How do you round the number 3.14159 to the nearest integer in Python?

markdown

- A) `round(3.14159)` - B) `int(3.14159)` - C) `ceil(3.14159)` - D) `floor(3.14159)`

Answer: A) round(3.14159)

  • Explanation: The round function in Python is used to round a floating-point number to the nearest integer.

19. Which Python keyword is used to define a function?

diff

- A) function - B) def - C) define - D) func

Answer: B) def

  • Explanation: In Python, the def keyword is used to define a function.

20. What is the output of the following code?

python

my_string = "Python" print(my_string[2:4])

  • A) Py
  • B) th
  • C) Pyt
  • D) thon

Answer: B) th

  • Explanation: This code uses slicing to extract the characters from index 2 (inclusive) to index 4 (exclusive) of the string, resulting in “th.”

Leave a Comment

error: Content is protected !!