파이썬[Python]: 내장함수 - oct 함수

내장함수 - oct 함수(function)


/// 설명

정수를 접두사 '0o'를 포함하는 8진수 형태로 변환하여 반환합니다.

※ 형식
oct()

reference
https://docs.python.org/3/library/functions.html

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
test_int = 63
test_hex = oct(test_int)
print(test_hex)  # 0o77
 
test_int = 0b111111
test_hex = oct(test_int)
print(test_hex)  # 0o77
 
test_hex = '%#o'  # 0x
print(test_hex % test_int)  # 0o77
test_hex = '%o'  # lowercase
print(test_hex % test_int)  # 77
 
test_hex = '{:#o}'  # 0x
print(test_hex.format(test_int))  # 0o77
test_hex = '{:o}'  # lowercase
print(test_hex.format(test_int))  # 77
 
print(f'{test_int:#o}')  # 0o77
print(f'{test_int:o}')  # 77
 
cs

/// 예제 __index__()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class A:
    def __init__(self, a):
        self.a = a
 
    def __index__(self):
        return int(self.a)
 
print(A(1.1))  # <__main__.A object at 0x0000021242B6CFD0>
 
print(oct(A(1.1)))  # 0o1
print(oct(A(88.5)))  # 0o130
 
= A(1.5)
 
print(oct(a))  # 0o1
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

C 언어: sin 함수, cos 함수, tan 함수

파이썬[Python]: 내장함수 - bit_length 메서드