Exercises on Python Variables

The following exercises cover scenarios on variables in Python.

Exercise 1

Create a variable named x, and assign it a value of 20.


Exercise 2

We have a variable named x. Assign it a string value of "Hello World".

x = ""

Exercise 3

Create two variables named x and y, and assign them with values 10 and 20 respectively.

,  = , 

Exercise 4

We have a variable named x which is assigned a value of 'apple'. Print the variable x to standard output.

x = 'apple'

Exercise 5

Assign variable x with 10, and variable y with 20. Find their sum and assign the result to a variable z. Then print the variable z.

x = 
y = 
 = x + y

Exercise 6

Fill in the fields with correct syntax to initialize all the three variables x, y, and z with the same value of 'apple' in a single statement.

 =  =  = 'apple'
Code copied to clipboard successfully 👍