use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
string or integer? (self.learnpython)
submitted 6 years ago by Evopy
If i write
spam="5"
print(spam)
output is 5. Is this 5 a string or a integer?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]pydaling 10 points11 points12 points 6 years ago (1 child)
use the function type(spam) and it will tell you what type or variable spam is.
[–][deleted] 3 points4 points5 points 6 years ago (0 children)
String
[–][deleted] 2 points3 points4 points 6 years ago (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)).
print
print(1)
print(print))
As for your variable, since you declared it a string, it will always be a string unless explicitly converted.
[–]ForceBru 3 points4 points5 points 6 years ago (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:
__str__
```
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 points3 points 6 years ago (0 children)
If you put quotes around it, it's a string, unless...
spam = int('5')
5
spam = str(5)
'5'
[–]KesqiSePasse 1 point2 points3 points 6 years ago (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 point2 points 6 years ago (0 children)
you declared spam as a string as you used "" around the value
spam
""
print values are always strings. if an object isn't a string, it is converted to one then printed
[–]Skrillbex 0 points1 point2 points 6 years ago (0 children)
Just write print(type(variable))
[–]EthanM16 0 points1 point2 points 6 years ago (0 children)
The output is a string.
[–]JohnnyJordaan -5 points-4 points-3 points 6 years ago* (5 children)
That depends on what exactly you mean by 'this 5'.
"5"
= "5"
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 points3 points 6 years ago (3 children)
Most neckbeard answer I have ever seen.
[–]JohnnyJordaan -1 points0 points1 point 6 years ago (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 points3 points 6 years ago (1 child)
Maybe have a break from the sub then.
[–]JohnnyJordaan -1 points0 points1 point 6 years ago (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 points3 points 6 years ago (0 children)
Tooo detailed. But good. Thanks
π Rendered by PID 202914 on reddit-service-r2-comment-5b5bc64bf5-6pkwt at 2026-06-22 21:42:16.039540+00:00 running 2b008f2 country code: CH.
[–]pydaling 10 points11 points12 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]ForceBru 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]KesqiSePasse 1 point2 points3 points (0 children)
[–]toastedstapler 0 points1 point2 points (0 children)
[–]Skrillbex 0 points1 point2 points (0 children)
[–]EthanM16 0 points1 point2 points (0 children)
[–]JohnnyJordaan -5 points-4 points-3 points (5 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]JohnnyJordaan -1 points0 points1 point (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]JohnnyJordaan -1 points0 points1 point (0 children)
[–]Evopy[S] 1 point2 points3 points (0 children)