简体   繁体   English

您如何在Python中创建“回到这一点”代码?

[英]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. 我是使用python进行编码的新手,不知道使用什么标头可以在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 . 您知道,就像在菜单中一样,您打开了一个标签页并且不想在该标签页中,因此按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. 当您学习Python本地语言时,您会发现无需使用goto type命令就可以完成所需的一切。 Depending on what you're trying to do, you might want to use a looping construct like for or while . 根据您要执行的操作,您可能需要使用诸如forwhile的循环构造。 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. Python是学习编程的绝佳方法,我在学习时发现如何像计算机科学家一样思考是一项重要资产。

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. 用Python和其他编程语言编写的编程结构确实无法通过这种方式工作。 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. 要以更有用的方式回答问题,需要一个更具体的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM