Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:将两个字符串作为关键字参数传递给函数_Python_Function_Arguments - Fatal编程技术网

Python:将两个字符串作为关键字参数传递给函数

Python:将两个字符串作为关键字参数传递给函数,python,function,arguments,Python,Function,Arguments,我希望:编写一个python程序,演示如何将两个字符串作为关键字参数传递给函数 我已经写了我认为正确的代码。想知道它是否正确,或者要更正什么 提前谢谢你 def class_students(fname,lname): print(fname + " " + lname) class_students("Sam" , "Walker") 要作为关键字参数传递,请将代码更改为: class_students(fname="S

我希望:编写一个python程序,演示如何将两个字符串作为关键字参数传递给函数

我已经写了我认为正确的代码。想知道它是否正确,或者要更正什么

提前谢谢你

def class_students(fname,lname):
print(fname + " " + lname)

class_students("Sam" , "Walker")

要作为关键字参数传递,请将代码更改为:

class_students(fname="Sam" , lname="Walker")
声明名称很有用,因为它可以确保参数按您希望的方式声明。此外,顺序并不重要:

class_students(lname="Walker", fname="Sam")
这也行得通