iT邦幫忙

2025 iThome 鐵人賽

DAY 4
0
自我挑戰組

Python 函式大全系列 第 4

類型三 類型轉換

  • 分享至 

  • xImage
  •  

1. ascii():回傳物件ASCII編碼

✦ 指令功能 : 將物件轉換為 ASCII 編碼的字面表示

✦ 使用時機 : 除錯、檢視物件字面值預防亂碼等

https://ithelp.ithome.com.tw/upload/images/20250916/20177993J7iHhUjDGa.jpg

2. bin():將整數轉換為二進位字串

✦ 指令功能 : 將整數轉換成以 0b 作為開頭的二進位字串

✦ 使用時機 : 檢查位元狀態、資料分析

https://ithelp.ithome.com.tw/upload/images/20250916/201779930yVypY2k5y.jpg

3. bool(): 轉換為布林值 (True 或 False)

✦ 指令功能 : 檢查物件是否「有內容」或「非零」

✦ 使用時機 : 條件判斷、資料驗證等

https://ithelp.ithome.com.tw/upload/images/20250916/20177993IvHUKPAAus.jpg

4. chr():字元與ASCII碼轉換

✦ 指令功能 : 將一個整數轉換成對應的單一字元

✦ 使用時機 : 處理字元編碼、生成特定字元等

https://ithelp.ithome.com.tw/upload/images/20250916/201779938Zq7AFQDKW.jpg

5. float():轉換為浮點數

✦ 指令功能 : 將物件轉換為浮點數

✦ 使用時機 : 數學計算、科學應用等

https://ithelp.ithome.com.tw/upload/images/20250916/20177993KeaXSUPVho.jpg

6. hex():將整數轉換為十六進位字串

✦ 指令功能 : 將整數轉換為十六進位字串,以 0x 開頭表示十六進位格式

✦ 使用時機 : 記憶體位址表示、編碼相關應用等

https://ithelp.ithome.com.tw/upload/images/20250916/20177993drEDa8gAxf.jpg


上一篇
類型二 物件建構
下一篇
類型三 類型轉換
系列文
Python 函式大全10
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言