luyantl 发表于 2018-9-2 00:42:41

python函数

>>> def MyFirstFunction():
        print('创建的第一个函数')
        print('\n')
        print('结束')

>>> MyFirstFunction()
创建的第一个函数


结束
>>> def MySecondFunction(name):
        print(name+'我爱你')

>>> MySecondFunction(99)
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
    MySecondFunction(99)
File "<pyshell#86>", line 2, in MySecondFunction
    print(name+'我爱你')
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> MySecondFunction('44')
44我爱你



>>> #为什么数值型的会报错???
>>> 66+'字符型'
Traceback (most recent call last):
File "<pyshell#90>", line 1, in <module>
    66+'字符型'
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> #因为数字加字符型,不会自动转换成字符型?
>>>

露转溪桥 发表于 2018-9-2 10:29:44

数字+字符本来就没有意义呀, 就好比数字*字符,会变成n个字符 数字后面跟着+号就是作为数值进行运算的
页: [1]
查看完整版本: python函数