Format string formatted, must be one by one corresponding
' I am {}, age{},{} '. Format ('seven',',') print (TPL)
' I am {1}, age{2},{2} '. Format ('seven',',') print (TPL)
Take a tuple first
TPL = ' I am {0[0]} ', Format ([1,2,3],[123])
function definition methods in Python:
def Test (x): ' The function Definitions ' #注释函数 x+ =1 return X
def: A keyword that defines a function
Test: Name of function
(): Internal Medicine defined formal parameters
' Document description, not necessary, strongly recommended to add
X+=1: Generic code block or program processing logic
Return: Define the return value
Using functions
def Test (x): ' :p Aram X: Shaping numbers ' #注释函数 y=2*x+1 return = Test (3) print (a)
No return value, none returned
There is only one return value, which returns the value
Returns a tuple with multiple return values
Parameters of the function
parameters, which are useful only if the function is called
arguments, always present
Formal parameter, argument one by one corresponds
def text (x, y): res=x*y return= text (1,2) print ( Z)
Parameter Group * * Dictionary * list
def text (x,*y): print (x) print (y) c= text (1,2,3,4, 5)
Python format string formatting, mathematical meaning functions and functions in Python day14