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:

    python
    result = number1 + number2
    
    • number1 and number2 are the numbers you want to add.
    • result will store the sum.

Examples and Exercises:

  1. Adding Two Integer Numbers:

    python
    a = 10
    b = 12
    c = a + b
    print(c)  
    • Output: 22
  2. Adding Multiple Numbers:

    • You can add more than two numbers in one line.
    python
    a = 10
    b = 12
    c = 5
    d = 63
    result = a + b + c + d
    print(result)  
    • Output: 90
  3. Adding Floating Point Numbers:

    • You can also add numbers with decimals.
    python
    a = 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!