Untitled

Untitled

Python 中寫 x=5 的意思是指

  1. x → Variable (像是容器/變數)

  2. = → 中間的等號是 Assign

  3. 5 → 是value

  4. 所以是指把5assign 到x 這個變數variable 中

  5. 所以 Python 中 = (assignment operator 不等於數學中等號的概念)

  6. 運作的方式是把等號右邊的value input 到等號左邊

  7. 這也代表為什麼是 寫x=6 , 改寫成 6 = x 會有問題

    1. cannot assign to literal (x 無法assign to 文字)

x = 6
print(x)

6 = x  # show 
print(x) 

---------------------------------
[Running] python -u "d:\\2022_python_全攻略\\11. Functions for Numbers"
  File "d:\\2022_python_\\u5168\\u653b\\u7565\\11. Functions for Numbers", line 29
    6 = x
    ^
SyntaxError: cannot assign to literal

[Done] exited with code=1 in 0.087 seconds