變量
需求,計算商品總價
變量:用來存儲數據的值表現形式
#蘋果數量
count1 = 2
#蘋果單價
price1 = 2.1
#雪糕數量
count2 = 3
#雪糕單價
price2 = 3
#榴蓮數量
count3 = 1
#榴蓮單價
price3 = 99
money = count1*price1+count2*price2+count3*price3
print("總價是%g 元"%money)
控制檯輸出結果
總價是112.2 元
標識符和關鍵字
%g:變量佔位符
Import keywords:導入Python中的所有關鍵字包
#佔位符
count1=2
print(count1)
print("count1=%g"%count1)
count2=5
print("count1=%g\tcount2=%g" % (count1, count2))
print("\ncount1=%g\ncount2=%g" % (count1, count2))
# 以下爲打印結果
# 2
# count1=2
# count1=2 count2=5
#
# count1=2
# count2=5
# 關鍵字
# 大小寫敏感
a=100
A=200
# 不能使用系統關鍵字作爲標識符
# class=22
import keyword
# 將所有的關鍵字存儲到變量result中
result = keyword.kwlist
# 打印所有的關鍵字
print(result)
# 求result中關鍵字的個數
print(len(result))
print(result.__len__())
# 以下爲打印結果
# ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'e