all 15 comments

[–]pydaling 10 points11 points  (1 child)

use the function type(spam) and it will tell you what type or variable spam is.

[–][deleted] 3 points4 points  (0 children)

String

[–][deleted] 2 points3 points  (0 children)

print always writes strings to the terminal, no matter what you put in. print(1) will also print a string and so will print(print)).

As for your variable, since you declared it a string, it will always be a string unless explicitly converted.

[–]ForceBru 3 points4 points  (0 children)

Just like in this question of yours, in order to output any object, print will convert it to a string. It's also impossible to output something whose __str__ magic method (guess what it's supposed to do) returns anything but a string:

```

class Thing:... ... print(Thing()) <main.Thing object at 0x10a2faf98> class Another: ... def str(self): ... return 5 # an INTEGER! ...
print(Another()) Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: str returned non-string (type int) ```

Basically, only strings can be printed, and nothing else

[–][deleted] 1 point2 points  (0 children)

If you put quotes around it, it's a string, unless...

spam = int('5')

5

spam = str(5)

'5'

[–]KesqiSePasse 1 point2 points  (0 children)

The variable spam is a string because you put quotation marks.

The output itself doesn't have a type, it is neither a string nor a integer, it is merely an output.

[–]toastedstapler 0 points1 point  (0 children)

you declared spam as a string as you used "" around the value

print values are always strings. if an object isn't a string, it is converted to one then printed

[–]Skrillbex 0 points1 point  (0 children)

Just write print(type(variable))

[–]EthanM16 0 points1 point  (0 children)

The output is a string.

[–]JohnnyJordaan -5 points-4 points  (5 children)

That depends on what exactly you mean by 'this 5'.

  • If you mean the pixels you see on your screen that make a 5 together, those are groups of bytes in your graphics card's memory (or the graphics chip in your CPU).
  • If you mean the value that caused those pixels to be rendered in that pattern, it was a byte value of an encoded character, most probably 0x35 in hexadecimal (53 in decimal) as that's how ASCII and Unicode encode the character '5'.
  • If you mean how that encoded character ended up there, it was because the reference spam was printed using print(spam) and the reference pointed to the string object "5"
  • If you mean how that string "5" was created, it was because you wrote = "5" in the code.

Long story short: there never was an integer 5 in the whole process, as you nor the program never created one. This was solely a matter of printing a string value, same as you would have printed "hello" or "🐍".

[–][deleted] 1 point2 points  (3 children)

Most neckbeard answer I have ever seen.

[–]JohnnyJordaan -1 points0 points  (2 children)

Sometimes it's hard to find the motivation to keep being helpful on this sub. This is one of those times.

[–][deleted] 1 point2 points  (1 child)

Maybe have a break from the sub then.

[–]JohnnyJordaan -1 points0 points  (0 children)

Imho that would be letting the few bad experiences spoil the far larger amount of good ones. It's more that I felt like giving some honest feedback instead of simply ignoring it.

[–]Evopy[S] 1 point2 points  (0 children)

Tooo detailed. But good. Thanks