>pip list
>pip install redis
>pip install redis==3.2.0
>pip uninstall redis
>python -m pip install --upgrade pip
python代碼
person = "小小"
address = "中華路"
phone = "13877775555"
num = 10
# 字符串連接
print("recipient of the order:"+person+",地址:"+address+",電話:"+phone)
# The type of the concatenation on both ends of the plus sign must both be strings
# print("recipient of the order:"+person+",地址:"+address+",電話:"+phone+",商品數量:"+num)
''' 最後連接的num是整型,So it will report a type error Traceback (most recent call last): File "print.py", line 11, in <module> print("recipient of the order:"+person+",地址:"+address+",電話:"+phone+",商品數量:"+num) TypeError: can only concatenate str (not "int") to str '''
# 強制轉換 int ==> str
print("recipient of the order:"+person+",地址:"+address+",電話:"+phone+",商品數量:"+str(num))
# 格式化輸出 %s 字符串 %d 整型 %f 浮點型
print("recipient of the order:%s,地址:%s,電話:%s,商品數量:%s" % (person,address,phone,num))
# 格式化輸出 The underlying automatically coerces other types to string types
isMarry = False
print("Are you married? 回答:%s" % isMarry) # Strong bottom turn str(False) --> 'False'
# 結果: Are you married? 回答:False
# format %d digit 整型
age = 13
print("你的年齡是:%d" % age)
# 強轉成int型
age = 3.14
print("你的年齡是:%d" % age)
#結果: 3
# 格式化輸出 %f 浮點型
money = 123.36873
print("金額:%.2f" % money) # 保留小數點後2位,並四捨五入
# 結果: 123.37
# 練習 字符串原樣輸出
# 電影名稱:葉問
# 庫存:39
# 票價:19.9
# total list price:庫存 * 標價
name = "葉問"
count = 39
price = 19.9
total = count * price
msg = ''' 電影名稱:%s 庫存:%d 票價:%.1f total list price:%.2f ''' % (name,count,price,total)
print(msg)
# 結果:
# 電影名稱:葉問
# 庫存:39
# 票價:19.9
# total list price:776.10
name = "小小"
age = 18
movie = "看電影"
money = 15.98
# 字符串.format() 函數
msg = "{}今年{}歲了,喜歡{},有{}零花錢".format(name,age,movie,money)
print(msg)
# 結果:小小今年18歲了,喜歡看電影,有15.98零花錢