Practicing Basic Calculations and Expressions in the Python REPL

1. Open the Python REPL:

Open your command prompt (Windows) or terminal (macOS and Linux).
Type python or python3 (depending on your system configuration) and press Enter.
You will enter the Python interactive shell, indicated by the >>> prompt.

2. Perform Basic Arithmetic Operations:

You can use the Python REPL as a calculator to perform basic arithmetic operations such as addition, subtraction, multiplication, and division.

        >>> 2 + 3     # Addition
        5
        >>> 7 - 4     # Subtraction
        3
        >>> 5 * 6     # Multiplication
        30
        >>> 10 / 2    # Division
        5.0
    

3. Use Parentheses for Precedence:

You can use parentheses to control the order of operations in complex expressions.

        >>> (2 + 3) * 4   # (2 + 3) is evaluated first, then multiplied by 4
        20
        >>> 10 / (2 + 3)  # 2 + 3 is evaluated first, then 10 is divided by the result (5)
        2.0
    

4. Try Different Data Types:

Python supports different data types, such as integers, floating-point numbers, and strings.

        >>> 10 / 3      # Division results in a floating-point number
        3.3333333333333335
        >>> 2 ** 3      # Exponentiation: 2 raised to the power of 3
        8
        >>> "Hello" + " " + "World"   # Concatenation of strings
        'Hello World'
    

5. Explore More Mathematical Functions:

Python provides several built-in mathematical functions in the math module.

        >>> import math
        >>> math.sqrt(25)    # Square root of 25
        5.0
        >>> math.sin(math.pi / 2)   # Sine of pi/2 (90 degrees)
        1.0
    

6. Use Variables:

You can store values in variables and use them in calculations.

        >>> x = 5
        >>> y = 10
        >>> result = x + y
        >>> result
        15
    

7. Quit the Python REPL:

To exit the Python REPL, type exit() and press Enter.

        >>> exit()
    

Practicing basic calculations and expressions in the Python REPL will help you gain confidence in Python's syntax and arithmetic capabilities. It's a great way to explore the language and experiment with various calculations interactively.

Intro to the Python REPL & Python's Interactive Shell YouTube Video