Difference between revisions of "Python:Functions"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
[[category:Python]] | [[category:Python]] | ||
+ | =Build in function= | ||
+ | |||
List of all build in functions [https://docs.python.org/3/library/functions.html] | List of all build in functions [https://docs.python.org/3/library/functions.html] | ||
Line 13: | Line 15: | ||
;input([prompt]) | ;input([prompt]) | ||
:Read and return input from standard input. Display 'prompt' first when provided. | :Read and return input from standard input. Display 'prompt' first when provided. | ||
+ | |||
+ | =Self defined functions= | ||
+ | |||
+ | Argument are positional but can be passed by keyword too. | ||
+ | |||
+ | <syntaxhighlight lang='python'> | ||
+ | def main(): | ||
+ | function(par1,par2) | ||
+ | function(par2 = <value>, par1 = <value>) | ||
+ | return | ||
+ | |||
+ | def function (par1, par2 = <defaultvalue>): | ||
+ | codeblock | ||
+ | return | ||
+ | |||
+ | main() | ||
+ | </syntaxhighlight> |
Revision as of 22:22, 11 September 2018
Build in function
List of all build in functions [1]
- len(obj1)
- Return the number of elements in obj1 (string, list, tuple, set)
- max(obj1)
- Return the largest item in obj1
- min(obj1)
Return the smallest item in obj1
- input([prompt])
- Read and return input from standard input. Display 'prompt' first when provided.
Self defined functions
Argument are positional but can be passed by keyword too.
def main():
function(par1,par2)
function(par2 = <value>, par1 = <value>)
return
def function (par1, par2 = <defaultvalue>):
codeblock
return
main()