1. 程式人生 > >實參和形參的一些問題

實參和形參的一些問題

its win 函數 false mpat edi darwin 形參 stdin

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;

實參和形參的一些問題