带参数和不带参数的Python单个函数



问题

我的部分解决方案

如果我想按照问题中的要求同时运行带参数和不带参数的函数,我该怎么办?

代码:

import pandas as pd
import numpy as np
def range_series(x,y):
if not x:
x=1
if not y:
y=10
d = np.array([])
d = np.arange(x,y)
s = pd.Series(d)
print(s)
print(type(s))

量程系列(5,10(

函数头中需要默认参数。

例如:

def my_func(x=2, y=3)
print(x+y)

当未指定这些参数时,此函数会将值2分配给x,将值3分配给y。

因此:

my_func()
> 5
my_func(5, 10)
> 15

相关内容

最新更新