开发者

How do you create a "go back to this point" code in Python?

I'm new to coding with python and did not know what header to search up my problem in python. My question is: How do you create a go back to this point command? You know, like in menus where you open a tab and don't want to be there, so you press Back.

Also, whenever I search it up I always find questions or explanations about exceptions. What do they do and do they have anything to do with my first开发者_运维问答 question?


"Flow control" might be a good thing to search on. As you learn the Python vernacular you'll see that you can do everything you need to without the goto type command you're reaching for. Depending on what you're trying to do, you might want to use a looping construct like for or while. Or you might write a reusable function or class that you can use in different contexts.

As for exceptions, that's a fancy word for certain types of errors. Learn to read them carefully, because they'll tell you exactly what you're doing wrong.

Have fun! Python is a great way to learn to program, I found How to Think Like a Computer Scientist a great asset when I was learning.


How do you create a go back to this point command?

You don't. Programming structure - in Python and in other programming languages - really doesn't work this way. You need to think about the problem differently.

You can create loops (that can be nested, and that can be broken out of), and you can remember some kind of "program state" that represents "where you are". In programming, you have to be able to distinguish many kinds of context: the current line of execution, as well as how you got there (because "returning" from a function will return the value into the context where it was called).

To answer the question in a more useful way requires a much more concrete example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜