文章詳情頁
Python %r和%s區別代碼實例解析
瀏覽:5日期:2022-07-31 09:59:04
%r用rper()方法處理對象
%s用str()方法處理對象
相同結果
有些情況下,兩者處理的結果是一樣的,比如說處理int型對象。
例:
print(’I am %s years old.’ % 22)print(’I am %r years old.’ % 22)
返回結果:
I am 22 years old.I am 22 years old.
不同結果
例:
x = 'There are %d types of people.' % 10print(’I said: %r’ %x)print(’I said: %s’ %x)
返回結果
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)
返回結果
2020-04-022020-04-02datetime.date(2020, 4, 2)
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. php網絡安全中命令執行漏洞的產生及本質探究2. 三個不常見的 HTML5 實用新特性簡介3. Angular獲取ngIf渲染的Dom元素示例4. IIS+PHP添加對webp格式圖像的支持配置方法5. ASP調用WebService轉化成JSON數據,附json.min.asp6. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁7. 使用.net core 自帶DI框架實現延遲加載功能8. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析9. php測試程序運行速度和頁面執行速度的代碼10. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析
排行榜
