Difference between revisions of "Python:Functions"

From wiki
Jump to navigation Jump to search
Line 32: Line 32:
 
main()
 
main()
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
;def function (*args,**kwargs):
 +
:Take any number of arguments and put them in the [[Python:DataTypes#Tuple|tuple]] args
 +
:Take any number of keyword arguments and put them in the [[Python:DataTypes#Dictionary_or_dict|dict]] kwargs

Revision as of 15:32, 9 December 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()
def function (*args,**kwargs)
Take any number of arguments and put them in the tuple args
Take any number of keyword arguments and put them in the dict kwargs