 Functions
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/value- v, which passed as argument;
- map(f, c)- returns iterable collection, in which function- fapplied to each element of iterable collection- c;
- filter(f, c)- returns iterable collection, which contains those elements of iterable collection- c, for which value of- fis- True;
- zip(c1,c2)- returns list of tuples with an item from each iterable collection- c1and- c2, by iterating them in parallel;
- len(s)- return number of items in object- s(either can be sequence, like string, or collection);
- max(c)- returns maximum value in iterable collection- c;
- max(arg1,arg2)- returns maximum value of elements- arg1and- arg2(can be used with larger number of arguments);
- min()- have two ways of usage, just like- max(), however - finds minimum value;
- sum()- returns sum of elements into collection;
- pow(base, power)- returns number- baseraised to power- power;
- 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:
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Kysy minulta kysymyksiä tästä aiheesta
Tiivistä tämä luku
Näytä käytännön esimerkkejä
Awesome!
Completion rate improved to 7.14 Functions
Functions
Pyyhkäise näyttääksesi valikon
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/value- v, which passed as argument;
- map(f, c)- returns iterable collection, in which function- fapplied to each element of iterable collection- c;
- filter(f, c)- returns iterable collection, which contains those elements of iterable collection- c, for which value of- fis- True;
- zip(c1,c2)- returns list of tuples with an item from each iterable collection- c1and- c2, by iterating them in parallel;
- len(s)- return number of items in object- s(either can be sequence, like string, or collection);
- max(c)- returns maximum value in iterable collection- c;
- max(arg1,arg2)- returns maximum value of elements- arg1and- arg2(can be used with larger number of arguments);
- min()- have two ways of usage, just like- max(), however - finds minimum value;
- sum()- returns sum of elements into collection;
- pow(base, power)- returns number- baseraised to power- power;
- 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:
Kiitos palautteestasi!