myd@ubuntu:~$ python3
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def func():
... global x
... print('x is', x)
... x = 2
... print('change local x to', x)
...
>>> x = 50
>>> func()
x is 50
change local x to 2
>>> print('value of x is', x)
value of x is 2
>>> def saySomething(msg, times = 1):
... print(msg * times)
...
>>> saySomething('Oh')
Oh
>>> saySomething('Oh', 10)
OhOhOhOhOhOhOhOhOhOh
>>> def func_key(a, b = 5, c = 10):
... print('a is', a, 'and b is', b, 'and c is', c)
...
>>> func_key(3, 7)
a is 3 and b is 7 and c is 10
>>> func_key(25, c = 24)
a is 25 and b is 5 and c is 24
>>> func_key(c = 50, a = 100)
a is 100 and b is 5 and c is 50
>>> def maximum(x, y):
... if x > y:
... return x
... else:
... return y
...
>>> maximum(3, 7)
7
>>> maximum(100, 7)
100
>>> def someFunction():
... pass
...
>>> if None == someFunction():
... print('OK')
...
OK
>>> import os
>>> os.system('clear')
>>> def printMax(x, y):
... '''
... Prints the maximum of two numbers.
... The two values must be integers.
... Now the \'DocStrings\' is over.
... '''
... if x > y:
... print(x)
... else:
... print(y)
...
>>> printMax(100, 20)
100
>>> print(printMax.__doc__)
Prints the maximum of two numbers.
The two values must be integers.
Now the 'DocStrings' is over.
>>>
>>> help(printMax)
func
最新推荐文章于 2022-07-07 16:47:16 发布