Numeric data types are used to store numbers.
Python supports three types of numeric types:
- Integer (int)
- Floating Point (float)
- Complex Number (complex)
1.) Integer (int):
An integer is a whole number that does not have a fractional or decimal part. It can be positive, negative, or zero. In Python, integers are created by assigning a whole number value to a variable.
Example:
a = 10
print(type(a)) # Output: <class 'int'>2.) Floating Point (float):
A float represents a real number that contains a decimal point. It is used to represent numbers that require precision, such as scientific measurements or calculations involving fractions.
Example:
b = 3.14
print(type(b)) # Output: <class 'float'>3.) Complex Number (complex):
A complex number is a number that has a real part and an imaginary part. In Python, complex numbers are written in the form a + bj, where a is the real part and b is the imaginary part.
Example:
c = 3 + 4j
print(type(c)) # Output: <class 'complex'>Boolean in Python:
In Python, the Boolean data type represents one of two possible values: True or False. It is used to perform logical operations, make decisions in control structures (like if statements), and evaluate conditions.
Booleans are a subclass of integers, with:
- True having an integer value of 1
- False having an integer value of 0
Examples:
x = 5 > 3
print(x) # Output: Trueage = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
#output: You are an adult.is_valid = True
print(is_valid) # Output: True