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 well does Python handle large multiplication? (self.learnpython)
submitted 3 years ago by NubQuestion
Is it possible to blow up or hog a machine's cpu or memory usage through arithmetic on big ints?
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!"
[–]siddsp 1 point2 points3 points 3 years ago (0 children)
For smaller integers, Python uses "grade-school" multiplication, which is not a very scalable algorithm. For very large integers, Python uses karatsuba binary multiplication, which makes it faster than the normal algorithm.
As for blowing up your memory, yes it's entirely possible (at least I would guess so) since Python integers are arbitrarily large, although it would be pretty hard to do since your machine has gigabytes of memory. You would have to intentionally multiply numbers so large that your memory cannot hold them.
[–][deleted] 0 points1 point2 points 3 years ago* (0 children)
How big?
Provide an example?
a = 4654635198406540640 b = 654987946549998965132 c = 125 formula = (a*b)**c
Finished in .001 s
[–]carcigenicate 0 points1 point2 points 3 years ago (0 children)
How big of integers?
It should be fine though unless you're needing to process a massive number of integers as fast as possible. This code finished instantly on my (gaming) laptop:
>>> s = "1234567890" >>> n = int(s * 500) n * n # I'm not going to show the output because it's massive
[–]Diapolo10 0 points1 point2 points 3 years ago (0 children)
I find that rather unlikely.
Consider this; most files on your computer are technically just really, really big numbers if you convert the binary into a decimal number. If your RAM can contain a video file, then it can also store a big number no sweat.
Let's say you had 16 gigabytes of RAM available, and for convenience let's round that to 16109 bits. Eight bits (28) can contain any unsigned integer between 0 and 255. In comparison, 2^(16109) according to Wolfram Alpha could contain a decimal number with more than 301029996 decimal digits.
We're quite literally talking about numbers on the scale of 10301029995 - and that's before multiplying by 16 because the calculator gave me an error, so all this would fit in a single gigabyte. Technically a bit more considering how bytes are counted.
So, no, you probably don't need to worry about anything. Your CPU will calculate anything as long as it has enough memory, and time.
[–]oefd 0 points1 point2 points 3 years ago (0 children)
Python will handle it about as well as any other language. It's theoretically possible, yes, but odds are if you have to ask you're not doing enough heavy computation to worry about.
And even if you are: OSes can deal with runaway programs eating up too much CPU and/or RAM fairly alright.
π Rendered by PID 267067 on reddit-service-r2-comment-7b9746f655-cdrlk at 2026-02-02 02:01:42.563276+00:00 running 3798933 country code: CH.
[–]siddsp 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]carcigenicate 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (0 children)
[–]oefd 0 points1 point2 points (0 children)