파이썬[Python]: collections - _field_defaults 변수

collections 모듈 - _field_defaults 변수(variable)


/// 설명

튜플에 주어지는 기본값을 표현합니다.(주어진 값은 변하지 않습니다.)

※ 형식
namedtuple._field_defaults

reference
https://docs.python.org/3/library/collections.html#module-collections

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import collections
 
Test1 = collections.namedtuple('Test1', ['a''b''c'], defaults=(12))
 
test_nt = Test1(a='a')
print(test_nt)  # Test1(a='a', b=1, c=2)
print(Test1._field_defaults)  # {'b': 1, 'c': 2}
 
Test2 = collections.namedtuple('Test2', ['a''b''c'], defaults=(123))
 
test_nt = Test2()
print(test_nt)  # Test2(a=1, b=2, c=3)
print(test_nt._field_defaults)  # {'a': 1, 'b': 2, 'c': 3}
test_nt = Test2(a='a')
print(test_nt)  # Test2(a='a', b=2, c=3)
print(Test2._field_defaults)  # {'a': 1, 'b': 2, 'c': 3}
 
cs

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


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

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

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

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

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

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