Re: [問題] Expression vs. statement
※ 引述《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
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章