Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

python 4

The document provides an overview of number data types in Python, specifically int, float, and complex. It includes definitions and examples for each type, demonstrating how they are represented and their respective outputs when printed. The content is aimed at helping users understand the basic numerical data types in Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

python 4

The document provides an overview of number data types in Python, specifically int, float, and complex. It includes definitions and examples for each type, demonstrating how they are represented and their respective outputs when printed. The content is aimed at helping users understand the basic numerical data types in Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

</> CodeWithHarry Menu Login

This site uses Google AdSense ad intent links. AdSense automatically generates these links and they may help creators earn
money.

Python Numbers
In Python, numbers are of the following data types:
int
float
complex

int
int is a positive or a negative integer of any length. int should not be a decimal or a
fraction.
Example:

int1 = -2345698
int2 = 0
int3 = 100548

print(type(int1))
print(type(int2))
print(type(int3))

Output:

<class 'int'>
<class 'int'>
<class 'int'>

Float
A float is a positive or a negative decimal number. It can be an exponential number
or a fraction.
Example:
flt1 = -8.35245 #decimal number
flt2 = 0.000001 #decimal number
flt3 = 2.6E44 #exponential number
flt4 = -6.022e23 #exponential number

print(type(flt1))
print(type(flt2))
print(type(flt3))
print(type(flt4))

Output:

<class 'float'>
<class 'float'>
<class 'float'>
<class 'float'>

complex
Complex numbers are a combination of real and imaginary number. They are of the
form a + bj, where a is the real part and bj is the imaginary part.
Example:

cmplx1 = 2 + 4j
cmplx2 = -(3 + 7j)
cmplx3 = -4.1j
cmplx4 = 6j

print(type(cmplx1))
print(type(cmplx2))
print(type(cmplx3))
print(type(cmplx4))

Output:

<class 'complex'>
<class 'complex'>
<class 'complex'>
<class 'complex'>
< < Previous Next > >

CodeWithHarry Copyright © 2024 CodeWithHarry.com

You might also like