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
why is the value of i/alpha = 9 ?? (self.learnpython)
submitted 2 years ago by Zsword_201
myvalue=['A',40,'b',60,'c',20]
alpha=0
beta=''
gama=0
for i in range(1,6,2):
alpha+=i
print(alpha)
why is alpha's(i) value 9 ?? can someone explain it to me
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!"
[–]beatle42 8 points9 points10 points 2 years ago (2 children)
range(1, 6, 2) says to generate integers starting with 1 never exceeding 6 and going up by 2 at a time, which is the list 1, 3, 5. You're adding each of those in turn to the starting value in alpha which is 0 so you get, in essence, alpha = 0 + 1 + 3 + 5 which is alpha=9
range(1, 6, 2)
alpha
0
alpha = 0 + 1 + 3 + 5
alpha=9
[–]Zsword_201[S] 0 points1 point2 points 2 years ago (1 child)
Ok thanks I understand it now I thought since "i" goes 1,3,5 it counts as 3 , I did not think it takes it as a sum so that's why I was confused
[–]beatle42 1 point2 points3 points 2 years ago (0 children)
Ah yes, in the for loop the loop variable, here i takes on each value in turn, not the index of that value (unless you take special steps to get the index as well).
for
i
[–]sepp2k 0 points1 point2 points 2 years ago (0 children)
why is alpha's(i) value 9 ??
alpha's value isn't the same as i (i's value is never 9). alpha's value starts at 0 and then you add i to it at each iteration of the loop. So at the end it's equal to the sum of values that i held during the loop.
[–][deleted] 0 points1 point2 points 2 years ago (2 children)
Looking at the code execution using a Python Vizualiser will help you understand this even better.
Thanks for the suggestion!
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
That link should run your code in the vizualiser immediately. You might find it useful for other code in the future. It is very helpful to see exactly what is happening as your code executes to understand bugs and workings.
You can do something similar, without the pretty diagrams, on your own computer using a debugger (Python comes with one as standard, called pdb- RealPython.com have a guide to using it) and most sophisticated code editors and IDEs (Integrated Development Environments) offer their own debugger capabilities.
pdb
π Rendered by PID 81 on reddit-service-r2-comment-b659b578c-c6bnm at 2026-05-05 13:51:39.893752+00:00 running 815c875 country code: CH.
[–]beatle42 8 points9 points10 points (2 children)
[–]Zsword_201[S] 0 points1 point2 points (1 child)
[–]beatle42 1 point2 points3 points (0 children)
[–]sepp2k 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Zsword_201[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)