Functions
What is a function?
Creating function
Function <function name> can be defined using following syntax:
def <function name>(arg1,arg2,...,argN):
<body of function>
return <output of function>
Where arg1,arg2,...,argN - arguments of function, <body of function> - actual block of code, <output of function> - return value, in fact - not necessary for some functions.
Built-in functions
Also, additionally to function, that we could create, there are a variety of built-in functions, which we can use without importing any libraries beforehand.
Among them we can highlight next:
type(v)- returns type of a variable/valuev, which passed as argument;map(f, c)- returns iterable collection, in which functionfapplied to each element of iterable collectionc;filter(f, c)- returns iterable collection, which contains those elements of iterable collectionc, for which value offisTrue;zip(c1,c2)- returns list of tuples with an item from each iterable collectionc1andc2, by iterating them in parallel;len(s)- return number of items in objects(either can be sequence, like string, or collection);max(c)- returns maximum value in iterable collectionc;max(arg1,arg2)- returns maximum value of elementsarg1andarg2(can be used with larger number of arguments);min()- have two ways of usage, just likemax(), however - finds minimum value;sum()- returns sum of elements into collection;pow(base, power)- returns numberbaseraised to powerpower;int(),float(),complex(),bool,list(),dict(),set(),str(),tuple(), etc - convert variable/value to the corresponding datatype.
Addition
For more detailed explanation and examples - dive into video:
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Still meg spørsmål om dette emnet
Oppsummer dette kapittelet
Vis eksempler fra virkeligheten
Awesome!
Completion rate improved to 7.14
Functions
Sveip for å vise menyen
What is a function?
Creating function
Function <function name> can be defined using following syntax:
def <function name>(arg1,arg2,...,argN):
<body of function>
return <output of function>
Where arg1,arg2,...,argN - arguments of function, <body of function> - actual block of code, <output of function> - return value, in fact - not necessary for some functions.
Built-in functions
Also, additionally to function, that we could create, there are a variety of built-in functions, which we can use without importing any libraries beforehand.
Among them we can highlight next:
type(v)- returns type of a variable/valuev, which passed as argument;map(f, c)- returns iterable collection, in which functionfapplied to each element of iterable collectionc;filter(f, c)- returns iterable collection, which contains those elements of iterable collectionc, for which value offisTrue;zip(c1,c2)- returns list of tuples with an item from each iterable collectionc1andc2, by iterating them in parallel;len(s)- return number of items in objects(either can be sequence, like string, or collection);max(c)- returns maximum value in iterable collectionc;max(arg1,arg2)- returns maximum value of elementsarg1andarg2(can be used with larger number of arguments);min()- have two ways of usage, just likemax(), however - finds minimum value;sum()- returns sum of elements into collection;pow(base, power)- returns numberbaseraised to powerpower;int(),float(),complex(),bool,list(),dict(),set(),str(),tuple(), etc - convert variable/value to the corresponding datatype.
Addition
For more detailed explanation and examples - dive into video:
Takk for tilbakemeldingene dine!