Python string stitching way to understand

Python string stitching

In the actual development of Python, many need to use string splicing, there are a lot of string splicing in Python, sum up today:

Splicing with + symbol

Stitch with % symbol

Stitching with join()

Splicing with the format() method

Use the Template object in the string module

example:

Fruit1 = 'apples'
Fruit2 = 'bananas'
Fruit3 = 'pears'

Claim:
Output string 'There are apples, bananas, pears on the table'

Splicing with + symbol

Use + to splic the string as follows:

str = 'There are' + fruit1 + ',' + fruit2 + ',' + fruit3 + 'on the table'

This method is relatively inefficient and is not recommended.

Stitch with % symbol

The method of splicing with % symbol is as follows:

Str = 'There are %s, %s, %s on the table.' % (fruit1,fruit2,fruit3)

In addition to the tuple method, you can also use the dictionary as follows:

str = 'There are% (fruit1 ) s,% (fruit2) s,% (fruit3) s on the table'% { 'fruit1': fruit1, 'fruit2': fruit2, 'fruit3': fruit3} This method is relatively common Stitching with join()

Join()` method is stitched as follows

temp = [ 'There are', fruit1, ',', fruit2, ',', fruit3, 'on the table'] ''. join (temp)

This method uses sequence operations

Splicing with the format() method

Use the format() method to splicing as follows:

Str = 'There are {}, {}, {} on the table' str .format(fruit1,fruit2,fruit3)

You can also specify the location of the parameter:

Str = 'There are {2}, {1}, {0} on the table' str .format(fruit1,fruit2,fruit3) # fruit1 appears at 0

Similarly, you can also use a dictionary:

Str = 'There are {fruit1}, {fruit2}, {fruit3} on the table' str .format(fruit1=fruit1,fruit2=fruit2,fruit3=fruit3) Using the Template object in the string module

Use the Template object in the string module as follows:

from string import Template str = Template ( 'There are $ {fruit1}, $ {fruit2}, $ {fruit3} on the table') # {} is used herein, no mistake, oh str.subsTItute (fruit1 = Fruit1,fruit2=fruit2,fruit3=fruit3) #If parameters are missing, or if you use the safe_subsTItute() method, it will not str.safe_subsTItute(fruit1=fruit1,fruit2=fruit2) #output'There are apples, bananas, ${fruit3} On the table'

to sum up

There are many ways to splicing. Different methods are used in different occasions. Individuals recommend % and format() methods, which are simple and convenient.

Maskking Vape

The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.

maskking vape,maskking vape price,maskking vape review,maskking vape shop,,maskking vape cost,maskking vape disposable,maskking vape informacion

Suizhou simi intelligent technology development co., LTD , https://www.msmsmart.com

Posted on