作者pkyosx (Insomnia)
看板Python
标题Re: [问题] Expression vs. statement
时间Fri Jan 5 21:03:08 2007
※ 引述《huggie (huggie)》之铭言:
: 什麽是 expression, 什麽是 statement?
: 应该有分这两种, 写了很久的python了 还是没弄懂
: http://norvig.com/python-iaq.html
: Java and C++ have the ternary conditional operator (test ? result :
: alternative). Python has resisted this, but in the upcoming Python 2.5 it
: will allow expressions of the form (result if test else alternative). This
: undermines Python's clear distinction between expressions and statements, but
: it is a compromise that many people have asked for.
: "distinction between expression and statements" 不懂他什麽意思
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
statement 是由一些 expression 组成,
主词 受词 都算是 expression, 完整的一句话就算是 statement
s = 2 + 1; //"s", "2+1" 是 expression, statement 则是 "s = 2+1;"
test? result:alternative 他认为有点模糊化了这两个关系
a = (i>10? 10:i); // 你觉得 i>10?10:i 算是 statement 还是 expression
// 从语意上来看 他已经具有一句话的功能 甚至超越了=>statement
// 但是从功能上来看 他就是一种计算 像是 2+1 =>expression
// 以上两句是我猜的 = ="
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.128.52