Python Forum
Converting str to int or float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting str to int or float
#2
The int built-in will convert a string representing an integer into an actual integer.

>>> x = '5'
>>> x
'5'
>>> int(x)
5
>>> int(x) + 3
8
Note that it will raise an error if the string cannot be converted to an int. I don't know if your teacher expects you to be able to handle that.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Converting str to int or float - by juliabrushett - Jun-16-2018, 06:53 PM
RE: Converting str to int or float - by ichabod801 - Jun-16-2018, 07:06 PM
RE: Converting str to int or float - by ljmetzger - Jun-17-2018, 09:57 AM
RE: Converting str to int or float - by volcano63 - Jun-17-2018, 03:05 PM
RE: Converting str to int or float - by DeaD_EyE - Jun-17-2018, 06:28 PM
RE: Converting str to int or float - by volcano63 - Jun-17-2018, 08:08 PM
RE: Converting str to int or float - by DeaD_EyE - Jun-18-2018, 10:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020