La lecture en ligne est gratuite
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
Télécharger Lire

Python language: Functions, modules and objects (session 9)

De
38 pages
Python language: Functions,modules and objectsThe FOSSEE GroupDepartment of Aerospace EngineeringIIT Bombay1 May, 2010Day 2, Session 3FOSSEE Team (IIT Bombay) Basic Python 1 / 37Outline1 FunctionsDefault argumentsKeywordBuilt-in functionsExercises2 Modules3 ObjectsFOSSEE Team (IIT Bombay) Basic Python 2 / 37FunctionsOutline1 FunctionsDefault argumentsKeywordBuilt-in functionsExercises2 Modules3 ObjectsFOSSEE Team (IIT Bombay) Basic Python 3 / 37Functions Default argumentsOutline1 FunctionsDefault argumentsKeywordBuilt-in functionsExercises2 Modules3 ObjectsFOSSEE Team (IIT Bombay) Basic Python 4 / 37Functions Default argumentsFunctions: default argumentsIn []: greet = ’hello world’In []: greet.split()Out[]: [’hello’, ’world’]In []: line = ’Rossum, Guido, 54, 46, 55’In []: line.split(’,’)Out[]: [’Rossum’, ’ Guido’, ’ 54’,’ 46’, ’ 55’]FOSSEE Team (IIT Bombay) Basic Python 5 / 37Functions Default argumentsFunctions: default arguments . . .In []: def welcome(greet, name="World"):.... print greet, nameIn []: welcome("Hello")Hello WorldIn []: welcome("Hi", "Guido")Hi GuidoFOSSEE Team (IIT Bombay) Basic Python 6 / 37Functions Keyword argumentsOutline1 FunctionsDefault argumentsKeywordBuilt-in functionsExercises2 Modules3 ObjectsFOSSEE Team (IIT Bombay) Basic Python 7 / 37Functions Keyword argumentsFunctions: Keyword argumentsWe have seen the followinglegend([’sin(2y)’], loc = ’center’)plot(y, sin(y), ’g’, ...
Voir plus Voir moins

Vous aimerez aussi

OFSSEEeT
Python language: Functions, modules and objects
maI(TIoBbmya)
The FOSSEE Group
Department of Aerospace Engineering IIT Bombay
1 May, 2010 Day 2, Session 3
BasicPython1/37
Outline
1
2
3
OF
Functions Default arguments Keyword arguments Built-in functions Exercises
Modules
Objects
SSEETeam(IITBombay)aBsicyPhtno2/73
3
Objects
nutcFuOltoisnenieaETSEOSF
1
Functions Default arguments Keyword arguments Built-in functions Exercises
2
Modules
/37hon3cPytaBisab)yBTmo(mII
ctunFafeDsnoimugratluentsOutlinemoBTII(maeTEESSOn4hoytcPsiBay)baF
Objects
3
3/7
1
Functions Default arguments Keyword arguments Built-in functions Exercises
Modules
2
nsiofaDeFctuntsumened:snoitgratluafumrgtaulncFutsen55
greet.split() [holle,orldw]
line =’Rossum, Guido,
54,
line.split(’,’) [msousR,’ Guido’,’ 54’, ’ 46’,55’]
In []:
In []:
In []: Out[]:
In []: Out[]:
greet =’hello world’
no/573
46,
icasthPymbBo)BaymaeTTII(OFEESS
DensioctunFuFstnemugratluafcnitno:sedafluatrguments...maeTTII(OFEESS
In []: welcome("olleH") Hello World
In []: welcome("Hi",o""idGu) Hi Guido
no/673
In []:defwelcome(greet, name="Wldor"): ....printgreet, name
asicPythBombay)B
oisnnutcF/37hon7cPytBasi
Objects
3
1
Functions Default arguments Keyword arguments Built-in functions Exercises
Modules
2
m(IIETeabay)TBomSOESFtlOueinwyeKadromugrstne
rgdaenumKes:orywstKeywordaunctionsuFcnitnogrmunestF
pie(science.values(), labels = science.keys())
annotate(’local max’, xy = (1.5, 1))
We have seen the following
plot(y, sin(y),’g’, linewidth = 2)
legend([(2y)sin], loc =retnec)
/873thonicPy)BasmbayoBTII(maeTEESSOF
an(e"=emdiuGg,"on[Iwe]:omlcSOESdiFo(mIITEae="HereeteyGuy")H73/9noh
In []: welcome("eHll"o,mes""aJ) Hello James
In []: welcome("Hi", name=G"iuod") Hi Guido
y)baomTBytcPsiBaroadgrmuoisneKwyFunctt,eemena)"dl...:irp.rgtnet,n(gre"Worame=:]edI.[nocemwflergdaoryw..tsenumcnuFstneek:snoit
ontiutsOint-ncfusnoiliuBFtcnuilenSSOFeTEEam(IITBombay)BasciyPhtno013/7
1
Functions Default arguments Keyword arguments Built-in functions Exercises
3
Objects
2
Modules
bmoBTII(cisaB)yaFOamTeEESSPython11/37
10 m
Variety of built-in functions are available abs, any, all, len, max, min pow, range, sum, type Refer here:t/hdoonctsp.:py//ht.org library/functions.html
rofeirweitcnBsnoioctnngtiunafFunsnuBtcoiniufli-t
Un pour Un
Permettre à tous d'accéder à la lecture
Pour chaque accès à la bibliothèque, YouScribe donne un accès à une personne dans le besoin