02.有如下函数定义,执行函数调用concat('earth','mars','venus',sep='.')的返回值是( )【注意:字符串 用单引号作为定界符】 #1.def concat(*args,sep='/'): #2. return sep.join(args)
时间: 2023-09-06 22:09:47 浏览: 36
执行函数调用concat('earth','mars','venus',sep='.')的返回值是'earth.mars.venus'。因为在函数定义中,使用了可变长参数*args,它会把传入的所有参数封装成一个元组,而sep参数的默认值是'/',在函数体中使用join方法以sep作为分隔符将这个元组中的所有元素连接起来,最终返回一个字符串。而在函数调用时,我们传入了三个字符串参数'earth'、'mars'、'venus',并且指定了sep参数的值为'.',因此函数返回的字符串为'earth.mars.venus'。
相关问题
有如下的函数定义: def concat(*args, sep="/"): return sep. join(args) 执行函数调用 concat(''earth'',''mars'',''venus'',sep=''. )的返回值是’__’。
这个函数定义中,使用了 *args 来表示可变数量的参数。在调用该函数时,所有的参数都会被收集到 args 这个元组里面。同时,函数也定义了一个名为 sep 的关键字参数,默认值为 "/"。
在执行 concat('earth', 'mars', 'venus', sep='') 这个函数调用时,传递了三个位置参数 'earth', 'mars', 'venus',以及一个关键字参数 sep='',表示使用空字符串作为分隔符。
因此,函数返回值为 'earthmarsvenus',而不是 '__'。如果要得到 '__',则应该执行 concat('earth', 'mars', 'venus', sep='__')。
如下的函数定义: def concat(*args, sep = "/"): return sep.join(args) 执行函数调用 concat("earth", "mars", "venus", sep = ".")的返回值是'__________'。
执行函数调用 `concat("earth", "mars", "venus", sep=".")` 的返回值是 `'earth.mars.venus'`。函数 `concat` 接受任意数量的位置参数 `*args`,并将它们使用指定的 `sep` 连接起来。在这里,我们传递了三个位置参数 `"earth"`, `"mars"`, 和 `"venus"`,并将 `sep` 设置为 `"."`,因此函数返回的字符串是 `"earth.mars.venus"`。