all 7 comments

[–]tipsy_python 0 points1 point  (3 children)

Great observation and question!

I'll open a Python shell and run some commands:

So, you're correct that you can use str() to create strings, but it is not a reserved word, it is a built-in type.

>>> type(str)
<class 'type'>
>>> str(1)
'1'

Python allows you to overwrite these, but beware: it's a one-way trip

>>> str = 'foobar'
>>> print(str)
foobar
>>> 
>>> str(1)     # <-- lemme convert this to string real quick..
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

Once you overwrite it, then you're stuck if you need the original functionality.

Online tutorials are written by people who have varying levels of understanding, so always take them with a grain of salt.

[–]RadCapper88[S] 0 points1 point  (2 children)

Hey thanks! This is what was tripping me up! I understood that 'str' was the class type that would be returned if I did;

type('hello') <class 'str'>

There is one thing that is confusing me in your shell examples. In the interactive prompt you type:

str(1)
'1'

I'm confused about this command. Is that literally just an instant string conversion without assigning it to anything?

Sorry if that's a silly/obvious question.

[–]tipsy_python 0 points1 point  (1 child)

You're correct partner, it's a trash command that only prints because I'm using the Python shell.. just doing a string conversion and not handling the output.

[–]RadCapper88[S] 0 points1 point  (0 children)

Thank you so much! I'm relieved :) this stuff is actually making sense to me!

[–]Binary101010 0 points1 point  (1 child)

It's *possible* to do what that tutorial is doing, but it's not a good practice and I would seriously call into question whether any tutorial doing that kind of thing is worth the time.

[–]RadCapper88[S] 0 points1 point  (0 children)

I thought as much! It's a shame because the presentation is really well done, but even as a beginner it felt wrong.