‘int(string)’ function takes a string as argument and convert it to an integer.
>>> data = "2345"
>>>
>>> data
'2345'
>>>
>>> int(data)
2345
You will get an error while converting non-numerical data.
>>> data = "hh"
>>>
>>> int(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'hh'
No comments:
Post a Comment