Python 中 = 和 == 運算子有什麼區別?
在 Python 中,= 符號定義為賦值運算子。它要求左側有一個變數,右側有一個表示式。右側表示式中的值被賦值給左側的變數。表示式和變數名稱不能互換。
>>> a=10 >>> b=20 >>> c=a+b >>> a,b,c (10, 20, 30) >>> a+b=c SyntaxError: can't assign to operator
== 符號是比較運算子,稱為等於運算子。如果兩邊的運算元相等,則返回 true,否則返回 false
>>> 10+2 == 10 False >>> (10+2) == 12 True >>> 'computer' == 'Computer' False >>> 'computer' == "computer" True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP