函数和关键字/语句有什么区别?
我已经看到“ del”被称为关键字和语句。显然,它不被视为函数:
python有一个del语句(关键字)删除对象,不是del函数。
https://tutorial.eyehunts.com/python/del-functions.com/python/del-functions -In-python-code/
我查找了Python中功能的定义,它说:
在Python中,一个函数是执行特定任务的一组相关语句。
在此定义下,我不明白如何将DEL视为函数。
它确实执行特定任务:在给定索引上删除项目。
语法似乎是不同的,因为您不需要括号来使用DEL语句:
motorcycles = ['honda', 'suzuki', 'yamaha']
del motorcycles[0]
但是DEL是语句/关键字而不是函数的其他实际后果是什么?
最后,主要问题是:如何将某些内容识别为陈述而不是功能,反之亦然?
考虑到我必须知道,要知道所需的语法,我认为对我来说很重要。
我做了一些研究,发现了一些解释,为什么功能与关键字不同:
函数比关键字互动较低 - 本身必须调用更高的指定系统操作呼叫或AKIN-从根本上与内存分配进行互动。
这样做的主要原因 - 是Python的层次结构本身的构建方式。
但对我来说 - Python的初学者,其第一种编程语言是R-似乎不能帮助我将某些内容识别为关键字而不是函数。
plus,如果语句与关键字不同,我认为DEL被称为语句和关键字的情况如何?
任何人都可以阐明这一点吗?我真的很感激!
I've seen 'del' being referred to as a keyword and as a statement. Apparently, it is not considered a function:
Python has a del statement (keyword) to delete objects, not a del function.
https://tutorial.eyehunts.com/python/del-function-in-python-code/
I looked up the definition of a function in Python and it says:
In Python, a function is a group of related statements that performs a specific task.
Under this definition, I do not understand how del cannot be considered a function.
It does perform a specific task: deleting an item at a given index.
The syntax appears to be different, as you don't need parentheses to use the del statement:
motorcycles = ['honda', 'suzuki', 'yamaha']
del motorcycles[0]
But what are the other practical consequences of del being a statement/keyword rather than a function?
Finally, the main question here is: how do I identify something as a statement rather than a function and vice versa?
Considering that I'll have to know that in order to know the syntax needed, I think it is quite important for me to understand that.
I did some research and I found a few explanations to why functions are different than keywords:
Function is a lower designation than a keyword interaction - and in of itself - has to call higher designated System operative calls or akin - to fundamentally interact with memory partitioning.
The main reason for this - is how Python’s hierarchy is constructed in of itself.
But to me - a beginner in Python whose first programming language is R - that does not seem to help me identify something as a keyword instead of a function.
Plus, if a statement is different than a keyword, how is it that I've seen del being referred to as both a statement AND a keyword?
(What is the difference between a statement and a keyword?)
Can anyone shed some light on this, please? I'd really appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python关键字本质上是
具有特定含义和目的的特殊保留单词,除了这些特定目的以外的任何其他方法。
它们都带有Python标准库,无论如何您都无法更改它们。您可以阅读有关关键字的更多信息在这里如果您运行help> help> help> help>“ keywords”)代码>在您的Python解释器中,将返回一堆关键字,而
del
是其中之一。Python语句是指python代码的任何行/行(包括
del Motorcycles [0]
和print(摩托车[0])
),它们没有必须满足要归类为语句的任何特定条件。Python函数是指可重复使用的代码块,该代码每次运行时都可以返回一个值。它们可以随附标准库,也可以由用户定义。您可以参考此以获取有关功能的更多信息。
del
在python中是一个关键字,因为它做了普通的python函数无法执行的操作:它与基础内存交互,并从内存中解开变量。它是用Cpython实施的。Python keywords are essentially
special reserved words that have specific meanings and purposes and can’t be used for anything but those specific purposes.
They come with the python standard library and you cannot change them in anyway. You can read more about keywords here If you runhelp("keywords")
in your python interpreter, a bunch of keywords will be returned, anddel
is one of them.Python statements refer to any line/lines of python code (which include stuff such as
del motorcycles[0]
andprint(motorcycles[0])
), and they do not have to meet any specific conditions to be classified as statements.Python functions refer to a block of reusable code that does something and can returns a value each time they are run. They can either come with the standard library or be defined by users. You can refer to this for more information about functions.
Del
in python is a keyword as it does something a normal python function cannot do: it interacts with the underlying memory and unbinds the variable from the memory. It is implemented with CPython.