products:ict:python:numeric_data_types_int_float_complex

Numeric data types include `int`, `float`, and `complex`.

1. int: Integers are whole numbers, positive or negative, without any decimal point. For example, `5`, `-3`, `1000`, etc. Integers have unlimited precision in Python 3.

x = 5

y = -10

2. float: Floats represent real numbers and are written with a decimal point dividing the integer and fractional parts. For example, `3.14`, `2.71828`, `-0.5`, etc.

pi = 3.14

euler = 2.71828

3. complex: Complex numbers are specified as `<real_part>+<imaginary_part>j`, where `j` represents the square root of -1 (also known as the imaginary unit). For example, `3 + 4j`, `-2.5 - 1j`, etc.

z = 3 + 4j

w = -2.5 - 1j

Python provides built-in functions to convert between these numeric types:

- `int()`: Converts a number or string to an integer. - `float()`: Converts a number or string to a floating-point number. - `complex()`: Converts a number or string to a complex number.

x = int(5.7) # x would be 5

y = float(“3.14”) # y would be 3.14

z = complex(2, -3) # z would be 2 - 3j

These data types can be used in arithmetic operations and mathematical functions according to their respective properties.

products/ict/python/numeric_data_types_int_float_complex.txt · Last modified: 2024/03/01 18:52 by wikiadmin