Syntax and Basics

Understanding Python syntax, indentation, and basic operations.

What is the correct way to print "Hello, World!" in Python?

print("Hello, World!")

2

How do you write a single-line comment in Python?

# This is a single-line comment

3

How do you write a multi-line comment in Python?

"""
This is a
multi-line comment
"""

4

How do you assign a value to a variable in Python? Provide an example.

x = 10
y = "Hello"

5

What is the output of the following code snippet?


6

How do you take user input in Python and store it in a variable?


7

What is the output of the following code snippet?


8

How do you check the data type of a variable in Python? Provide an example.


9

What is the difference between = and == in Python?


10

What will be the output of the following code snippet?


11

How do you write an if-else statement in Python? Provide an example.


12

What will be the output of the following code snippet?


13

How do you write a for loop in Python to iterate over a list of numbers?


14

What will be the output of the following code snippet?


15

How do you write a while loop in Python? Provide an example.


16

What is the purpose of the break statement in a loop? Provide an example.


17

What is the purpose of the continue statement in a loop? Provide an example.


18

How do you define a function in Python? Provide an example.


19

What is the output of the following code snippet?


20

How do you call a function in Python and pass arguments to it? Provide an example.


21

How do you convert a string to an integer in Python? Provide an example.


22

How do you convert an integer to a string in Python? Provide an example.


23

How do you find the length of a string in Python? Provide an example.


24

What will be the output of the following code snippet?


25

How do you concatenate two strings in Python? Provide an example.


26

How do you use string formatting in Python? Provide an example.


27

What will be the output of the following code snippet?


28

How do you append an element to a list in Python? Provide an example.


29

What will be the output of the following code snippet?


30

How do you create a dictionary in Python? Provide an example.


31

How do you access a value in a dictionary using a key? Provide an example.


32

How do you add a key-value pair to a dictionary? Provide an example.


33

How do you remove a key-value pair from a dictionary? Provide an example.


34

What will be the output of the following code snippet?


35

How do you create a tuple in Python? Provide an example.


36

What will be the output of the following code snippet?


37

How do you define a function with default arguments in Python? Provide an example.


38

What will be the output of the following code snippet?


39

How do you return multiple values from a function in Python? Provide an example.


40

What is the purpose of the pass statement in Python? Provide an example.


41

How do you create a class in Python? Provide an example.


42

What will be the output of the following code snippet?


43

How do you inherit a class in Python? Provide an example.


44

What is a lambda function in Python? Provide an example.


45

How do you handle exceptions in Python? Provide an example.


Last updated