def my_func1(x,y,z=10): xyz = x*x + y*y - z return xyz print my_func1(2.5, -3.9) def circ(R=6371, pin=3.14): z = 2*R*pin return z c = circ() print 'The circumference of the Earth is %.1f km-s' % (c) def circ(R=6371, pin=3.14): z = 2*pin*R return z print circ(R=3397) # можно так print circ(3397) # а можно и вот так! print circ(pin=3.14, R=3397) # а можно ещё и так! print circ(3.14, 3397) # а вот так не получится! Или получиться? =) (см. формулу) print 'The circumference of the Mars is %.1f km-s' % (c) def circ(R, pin=3.14): z = 2*R*pin return z #с = circ(R=3397) # указали радиус Марса #с = circ(3397) # это тоже Марс #с = circ(pin=3.14, 3397) # а вот так не получится! Ошибка! print 'The circumference of the Mars is %.1f km-s' % (c) def my_func(): ''' This string is a comment ''' pass # ничего не делает, но без него тело функции будет пустым print(my_func.__doc__) def circ(R, pin=3.14): ''' Subroutine computes the planet circumference with given radii \n **INPUT:** \n `R [float]` - planet radii \n `pin [float]` - pi number. Initial pin=3.14 \n \v **OUTPUT:** \n `z [float]` - the planet circumference \n **Author:** Pavel Shabanov \n Blog: http://geofortran.blogspot.ru \n ''' z = 2*R*pin return z def circ(R, pin=3.14, out='R'): ''' Subroutine computes the planet circumference with given radii \n **INPUT:** \n `R [float]` - planet radii \n `pin [float]` - pi number. Initial pin=3.14 \n `out [str]` - output parameter. Initial out='R' \n \v **OUTPUT:** \n out='R': `z [float]` - the surface area of a planet \n \v out='RV': 1. `z [float]` - the planet circumference \n 2. `v [float]` - the surface area of a planet \n \v out='V': `v [float]` - the surface area of a planet \n **Author:** Pavel Shabanov \n Blog: http://geofortran.blogspot.ru \n ''' z = 2*R*pin if (out == 'R'): return z elif (out == 'RV'): v = 4*R*R*pin return z, v elif (out == 'V'): return 4*R*R*pin else: return z R, V = circ(R=3397, out='V') # ошибка (в выводе стоит один параметр - V (см. описание), а запросили два - R и V) print type(RV), RV RV = circ(R=3397, out='RV') # RV - не 2 числа, а кортеж из двух чисел print type(RV), RV