In Python, there are several built-in data types for storing numbers:
Integer (
int
): Integers are whole numbers that can be positive, negative, or zero. They do not have a decimal point. For example, 10, -5, and 0 are all integers.Floating-point number (
float
): Floating-point numbers are numbers with a decimal point. They can also be positive, negative, or zero. For example, 3.14, -0.01, and 0.0 are all floating-point numbers.Complex number (
complex
): Complex numbers are numbers that have a real and an imaginary part. The real part is a floating-point number, and the imaginary part is denoted by the letter "j". For example, 3+4j is a complex number with a real part of 3 and an imaginary part of 4.
You can perform various arithmetic operations with numbers in Python, such as addition, subtraction, multiplication, and division. For example:
x = 10
y = 3
# Addition
print(x + y) # Output: 13
# Subtraction
print(x - y) # Output: 7
# Multiplication
print(x * y) # Output: 30
# Division (the result is always a float)
print(x / y) # Output: 3.3333333333333335
# Integer division (the result is always an integer)
print(x // y) # Output: 3
# Modulus (returns the remainder of the division)
print(x % y) # Output: 1
You can also use various built-in functions to perform operations on numbers in Python. Some common examples include:
abs()
: returns the absolute value of a numberround()
: rounds a number to a specified precisionmax()
: returns the
0 댓글