实参和形参的一些问题

1.形参和实参的一些问题

2.另外,了解到list默认为可变类型的,append函数是原地修改对象的;要把列表与字符串、元组区分开来。故可在方法内修改外传进来的list

 

Last login: Fri Aug 11 08:51:47 on console
bingjun1:~ bingjun$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> y = math.sqrt
>>> print y(4)
2.0
>>> callable(y)
True
>>> callable(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = 1
>>> callable(x)
False
>>> def hello(name):
... return ('str1','str2')
... hello('ad')
File "<stdin>", line 3
hello('ad')
^
SyntaxError: invalid syntax
>>> def hello(name):
... return ('str1','str2')
...
>>> hello('ad')
('str1', 'str2')
>>> def hello(name):
... return ['str1','str2']
...
>>> hello('asdf')
['str1', 'str2']
>>> help(hello)

>>> hellp(hello)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hellp' is not defined
>>> help(hello)

>>> help(hello)

>>> def hello(name):
... 'test 文档字符串'
... return 'name'
...
>>> hello.__doc__
'test \xe6\x96\x87\xe6\xa1\xa3\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2'
>>> help(hello)

>>> help(hello)

>>> help(sqrt)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sqrt' is not defined
>>>
>>> def appendList(list)
File "<stdin>", line 1
def appendList(list)
^
SyntaxError: invalid syntax
>>> def appendList(list):
... list.append(4)
...
>>> list = [1, 2, 3]
>>> appendList(list)
>>> list
[1, 2, 3, 4]
>>> def appendList(list):
... list = 'shuai'
...
>>> list = he
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'he' is not defined
>>> list = 'he'
>>> appendList(list)
>>> list
'he'
>>> liston;

转载于:https://www.cnblogs.com/wskgjmhh/p/7347298.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值