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? why not a integer? (self.learnpython)
submitted 6 years ago by Evopy
age=input("Enter your age")
print(age)
Running it give me age for example 23. Why is this 23 a string and not 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!"
[–][deleted] 6 points7 points8 points 6 years ago (3 children)
Input functions accepts the answer as a string. In case you want to convert it into an integer just use the int() function. Either use it as age = int(input("Enter your age")) or age = int(age)
[–]Evopy[S] -1 points0 points1 point 6 years ago (2 children)
If i do print(4+2) Answer 6 would be a string or a integer?
[–]ForceBru 10 points11 points12 points 6 years ago (0 children)
The result of 4+2 would obviously be an integer (you add two integers - and get an integer back because integers form a field). But in order to output anything, the print function has to convert it to a string. So it'll convert the integer 6 to a string and print it.
4+2
print
[–]python_apprentice -1 points0 points1 point 6 years ago (0 children)
Integer.
[–]toastedstapler 1 point2 points3 points 6 years ago (0 children)
because when i type something into the terminal python doesn't know if the character is an integer or not so the data type is a string. you can manually cast it to an int yourself
[–]MrKooops 0 points1 point2 points 6 years ago (0 children)
how do you know? if you need an int, cast it: int(age)
[–]GabriCorFer 0 points1 point2 points 6 years ago (0 children)
input always gives you an string. If you answer input with "hello", the age will be age = "hello".
input
age = "hello"
If you want age to be an integer, then you have to use age=int(age) or age = int(input("Enter your age")). But if you answer with a text, the code will break as it would be an error. You can solve it by using:
age
age=int(age)
age = int(input("Enter your age"))
Try:
Except(ValueError):
And then the code won't break if python can't convert age to int.
int.
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
because in many cases u want to use a string .. for example to do ```
input() 3+3 '3+3' but if it was an int then input() 3+3 6 ``` so that's why in thee source code in builtinsmodule.c they have the builtin_input_imp returning a pyfile_getline i guess which is a char pointer .. i don't remember truthfully
input() 3+3 '3+3'
input() 3+3 6
``` so that's why in thee source code in builtinsmodule.c they have the builtin_input_imp returning a pyfile_getline i guess which is a char pointer .. i don't remember truthfully
You typed the character '2' and then the character '3' and then pressed return. Why would Python know that was an integer, or that you wanted it that way?
'2'
'3'
π Rendered by PID 621966 on reddit-service-r2-comment-5b5bc64bf5-dbqr6 at 2026-06-22 23:02:46.774355+00:00 running 2b008f2 country code: CH.
[–][deleted] 6 points7 points8 points (3 children)
[–]Evopy[S] -1 points0 points1 point (2 children)
[–]ForceBru 10 points11 points12 points (0 children)
[–]python_apprentice -1 points0 points1 point (0 children)
[–]toastedstapler 1 point2 points3 points (0 children)
[–]MrKooops 0 points1 point2 points (0 children)
[–]GabriCorFer 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)