Numbers in Python #
Python provides several built-in numeric data types, including integers, floating-point numbers, and complex numbers.
Integers #
Integers are whole numbers that can be positive, negative, or zero. In Python, integers are represented by the int data type. You can use integers to represent counts, scores, and other discrete values in your programs. For example:
# Example of integers
x = 5
y = -3
z = 0
Floating-Point Numbers #
Floating-point numbers are numbers with a decimal point that can be positive, negative, or zero. In Python, floats are represented by the float data type. You can use floats to represent measurements, ratios, and other continuous values in your programs. For example:
# Example of floating-point numbers
x = 3.5
y = -2.25
z = 0.0
Complex Numbers #
Complex numbers have both a real and an imaginary part.
# Example of complex numbers
x = 2 + 3j
y = -1 - 4j
z = 0 + 2j
Exercise #
- Create a variable
xand assign an integer to it. - Create a variable
yand assign a float number to it.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules