python学习——day02

1.函数的参数

可变参数:
定义:def fun(*number)
使用:fun(1,2,3,4)

关键字参数
定义:def other(**word)
使用:other(city='beijing',age=18)
输出:{'city':'beijing','age':18}

2.切片

利用切片操作,实现一个trim()函数,去除字符串首尾的空格,注意不要调用str的strip()方法:

def trim(s):
    if s!='':
        while(s[:1]==' '):
            s = s[1:]
        while(s[-1:]==' '):
            s = s[:-1]
    return s

猜你喜欢

转载自blog.csdn.net/lwycc2333/article/details/79989695