Python oct 函數 - Python零基礎入門教程

目錄

基礎 Python 學習路線推薦 : Python 學習目錄 >> Python 基礎入門

oct 函數也是 Python 內置函數,主要將一個整數轉爲八進制,與 ord 函數 / chr 函數 有點類似;

一.Python oct 函數簡介

oct 函數將一個整數轉換成 8 進制字符串,語法如下:

'''
參數:
    x – 整數;

返回值:返回整數對應的八進制數據;
'''
oct(x)

二.Python oct 函數使用

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿說編程
@Blog(個人博客地址): www.codersrc.com
@File:Python oct 函數.py
@Time:2021/05/10 07:37
@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!

"""

>>>oct(10)
'012'
>>> oct(20)
'024'
>>> oct(15)
'017'
>>>

1.Python chr 函數將 ascll 碼轉爲字符

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿說編程
@Blog(個人博客地址): www.codersrc.com
@File:Python oct 函數.py
@Time:2021/05/10 07:37
@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!

"""

chr(65)
>>>> "A"

2.Python ord 函數將字符轉爲 ascll 碼

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿說編程
@Blog(個人博客地址): www.codersrc.com
@File:Python oct 函數.py
@Time:2021/05/10 07:37
@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!

"""

ord("A")
>>>> 65

三.猜你喜歡

  1. Python 條件推導式
  2. Python 列表推導式
  3. Python 字典推導式
  4. Python 不定長參數 *argc/**kargcs
  5. Python 匿名函數 lambda
  6. Python return 邏輯判斷表達式
  7. Python is 和 == 區別
  8. Python 可變數據類型和不可變數據類型
  9. Python 淺拷貝和深拷貝
  10. Python 異常處理
  11. Python 線程創建和傳參
  12. Python 線程互斥鎖 Lock
  13. Python 線程時間 Event
  14. Python 線程條件變量 Condition
  15. Python 線程定時器 Timer
  16. Python 線程信號量 Semaphore
  17. Python 線程障礙對象 Barrier
  18. Python 線程隊列 Queue – FIFO
  19. Python 線程隊列 LifoQueue – LIFO
  20. Python 線程優先隊列 PriorityQueue
  21. Python 線程池 ThreadPoolExecutor(一)
  22. Python 線程池 ThreadPoolExecutor(二)
  23. Python 進程 Process 模塊
  24. Python 進程 Process 與線程 threading 區別
  25. Python 進程間通信 Queue / Pipe
  26. Python 進程池 multiprocessing.Pool
  27. Python GIL 鎖

未經允許不得轉載:猿說編程 » Python oct 函數

本文由博客 - 猿說編程 猿說編程 發佈!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章