Google News
logo
Python Program to Add a Variable to another Variable
In the following example of Python program that demonstrates how to add a variable to another variable :
Program :
# Creating two variables
num1 = 10
num2 = 20

# Adding the variables together
result = num1 + num2

# Outputting the result
print(result)
Output :
30
In the above program, we create two variables named num1 and num2 and assign them the values 10 and 20, respectively. We then use the + operator to add the values of the two variables together and assign the result to a new variable named result.

Finally, we use the print function to output the value of result to the console. When we run the program, it will output the value 30, which is the result of adding num1 and num2 together.

You can use the same technique to add other types of variables together in Python, including strings, lists, and more. Just remember that the + operator behaves differently depending on the types of the variables being added.

For example, adding two strings together with the + operator will concatenate them, while adding two lists together will combine them into a new list.