Addition
What Is Addition in Python?
- In Python, the addition operator
+is used to add two numbers together.
How to Use It:
The basic way to add two numbers is:
pythonresult = number1 + number2number1andnumber2are the numbers you want to add.resultwill store the sum.
Examples and Exercises:
Adding Two Integer Numbers:
pythona = 10 b = 12 c = a + b print(c)- Output:
22
- Output:
Adding Multiple Numbers:
- You can add more than two numbers in one line.
pythona = 10 b = 12 c = 5 d = 63 result = a + b + c + d print(result)- Output:
90
Adding Floating Point Numbers:
- You can also add numbers with decimals.
pythona = 10.5 b = 12.9 result = a + b print(result)- Output:
23.4
Summary:
- The addition operator
+in Python is used to sum up numbers. It can be used with integers, floating point numbers, and even complex numbers. Try out the examples to get a feel for how it works!