Numbers
1. IntegersIn Python, the definition of an integer is the same as what we learn in mathematics, which is a number without a decimal part, such as positive integers, zero, and negative integers.Python integers not only support basic arithmetic operations but also support exponentiation ( ** ), modulus (<span><span>%</span></span> ) and floor division (<span><span>//</span></span> ):
print(3+3) # Output is 6
print(3-2) # Output is 1
print(3*2) # Output is 6
print(3/2) # Output is 1.5
print(3**2) # Output is 9

Similarly, Python also supports the order of operations in mathematics.
print(2+3*5) # Output is 17
print((2+3)*5) # Output is 30
2. Floating-Point NumbersDefinition: In Python, numbers with a decimal point are collectively referred to as floating-point numbers. Likewise, floating-point numbers, like integers, also follow the rules of operations and order of operations.
3. Integers and Floating-Point NumbersIn Python, when dividing any two numbers, the result is always a floating-point number, even if both numbers are integers and can be divided evenly.
print(6/2) # Output is 3.0
However, the result of floor division is an integer.
In any operation in Python, as long as there is a floating-point number as a parameter, the default result of the calculation is always a floating-point number, even if it could be an integer.
print(1.0+2) # Output is 3.0
print(1.0*2) # Output is 2.0
print(2.0-1) # Output is 1.0
print(2.0**2) # Output is 4.0
Summary:
- Division between integers (
<span><span>/</span></span>) always returns a floating-point number (e.g.,<span><span>6/2=3.0</span></span>), while floor division (<span><span>//</span></span>) returns an integer (e.g.,<span><span>6//2=3</span></span>). - When performing mixed operations between floating-point numbers and integers, integers will be implicitly converted to floating-point numbers before calculation (e.g.,
<span><span>1.0 + 2</span></span>is equivalent to<span><span>1.0 + 2.0</span></span>).
4. Representation of NumbersIn Python, when the value to be represented is large, we can use underscores “_” to group it for better readability.
Money=868_686_868_68 # Define variable Money
print(Money) # Output Money value is 86868686868
In the above code, we can see that Python does not output the underscores in the result because Python automatically ignores underscores when storing numbers with underscores. At the same time, when grouping numbers, the position of the underscores does not affect the final value; in Python’s view,<span><span>1000</span></span> and <span><span>10_00</span></span> are the same,<span><span>1_000</span></span> and <span><span>10_00</span></span> are also the same. This rule applies to both integers and floating-point numbers. It is important to note that underscores cannot be at the beginning or end of a number (e.g.,<span><span>_100</span></span> or<span><span>100_</span></span> will both result in an error).