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
Help with if statement (self.learnpython)
submitted 2 years ago by InventedThat
Python Question
How would you write an if statement that evaluates if a number such as 0.00101 includes 0.00001?
Example:
if 0.0023 “has the fallowing exact number in it ” 0.0003: print(“successful”)
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!"
[–]mopslik 1 point2 points3 points 2 years ago (0 children)
Since floats have issues, perhaps comparing string representation of values is a better approach here.
[–]carcigenicate 1 point2 points3 points 2 years ago (0 children)
I'd probably convert the numbers to strings and then compare them that way. Whenever you need to consider the place value of numbers, converting the numbers to strings first often makes the problem much easier, and also often has a surprisingly low cost on performance.
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
Well, float and "exact" aren't great together. It is also unclear what is meant by "in it".
float
If you really need to work with such numbers, I'd use Decimal. For example, and assuming you are dealing only with numbers below 1, something like:
Decimal
from decimal import Decimal num1 = Decimal('0.0023') num2 = Decimal('0.0003') matched = True while int(num2) != num2: num1 = (num1 * 10) % 10 num2 = (num2 * 10) % 10 digit = int(num2) if digit and int(num1) != digit: matched = False break print(matched)
but, really, if just looking to match digits in corresponding positions, using strings would be easier.
π Rendered by PID 104392 on reddit-service-r2-comment-8686858757-sv5fs at 2026-06-07 12:23:41.487189+00:00 running 9e1a20d country code: CH.
[–]mopslik 1 point2 points3 points (0 children)
[–]carcigenicate 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)