python语句和函数的区别_Python中的语句和函数有什么区别?

Edit: The suggested duplicate, does not answer my question, as I am primarily concerned with the difference in Python specifically. The suggested duplicate is far broader than this question.

I have recently started to learn Python. I'm currently reading "Learn Python the Hard Way". I have some ad-hoc programming experience, but am going back to the beginning to learn everything from the ground up this time.

In the book, one of the first lessons concerns print and the author provides various instructions of its use in Python 2.7, e.g.:

print "This is fun."

I found myself wondering what print is technically called here from the programming perspective. Some research found this, PEP-3105

In which case is made to make print a function:

The print statement has long appeared on lists of dubious language

features that are to be removed in Python 3000, such as Guido's

"Python Regrets" presentation 1 . As such, the objective of this PEP

is not new, though it might become much disputed among Python

developers.

So print is a statement in Python 2.7, and a function in Python 3.

But I have been unable to find a straight-forward definition for the difference between a statement and a function. I found this also by the person who invented Python, Guido van Rossum in which he explains why it would be good to make print a function instead of a statement.

From what I have read it appears that a function is some code that takes parameters and returns a value. But isn't print doing this in python 2.7? Isn't it taking in strings and returning a concatenated string?

What is the difference between a statement and a function in Python?

解决方案

A statement is a syntax construct. A function is an object. There's statements to create functions, like def:

def Spam(): pass

So statements are one of the ways to indicate to Python that you want it to create a function. Other than that, there's really not much relation between them.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值