Python Function Arguments - W3Schools

文章推薦指數: 80 %
投票人數:10人

The terms parameter and argument can be used for the same thing: information that are passed into a function. From a function's perspective: A parameter is the ... Tutorials References Exercises Videos Menu Login Website GetCertified ProNEW HTML CSS JAVASCRIPT SQL PYTHON PHP BOOTSTRAP HOWTO W3.CSS JAVA JQUERY C C++ C# R React    Darkmode Darkcode × Tutorials HTMLandCSS LearnHTML LearnCSS LearnRWD LearnBootstrap LearnW3.CSS LearnColors LearnIcons LearnGraphics LearnSVG LearnCanvas LearnHowTo LearnSass DataAnalytics LearnAI LearnMachineLearning LearnDataScience LearnNumPy LearnPandas LearnSciPy LearnMatplotlib LearnStatistics LearnExcel XMLTutorials LearnXML LearnXMLAJAX LearnXMLDOM LearnXMLDTD LearnXMLSchema LearnXSLT LearnXPath LearnXQuery JavaScript LearnJavaScript LearnjQuery LearnReact LearnAngularJS LearnJSON LearnAJAX LearnAppML LearnW3.JS Programming LearnPython LearnJava LearnC LearnC++ LearnC# LearnR LearnKotlin LearnGo LearnDjango LearnTypeScript ServerSide LearnSQL LearnMySQL LearnPHP LearnASP LearnNode.js LearnRaspberryPi LearnGit LearnAWSCloud WebBuilding CreateaWebsiteNEW WhereToStart WebTemplates WebStatistics WebCertificates WebDevelopment CodeEditor TestYourTypingSpeed PlayaCodeGame CyberSecurity Accessibility Blog DataAnalytics LearnAI LearnMachineLearning LearnDataScience LearnNumPy LearnPandas LearnSciPy LearnMatplotlib LearnStatistics LearnExcel LearnGoogleSheets XMLTutorials LearnXML LearnXMLAJAX LearnXMLDOM LearnXMLDTD LearnXMLSchema LearnXSLT LearnXPath LearnXQuery × References HTML HTMLTagReference HTMLBrowserSupport HTMLEventReference HTMLColorReference HTMLAttributeReference HTMLCanvasReference HTMLSVGReference GoogleMapsReference CSS CSSReference CSSBrowserSupport CSSSelectorReference Bootstrap3Reference Bootstrap4Reference W3.CSSReference IconReference SassReference JavaScript JavaScriptReference HTMLDOMReference jQueryReference AngularJSReference AppMLReference W3.JSReference Programming PythonReference JavaReference ServerSide SQLReference MySQLReference PHPReference ASPReference XML XMLDOMReference XMLHttpReference XSLTReference XMLSchemaReference CharacterSets HTMLCharacterSets HTMLASCII HTMLANSI HTMLWindows-1252 HTMLISO-8859-1 HTMLSymbols HTMLUTF-8 × ExercisesandQuizzes Exercises HTMLExercises CSSExercises JavaScriptExercises SQLExercises MySQLExercises PHPExercises PythonExercises NumPyExercises PandasExercises SciPyExercises jQueryExercises JavaExercises C++Exercises C#Exercises RExercises KotlinExercises GoExercises BootstrapExercises Bootstrap4Exercises Bootstrap5Exercises GitExercises Quizzes HTMLQuiz CSSQuiz JavaScriptQuiz SQLQuiz MySQLQuiz PHPQuiz PythonQuiz NumPyQuiz PandasQuiz SciPyQuiz jQueryQuiz JavaQuiz C++Quiz C#Quiz RQuiz KotlinQuiz XMLQuiz BootstrapQuiz Bootstrap4Quiz Bootstrap5Quiz CyberSecurityQuiz AccessibilityQuiz Courses HTMLCourse CSSCourse JavaScriptCourse FrontEndCourse SQLCourse PHPCourse PythonCourse NumPyCourse PandasCourse DataAnalyticsCourse jQueryCourse JavaCourse C++Course C#Course RCourse React.jsCourse Bootstrap3Course Bootstrap4Course XMLCourse CyberSecurityCourse AccessibilityCourse Certificates HTMLCertificate CSSCertificate JavaScriptCertificate FrontEndCertificate SQLCertificate PHPCertificate PythonCertificate DataScienceCertificate Bootstrap3Certificate Bootstrap4Certificate Bootstrap5Certificate jQueryCertificate JavaCertificate C++Certificate C#Certificate React.jsCertificate TypeScriptCertificate XMLCertificate CyberSecurityCertificate AccessibilityCertificate ExcelCertificate × Tutorials References Exercises GetCertified Spaces Videos Shop Pro PythonTutorial PythonHOME PythonIntro PythonGetStarted PythonSyntax PythonComments PythonVariables PythonVariables VariableNames AssignMultipleValues OutputVariables GlobalVariables VariableExercises PythonDataTypes PythonNumbers PythonCasting PythonStrings PythonStrings SlicingStrings ModifyStrings ConcatenateStrings FormatStrings EscapeCharacters StringMethods StringExercises PythonBooleans PythonOperators PythonLists PythonLists AccessListItems ChangeListItems AddListItems RemoveListItems LoopLists ListComprehension SortLists CopyLists JoinLists ListMethods ListExercises PythonTuples PythonTuples AccessTuples UpdateTuples UnpackTuples LoopTuples JoinTuples TupleMethods TupleExercises PythonSets PythonSets AccessSetItems AddSetItems RemoveSetItems LoopSets JoinSets SetMethods SetExercises PythonDictionaries PythonDictionaries AccessItems ChangeItems AddItems RemoveItems LoopDictionaries CopyDictionaries NestedDictionaries DictionaryMethods DictionaryExercise PythonIf...Else PythonWhileLoops PythonForLoops PythonFunctions PythonLambda PythonArrays PythonClasses/Objects PythonInheritance PythonIterators PythonScope PythonModules PythonDates PythonMath PythonJSON PythonRegEx PythonPIP PythonTry...Except PythonUserInput PythonStringFormatting FileHandling PythonFileHandling PythonReadFiles PythonWrite/CreateFiles PythonDeleteFiles PythonModules NumPyTutorial PandasTutorial SciPyTutorial DjangoTutorial PythonMatplotlib MatplotlibIntro MatplotlibGetStarted MatplotlibPyplot MatplotlibPlotting MatplotlibMarkers MatplotlibLine MatplotlibLabels MatplotlibGrid MatplotlibSubplot MatplotlibScatter MatplotlibBars MatplotlibHistograms MatplotlibPieCharts MachineLearning GettingStarted MeanMedianMode StandardDeviation Percentile DataDistribution NormalDataDistribution ScatterPlot LinearRegression PolynomialRegression MultipleRegression Scale Train/Test DecisionTree ConfusionMatrix HierarchicalClustering LogisticRegression GridSearch CategoricalData K-means BootstrapAggregation CrossValidation AUC-ROCCurve K-nearestneighbors PythonMySQL MySQLGetStarted MySQLCreateDatabase MySQLCreateTable MySQLInsert MySQLSelect MySQLWhere MySQLOrderBy MySQLDelete MySQLDropTable MySQLUpdate MySQLLimit MySQLJoin PythonMongoDB MongoDBGetStarted MongoDBCreateDatabase MongoDBCreateCollection MongoDBInsert MongoDBFind MongoDBQuery MongoDBSort MongoDBDelete MongoDBDropCollection MongoDBUpdate MongoDBLimit PythonReference PythonOverview PythonBuilt-inFunctions PythonStringMethods PythonListMethods PythonDictionaryMethods PythonTupleMethods PythonSetMethods PythonFileMethods PythonKeywords PythonExceptions PythonGlossary ModuleReference RandomModule RequestsModule StatisticsModule MathModule cMathModule PythonHowTo RemoveListDuplicates ReverseaString AddTwoNumbers PythonExamples PythonExamples PythonCompiler PythonExercises PythonQuiz PythonCertificate PythonFunctionArguments ❮PythonGlossary Arguments Informationcanbepassedintofunctionsasarguments. Argumentsarespecifiedafterthefunctionname,insidetheparentheses. Youcanaddasmanyargumentsasyouwant,justseparatethemwithacomma. Thefollowingexamplehasafunctionwithoneargument(fname). Whenthefunctioniscalled,wepassalongafirstname, whichisusedinsidethefunctiontoprintthefullname: Example defmy_function(fname): print(fname+"Refsnes") my_function("Emil")my_function("Tobias")my_function("Linus") TryitYourself» ArgumentsareoftenshortenedtoargsinPythondocumentations. ParametersorArguments? Thetermsparameterandargumentcanbeusedforthesamething:informationthatarepassedintoafunction. Fromafunction'sperspective: Aparameteristhevariablelistedinsidetheparenthesesinthefunctiondefinition. Anargumentisthevaluethataresenttothefunctionwhenitiscalled. NumberofArguments Bydefault,afunctionmustbecalledwiththecorrectnumberofarguments. Meaningthatifyourfunctionexpects2arguments,youhavetocallthefunction with2arguments,notmore,andnotless. Example Thisfunctionexpects2arguments,andgets2arguments: defmy_function(fname,lname): print(fname+""+lname) my_function("Emil","Refsnes") TryitYourself» Ifyoutrytocallthefunctionwith1or3arguments,youwillgetanerror: Example Thisfunctionexpects2arguments,butgetsonly1: defmy_function(fname,lname): print(fname+""+lname) my_function("Emil") TryitYourself» RelatedPages PythonFunctionsTutorial Function CallaFunction *args KeywordArguments **kwargs DefaultParameterValue PassingaListasanArgument FunctionReturnValue ThepassStatementiFunctions FunctionRecursion ❮PythonGlossary NEW WejustlaunchedW3Schoolsvideos Explorenow COLORPICKER Getcertifiedbycompletingacoursetoday! w3schoolsCERTIFIED.2022 Getstarted CODEGAME PlayGame



請為這篇文章評分?