Make up: The first 19 study notes string concatenation

String concatenation

ins = "i an% s, is old% s"% ( "test", [1,2,3]) #% s can take any value,% d only incoming digital 
Print (INS)

INS = "I S% AN,% D iS Old "% (" Test ", 18 is)
Print (INS)

TP1 =" Percent% .2f "float% 99.67890 # foregoing f 2 is 2 decimal places the result: 99.68
Print ( TP1)

TP1 = "Percent% .2s" float% 99.67890 # foregoing s 2 represents several retention results: 99. Most functions using truncated string
Print (TP1)

TP1 = "Percent% .2f %%" #% 99.67890% of the float, the output method: 2 %%
Print (TP1)

INS = "% AN I (name) s, is old% (age) d "% {" name ":" test "," age ": 18} # can be specified by value, applied between the key value and% s,% between plus and the value d value,
Print (INS)

String Format: Percent format
1. Percent
ins = "i an% -20s, is old% d"% ( "test", 18) # 20 represents a left-aligned position 
Print (INS)

# "-" represents: Left
# "+" means: right justified

1.format

tp1 = "i am {}, age {}, {}". format ( "test", 18, "teat1") # correspondence value tuple
Print (TP1)

TP1 = "I AM {2}, age {1}, {0} ". format (" test ", 18," teat1 ") # index value may tuple
Print (TP1)

TP1 =" I AM. 1 {}, Age {}. 1, {0} ". format (" test ", 18," teat1 ") # values can
Print (TP1)

TP1 =" I AM {name}, Age Age {}, {} Age. "the format (name =" Test ", age = 18) # possible values, Dictionary
print (tp1)

Guess you like

Origin www.cnblogs.com/jianchixuexu/p/11518865.html