Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Things That Count Ints & Floats

jacob maggs
jacob maggs
1,703 Points

Complete the following to make my string into an integer:

im having trouble with this Complete the following to make my string into an integer: ____________ ('3')

2 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

This is a lot like doing this but backwards lol. What does that mean? Well, let me show you an interpreter example.

See how if I do str(3) it gives me back a string. In the event I don't know what I have for sure. I can save it to variable x then run type(x) which gives back class str. So I know I have a string.

>>> str(3)
'3'
>>> x = str(3)
>>> type(x)
<class 'str'>
>>>

Here is your example with the integer. All I do is use int(). To go between string to integer and use str to do integer to string.

>>> int('3')
3
>>> x = int('3')
>>> type(x)
<class 'int'>
>>>

Let me know if this answers all your questions!

Thanks!

jacob maggs
jacob maggs
1,703 Points

wow thanks that helps alot! nothing was said of this in any of the lessons like I was expected to know it, thank you!

Ryan Ruscett
Ryan Ruscett
23,309 Points

haha yeah sometimes in the python course. You will be asked to do things and be like what?? then the next video actually talks about it. I've noticed that here and there.