開頭必須為英文字或是底線,不能用數字當開頭。
_player_1 | 🙆♀️ |
---|---|
player_1 | 🙆♀️ |
1_player | 🙅♀️ |
1player = "Grace"
print(1player) # 命名字首不得為數字。
# SyntaxError: invalid syntax
只能用字母、數字,以及底線作為命名元素。
命名大小寫有分別的。
NAME = "Grace"
print(name) # 命名的大小寫有區分。
# NameError: name 'name' is not defined
formal_name = "Grace Zhan"
formalName = "Grace Zhan" # camelcase 像駱駝駝峰一樣突然凸起。
haveBudget = True
if haveBudget:
print("Buy a house")
else:
print("Don't buy a house.")
# Buy house
haveBudget = True
if haveBudget == True:
print("Buy a house")
else:
print("Don't buy a house.")
# Buy a house
# 比較好的寫法
not_have_budget = False
if not not_have_budget:
print("buy a house")
else:
print ("Don't buy a house.")
# Buy a house