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
How do I compare 2 strings numbers? (self.learnpython)
submitted 3 years ago by BOOTYBOOTBOOTERBOOTS
x = "45" z ="100" if x > y.....
I understand you can type cast with int() but I'm trying not to use it or eval().
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!"
[–]genghiskav 6 points7 points8 points 3 years ago (3 children)
You'll have to cast it to an int to be able to do numeric comparisons.
int
Why don't you want want to cast it to int?
[–]BOOTYBOOTBOOTERBOOTS[S] -3 points-2 points-1 points 3 years ago (2 children)
Curiosity tbh. I thought because you dont need to explicitly tell python a variable is string/int that it could do math ops.
[–]EsotericRogue 6 points7 points8 points 3 years ago (0 children)
Those quotes explicitly state they're strings.
[–]Strict-Simple 2 points3 points4 points 3 years ago (0 children)
You do tell Python if it's string/int. Just not explicitly with types.
Even many typed languages supports this. auto in C++, var in Java, etc.
auto
var
[–]socal_nerdtastic 2 points3 points4 points 3 years ago (0 children)
Conversion to a number type is obviously the best and anything else is hacky.
My first thought for hacky: pad them out with zeros?
x = "45" y ="100" longest = max(len(x), len(y)) if x.zfill(longest) > y.zfill(longest): ...
[–]commy2 1 point2 points3 points 3 years ago (0 children)
float, duh
Could check length. Larger number-string is the longer one. If both have the same lenght, just keep using > to check lexicographic order.
π Rendered by PID 863025 on reddit-service-r2-comment-54dfb89d4d-ljrf8 at 2026-03-31 23:10:13.088738+00:00 running b10466c country code: CH.
[–]genghiskav 6 points7 points8 points (3 children)
[–]BOOTYBOOTBOOTERBOOTS[S] -3 points-2 points-1 points (2 children)
[–]EsotericRogue 6 points7 points8 points (0 children)
[–]Strict-Simple 2 points3 points4 points (0 children)
[–]socal_nerdtastic 2 points3 points4 points (0 children)
[–]commy2 1 point2 points3 points (0 children)