Welcome back, aspiring Pythonista! In our last step, we printed our very first message to the screen. Now, let's dive into the fascinating world of numbers in Python. Computers are excellent at crunching numbers, and Python provides us with two primary ways to represent them: integers and floating-point numbers.
Integers, often shortened to 'int', are whole numbers, both positive and negative, without any decimal point. Think of them as counting numbers. Examples include 0, 1, -5, 42, and -1000. Python can handle integers of virtually any size, limited only by your computer's memory!
my_age = 30
number_of_students = 150
negative_score = -10We can also perform standard arithmetic operations with integers:
sum_result = 5 + 3
difference = 10 - 4
product = 6 * 7
quotient = 20 / 4
exponent = 2 ** 3Note that division with integers in Python 3 (which is what we're using) will always result in a floating-point number, even if the result is a whole number. We'll explore this more in the next section.
Floating-point numbers, or 'float' for short, are numbers that have a decimal point. They are used to represent fractional values and can also be used for very large or very small numbers using scientific notation. Examples include 3.14, -0.5, 2.0, and 1.23e6 (which means 1.23 multiplied by 10 to the power of 6).
pi_value = 3.14159
gravity_constant = 6.674e-11
price = 19.99Arithmetic operations with floats work similarly to integers, but with potential nuances regarding precision. When you mix integers and floats in an operation, the result will typically be a float.