Python: Integers, Floating Point Numbers and Complex Number
integers:
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length .
Example
Integers:
x = 7
y = 7893245783756
z = -46582756
print(type(x))
print(type(y))
print(type(z))
Floating Point Numbers:
Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Example
Floats:
x = 1.15
y = 1.5
z = -35.58
print(type(x))
print(type(y))
print(type(z))
by using the command "print(type(x))" you can identify the class/ Type by a certain value which show to be a float (floating Point Numbers).floating point numbers can also be scientific numbers with a "e" within it to indicate the power of 10, for example:
Input:
x =
Complex:
Complex numbers are written with a "j" as the imaginary part:
Example:
Complex:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
Complex Numbers:
An complex number is represented by “ x + yi “. Python converts the real numbers x and y into complex using the function complex(x,y). The real part can be accessed using the function real() and imaginary part can be represented by imag(). for example:
Complex numbers are written with a "j" as the imaginary part:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
Type Conversion :
You can convert from one type to another with the int(), float(), and complex() methods:
Example
Convert from one type to another:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
Programming for computer Animation and VFX TB1
Status | In development |
Category | Other |
Author | up2146107 |
More posts
- Python: Printing and CommentingDec 15, 2022
- Python : Functions and Argument and ReturnDec 15, 2022
- Python: Type() and factorials and VariablesDec 15, 2022
Leave a comment
Log in with itch.io to leave a comment.