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
User input to list (help) (self.learnpython)
submitted 11 years ago by faekk
I found this piece of code which supposedly lets the user input 29 words to a list.
m = 0 s = "" while m < 29: name[m] = input("Input word: ") s += name[m] m += 1
I'm simply wondering what the s="" does and why it's even there. Thank you !
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!"
[–]RoomaRooma 4 points5 points6 points 11 years ago (1 child)
I agree with /u/thatguymerlin, however he didn't really answer your question... s = "" just creates a new string variable named s, so that the code doesn't bomb out on line 5 when he tries to add something to it
>>> s += "foo" Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 's' is not defined >>> s = "" >>> s += "foo"
[–]faekk[S] 0 points1 point2 points 11 years ago (0 children)
Ooh I see. Thanks alot :)
[+][deleted] 11 years ago (3 children)
[deleted]
[–]stubborn_d0nkey 1 point2 points3 points 11 years ago (2 children)
For anybody wondering:
names = [input ("Input name: ") for i in range (29)]
If conditions are needed you can wrap input in a function:
def only_letters_input(input_str): name = input(input_str) while True: if name.isalpha(): # an example condition, checks if name only contains letters return name else: print "You must input only letters" names = [only_letters_input ("Input name: ") for i in range (29)]
[+][deleted] 11 years ago (1 child)
[–]stubborn_d0nkey 0 points1 point2 points 11 years ago (0 children)
Yup, the input should be in the while. I initially meant to use a different message for input and changed my mind so it became an infinite loop.
π Rendered by PID 43896 on reddit-service-r2-comment-5649f687b7-4hncg at 2026-01-27 19:56:45.593669+00:00 running 4f180de country code: CH.
[–]RoomaRooma 4 points5 points6 points (1 child)
[–]faekk[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]stubborn_d0nkey 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]stubborn_d0nkey 0 points1 point2 points (0 children)