👋 Hello

10 Basic Python Questions and Answers with Code | Python MCQs

1 comment

This article provides 10 multiple-choice questions on fundamental Python concepts and syntax, along with their answers and code snippets. These questions cover topics such as operators, lists, strings, functions, and maps, and are suitable for anyone learning Python, preparing for coding interviews, or testing their knowledge. Whether you are a beginner or an intermediate Python developer, this set of Python MCQs will help you test and improve your understanding of the language.

1 : Basic

What is the output of the following code snippet ?


       x = 5
       y = 2
       print(x % y)
        
0
1
2
3

2 : list

What is the output of the following code snippet ?


        x = [1, 2, 3, 4, 5]
        y = x[1:3]
        print(y)
          
[1,2]
[2,3]
[2,3,4]
[3,4]

3 : Basic

What is the output of the following code snippet ?


            x = "Hello World"
            print(x[3:7])
           
'Hello'
'lo W'
'llo W'
None

4 : List

What is the output of the following code snippet ?


      x = [1, 2, 3]
      y = [4, 5, 6]
      z = x + y
      print(z)
     
[[1, 2, 3], [4, 5, 6]]
[1, 2, 3, 4, 5, 6]
1, 2, 3, [4, 5, 6]]
[1, 2, 3, 4, 5, 6]

5 : Basic

What is the output of the following code snippet ?


      x = 5
      y = "6"
      print(x + y)
      
11
56
'56'
Type Error

6 : List

What is the output of the following code snippet ?


    x = ["apple", "banana","cherry"]
    y = [i.upper() for i in x]
    print(y)
      
) ["Apple", "Banana", "Cherry"]
["APPLE", "BANANA", "CHERRY"]
["apple", "banana", "cherry"]
["A", "B", "C"]

7

What is the output of the following code snippet ?


      x = "banana"
      y = "apple"
      print(x > y)
     
True
False
Type Error
Syntax Error

8 : Dictionary

What is the output of the following code snippet ?


      x = {"name": "John", "age": 30}
      y = x.get("gender", "male")
      print(y)
     
'Male'
30
'John'
None

9 : List


     x = [1, 2, 3, 4, 5]
     y = [i * 2 for i in x if i % 2 == 0]
     print(y) 
    
[2, 4, 6, 8, 10]
[4, 8]
[1, 2, 3, 4, 5]
[2, 4, 6, 8]

10 : Def


  def square(x):
    return x * x

numbers = [1, 2, 3, 4]
squares = map(square, numbers)
print(list(squares))
 
    
[1, 4, 9, 16]
[1, 3, 6, 10]
[0, 1, 4, 9]
[2, 4, 6, 8]


You May Be Write Your Score and Suggestions in our Comment Section, Notes Are upload soon. Stayonnected with It,s Quize.


Newer Oldest

Related Posts

1 comment

Post a Comment

Subscribe Our Newsletter