Numbers In Python
In Python, there are several types of numbers that can be used. The most commonly used types are integers and floating-point numbers.
Integers:
Integers are whole numbers, such as 42, and -1. With integers, you can perform mathematical operations such as addition, subtraction, multiplication, and division.
# Addition
x= 10 # integar
print(x + x) # prints 10Floating-point numbers:
Floating-point numbers, also known as “floats,” are numbers with decimal points, such as 3.14 or -0.01. They are represented in a computer using a fixed number of bits, which limits the precision of their decimal representation. You can also perform mathematical operations with floating-point numbers, such as 3.14 * 2.5.
x= 3.14 # float
y= 2.5 #float
print(x + y) Complex Numbers:
You can also use complex numbers like 1+2j
# Complex numbers
a= 1 + 2j
print(a) # prints (1+2j)In addition to these basic types, Python also includes support for arbitrary precision integers using the decimal module and for rational numbers using the fractions module.
You can convert between different types of numbers using the built-in functions int(), float(), and complex().
Here are some examples of working with numbers in Python:
# Addition
print(2 + 3) # prints 5# Subtraction print(5 - 2) # prints 3
# Multiplication print(3 * 4) # prints 12
# Division print(8 / 3) # prints 2.6666...
# Exponentiation print(2 ** 3) # prints 8
# Complex numbers print(1 + 2j) # prints (1+2j)
Python also you have a module called math for more math-related operations.
If you Want to Learn Python, You can watch my ultimate Python Course on My Youtube Channel.
You can join there as well to share your Queries and suggestions. Facebook Facebook Group: https://web.facebook.com/groups/890525732087988/?mibextid=HsNCOg
Thanks For Reading.
You can Also Follow Me on My Social Media Platforms: