👋 들어가기전
- python스럽게 개발 전반적인 지식을 다음 페이지에 모아두고 있습니다. 필요시 확인하세요~
2022.07.19 - [Python/파이썬스럽게 개발하기] - [python] 파이썬스럽게 개발하기 다수의 링크
[python] 파이썬스럽게 개발하기 다수의 링크
※ 링크가 없을 경우 아직 작성 전 입니다. 🌈. 링크 모음 파이썬 공홈 파이썬 공식 github pep8 🌟🌟파이썬 문서 모음(공식) 🌟🌟 어썸 파이썬 Effective-Python 🌟python cheatsheet(기본기 요약 핸드북)
inhwanjeong.tistory.com
🚨 급한사람!! 이거만 보세요
- 정의되지 않은 arguments를 받고싶을때 사용
- args: 순서대로 Tuple로 받음
- (1,2,3)
- kwargs: keyword args로 DICT 형태로 데이터를 받음
- (a=1, b=2, c=3)
- args: 순서대로 Tuple로 받음
def some_function(*args, **kwargs):
print(f'args, {args}')
print(f'kwargs, {kwargs}')
# args
some_function(1,2,3)
#args, (1, 2, 3)
#kwargs, {}
# kwargs
some_function(a=1,b=2,c=3)
args, ()
kwargs, {'a': 1, 'b': 2, 'c': 3}
# args and kwargs
some_function(1,a=2)
args, (1,)
kwargs, {'a': 2}
1.Python *args and **kwargs 더 상세히
- 일반적으로 args와 kwargs를 만난다면 거부감을 느끼고 어렵다고 느낄 것입니다.
- 우리가 알아야하는 핵심은 많은수의 인수와 키워드를 전달할 수 있다는 것입니다.
- 왜 args와 kwargs라고 불릴까요?
- 해당 단어는 개발언어의 관례
- python 커뮤니티의 모범사례
- 여러 인수와 키워드를 받기위한 핵심 키워드는 *와 **이다.
- 실제 사용 예시
참고 url: https://www.pythoncheatsheet.org/blog/python-easy-args-kwargs
Python *args and **kwargs Made Easy - Python Cheatsheet
args and kwargs may seem scary, but the truth is that they are not that difficult to grasp and have the power to grant your functions with lots of flexibility.
www.pythoncheatsheet.org
'Python > 파이썬스럽게 개발하기' 카테고리의 다른 글
[python] mimesis - 파이썬 mock 데이터 (0) | 2022.08.18 |
---|---|
[python] haversine, 위도 경도를 이용하여 거리를 구하는 모듈 (0) | 2022.07.26 |
[python] 파이썬스럽게 개발하기 다수의 링크 (0) | 2022.07.19 |
[python] itertools (0) | 2022.03.17 |
[Python3] 동시성과 병렬성 (0) | 2021.04.16 |