t= "I am {},age {}, {}", Format ("Seven", "Wang")
Must one by one correspond otherwise error
Need to wear a dictionary * *
t = "I am {name},age {age}, really{name}", Format (**{"name": "Seven", "Age": 18})
Print (t)
Results: I am seven,age 18,reallyseven
Send List
t= "I am {: s},age{:d}", Format (*["Seven", 18])
Binary, octal, integer, hexadecimal, hexadecimal uppercase, displayed as a percentage (six digits after the decimal point by default)
tp1= "number:{:b},{:o},{:d},{:x},{:x},{:%}", Format (15,15,15,15,15.87623,2)
Results: number:1111,17,15,f,f,1587.621450%
Function:
The definition of functions in Python: functions are a programmatic way of logically structuring and procedural.
def test (x): #x为形参, def keyword test is a function name
Second line write comment
Write n line code behind
return x #返回一个结果
Benefits of using Functions:
1. Code Reuse
2. Maintain consistency to maintain
3. Expandable
Procedure: A function that can be understood as having no return value.
If the return value is 0, that is, no return returns none
The return value is 1: Returns an object
return value >1, return tuple cylinder template
Parameters of the function: Def calc (x, y):
Res=x**y
return res
C=calc (A, B)
The first line, X, Y, is the parameter, and only the memory unit is allocated when called, and the allocated memory unit is freed immediately at the end of the call.
Python Learning Notes