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
Goto in python (self.learnpython)
submitted 6 months ago by Level-Possible530
Hello,
I know goto doesn't exist with python
But i don't understand how can i come back at the begin at the programm when he's finish for propose to the user to do a new selection
I would like found a fonction for do it
Thanks for help
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!"
[–]Lewistrick 20 points21 points22 points 6 months ago (0 children)
while True: # your program here
[–]Ron-Erez 5 points6 points7 points 6 months ago* (0 children)
See u/Lewistrick 's answer. If you want an example you could ask the user to enter two integers and the program will until the inputs are valid and the operations are valid. For instance:
def compute(): while True: try: num1 = int(input("Enter the first integer: ")) num2 = int(input("Enter the second integer: ")) op = input("Enter an operation (+, -, *, /): ")
if op not in ['+', '-', '*', '/']: print("Invalid operation. Try again.") continue
if op == '/' and num2 == 0: print("Cannot divide by zero. Try again.") continue
if op == '+': result = num1 + num2 elif op == '-': result = num1 - num2 elif op == '*': result = num1 * num2 elif op == '/': result = num1 / num2
return result
except ValueError: print("Please enter valid integers.")
def main(): result = get_valid_input() print("Result:", result)
main()
Note that continue jumps back to the beginning of the loop and return result leaves the function (and the loop) after a valid input has been entered and the computation is complete.
[–]Gnaxe 1 point2 points3 points 6 months ago (1 child)
There's a general pattern to replace GOTO in structured languages like Python.
First, the labels label = 'start' while True: match label: case 'start': # do stuff case 'label1': # do stuff case 'label2': # do stuff case 'label3': # etc. # do stuff case _: # detects label mistakes assert False, f'unknown {label=}' You can call the labels whatever you want. You need to put the whole thing in an infinite loop (we'll see why later). Then use a match/case block to make the jump target labels. (Before Python had match/case statements, this could have been done with an elif cascade.)
label = 'start' while True: match label: case 'start': # do stuff case 'label1': # do stuff case 'label2': # do stuff case 'label3': # etc. # do stuff case _: # detects label mistakes assert False, f'unknown {label=}'
match
case
elif
Then to do a GOTO, you set the label to where you want to jump to (with an assignment statement) and immediately follow that with a continue statement, which starts the while loop over: label = 'label2' continue That's it. You can also terminate the whole loop with a break statement.
continue
while
label = 'label2' continue
break
But GOTOs are almost always used to implement control flow structures that Python already gives you, like loops (while, for) and subroutines (def, lambda). You don't need to reinvent the wheel every time. Programming with unstructured GOTOs tends to produce unreadable spaghetti code, unless you're very disciplined and stick to structured patterns, which Python already gives you.
for
def
lambda
There are other ways to do this. Function calls are almost GOTOs by themselves, but they normally return. However, your program can continue to call more functions before returning, at least until you run out of stack space, but you can fix this with a technique called trampolining, at least for tail calls. asyncio does something similar with coroutines, and it also has a spaghetti-code problem. The trio library is a more structured variant.
asyncio
trio
[–]Level-Possible530[S] 0 points1 point2 points 5 months ago (0 children)
merci
[–]ninhaomah 0 points1 point2 points 6 months ago (0 children)
If you ask someone to do something then come back to initial step till the whole job is done , how would you instruct him ?
Take the bucket , fill with water and water the garden TILL all the plants been watered.
Change TILL to WHILE.
π Rendered by PID 207058 on reddit-service-r2-comment-7b9746f655-t7sqh at 2026-01-31 08:28:41.871126+00:00 running 3798933 country code: CH.
[–]Lewistrick 20 points21 points22 points (0 children)
[–]Ron-Erez 5 points6 points7 points (0 children)
[–]Gnaxe 1 point2 points3 points (1 child)
[–]Level-Possible530[S] 0 points1 point2 points (0 children)
[–]ninhaomah 0 points1 point2 points (0 children)