Data Science Explorer

[Basic Grammar] Python Numbers 본문

Python

[Basic Grammar] Python Numbers

grace21110 2023. 10. 20. 12:49
반응형

There are three numeric types in Python which are int(), float(), complex().

 

  • Int()

It is a whole number, positive or negative (without decimals).

 

Example

x = 2
y = -2
print (x) 
print (y)
  • Float()

It is a number, positive or negtiave, containing one or more decimals. 

 

Example

x = 1.89
print(type(x))

Example 

 = 35e3
 y = -67.7e100
print(type(x))
print(type(y))

 

  • Complex()

They are numbers that are written with a "j" as the imaginary part.

x = 9+5j
Y = -5j
print(type(x))
print(type(y))

 

Exercises 

Insert the correct Python syntax to convert the variable x into a floating-point number.

x = "3.14" 
x = float(x)