实参和形参的一些问题

Posted 有一天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实参和形参的一些问题相关的知识,希望对你有一定的参考价值。

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;

以上是关于实参和形参的一些问题的主要内容,如果未能解决你的问题,请参考以下文章

1.实参和形参的关系 2.函数的参数可以是任意类型吗? 3.函数作用域的问题

实参和形参的关系2.函数的参数可以是任意数据类型吗?3。函数的作用域问题

实参和形参

形参的形参和实参的关系

关于python函数形参实参和变量作用域的分析

VBA的有参过程定义,形参用啥说明