*args는 이름이 지정되지 않은 여러 매개변수(튜플)를 나타냅니다. **kwargs는 딕셔너리인 키워드 매개변수를 나타냅니다.
def fun(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '###' if __name__ == '__main__': foo(1,2,3,4) foo(a=1,b=2,c=3) foo(1,2,3,4, a=1,b=2,c=3) foo('a', 1, None, a=1, b='2', c=3)
출력 결과는 다음과 같습니다.
args = (1, 2, 3, 4) kwargs = {} ### args = () kwargs = {'a': 1, 'c': 3, 'b': 2} ### args = (1, 2, 3, 4) kwargs = {'a': 1, 'c': 3, 'b': 2} ### args = ('a', 1, None) kwargs = {'a': 1, 'c': 3, 'b': '2'} ###
보시다시피 이 둘은 파이썬에서 변수 매개변수입니다.
참고: *args와 **kwargs를 동시에 사용하는 경우 *args 매개변수는 foo(a=1, b='2', c=3, a', 1, None, ) 이런 식으로 호출하면 "SyntaxError: 키워드 arg 뒤에 키워드가 아닌 arg"라는 구문 오류가 표시됩니다.
def fun2(param1, *args, **kwargs): print 'param1 = ', param1 print 'args = ', args print 'kwargs = ', kwargs print '###' fun2(1, 2, 3, 4, a=1,b=2,c=3)
출력 결과:
param1 = 1 args = (2,3,4) kwargs = {'a': 1, 'c': 3, 'b': 2} ###
1이 param1에 할당되고 나머지 2, 3, 4가 할당됩니다. * args에, 나머지는 **kwargs에 할당됩니다
사전을 만드는 매우 아름다운 사용법도 있습니다:
def kw_dict(**kwargs): return kwargs print kw_dict(a=1,b=2,c=3)
결과:
{'a':1, 'b':2, 'c':3}
실제로 Python에는 dict 클래스가 있습니다. dict(a=1,b=2,c=3)을 사용하여 사전을 만들 수 있습니다.

Arraysinpython, 특히 비밀 복구를위한 ArecrucialInscientificcomputing.1) theaRearedFornumericalOperations, DataAnalysis 및 MachinELearning.2) Numpy'SimplementationIncensuressuressurations thanpythonlists.3) arraysenablequick

Pyenv, Venv 및 Anaconda를 사용하여 다양한 Python 버전을 관리 할 수 있습니다. 1) PYENV를 사용하여 여러 Python 버전을 관리합니다. Pyenv를 설치하고 글로벌 및 로컬 버전을 설정하십시오. 2) VENV를 사용하여 프로젝트 종속성을 분리하기 위해 가상 환경을 만듭니다. 3) Anaconda를 사용하여 데이터 과학 프로젝트에서 Python 버전을 관리하십시오. 4) 시스템 수준의 작업을 위해 시스템 파이썬을 유지하십시오. 이러한 도구와 전략을 통해 다양한 버전의 Python을 효과적으로 관리하여 프로젝트의 원활한 실행을 보장 할 수 있습니다.

Numpyarrayshaveseveraladvantagesstandardpythonarrays : 1) thearemuchfasterduetoc 기반 간증, 2) thearemorememory-refficient, 특히 withlargedatasets 및 3) wepferoptizedformationsformationstaticaloperations, 만들기, 만들기

어레이의 균질성이 성능에 미치는 영향은 이중입니다. 1) 균질성은 컴파일러가 메모리 액세스를 최적화하고 성능을 향상시킬 수 있습니다. 2) 그러나 유형 다양성을 제한하여 비 효율성으로 이어질 수 있습니다. 요컨대, 올바른 데이터 구조를 선택하는 것이 중요합니다.

tocraftexecutablepythonscripts, 다음과 같은 비스트 프랙티스를 따르십시오 : 1) 1) addashebangline (#!/usr/bin/envpython3) tomakethescriptexecutable.2) setpermissionswithchmod xyour_script.py.3) organtionewithlarstringanduseifname == "__"

numpyarraysarebetterfornumericaloperations 및 multi-dimensionaldata, mumemer-efficientArrays

numpyarraysarebetterforheavynumericalcomputing, whilearraymoduleisiMoresuily-sportainedprojectswithsimpledatatypes.1) numpyarraysofferversatively 및 formanceforgedatasets 및 complexoperations.2) Thearraymoduleisweighit 및 ep

ctypesallowscreatingandmanipulatingC-stylearraysinPython.1)UsectypestointerfacewithClibrariesforperformance.2)CreateC-stylearraysfornumericalcomputations.3)PassarraystoCfunctionsforefficientoperations.However,becautiousofmemorymanagement,performanceo


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
