Python Programming - Variables - Discussion

Discussion Forum : Variables - General Questions (Q.No. 26)
26.
Which of the following is a valid way to convert a string '10' to an integer?
int('10')
'10'.toint()
integer('10', base=10)
All of the above
Answer: Option
Explanation:

int('10') is the correct way to convert a string to an integer in Python.

'10'.toint() is not a valid method for converting a string to an integer; instead, it will raise an AttributeError.

integer('10', base=10) is also not a valid way to convert a string to an integer, it will raise a NameError: name 'integer' is not defined.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.