Python中的表达式和语句有什么区别? [英] What is the difference between an expression and a statement in Python?

查看:206
本文介绍了Python中的表达式和语句有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

.python.org / reference / expressions.htmlrel =noreferrer>表达式只包含标识符文字运算符,其中运算符包括算术和布尔运算符,功能通话操作员 () 订阅运营商 [] 和类似的,可以减少到某种价值,这可以是任何Pyth对象。示例:

  3 + 5 
地图(lambda x:x * x,range(10))
[ax for a in some_iterable]
yield 7

语句(请参阅 1 2 )是可以构成一行(或几行)Python代码的一切。请注意,表达式也是语句。示例:

 #所有上述表达式
打印42
如果x:do_y()
return
a = 7


In Python, what is the difference between expressions and statements?

解决方案

Expressions only contain identifiers, literals and operators, where operators include arithmetic and boolean operators, the function call operator () the subscription operator [] and similar, and can be reduced to some kind of "value", which can be any Python object. Examples:

3 + 5
map(lambda x: x*x, range(10))
[a.x for a in some_iterable]
yield 7

Statements (see 1, 2), on the other hand, are everything that can make up a line (or several lines) of Python code. Note that expressions are statements as well. Examples:

# all the above expressions
print 42
if x: do_y()
return
a = 7

这篇关于Python中的表达式和语句有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆