0
Hello, please what is the use of "int" in the py programs?
2 Réponses
+ 1
int is a function which is use to convert string number to integer
For example:
a = "5" it is a string
b = int(a) is is a number
When you take user input then it is bydefault string so you need to cast input with int function to get in number:
a = input()
print (type(a)) # string
b = int(a)
print (type(b)) #integer
+ 1
int is a class, which can be called like a function to easily convert numeric strings to integers:
int("890") -> 890
int("-7") -> -7
int("4") -> 4
You can also use int to remove decimal parts from floats:
int(5.8) -> 5
int(2.99999) -> 2
int(-3.5) -> -3