Python %r和%s區(qū)別代碼實(shí)例解析
%r用rper()方法處理對象
%s用str()方法處理對象
相同結(jié)果
有些情況下,兩者處理的結(jié)果是一樣的,比如說處理int型對象。
例:
print(’I am %s years old.’ % 22)print(’I am %r years old.’ % 22)
返回結(jié)果:
I am 22 years old.I am 22 years old.
不同結(jié)果
例:
x = 'There are %d types of people.' % 10print(’I said: %r’ %x)print(’I said: %s’ %x)
返回結(jié)果
I said: ’There are 10 types of people.’ # 通過%r 保留了原有所有屬性I said: There are 10 types of people.
例:
import datetimeriqi = datetime.date.today()print(riqi)print('%s' %riqi)print('%r' %riqi)
返回結(jié)果
2020-04-022020-04-02datetime.date(2020, 4, 2)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于PHP做個圖片防盜鏈2. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)3. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁4. XML在語音合成中的應(yīng)用5. jscript與vbscript 操作XML元素屬性的代碼6. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解7. ASP.NET MVC把數(shù)據(jù)庫中枚舉項的數(shù)字轉(zhuǎn)換成文字8. 如何使用ASP.NET Core 配置文件9. .NET中實(shí)現(xiàn)對象數(shù)據(jù)映射示例詳解10. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)
