There are many ways to concatenate strings in Python. Here is a brief summary. It should be more comprehensive and convenient for future reference.
Plus connection
The first one, through the + sign:
>>> a, b ='hello', 'world'>>> a + b'hello world'
Comma connection
The second, through, comma form:
>>> a, b ='hello', 'world'>>> print(a, b)hello world
However, one thing to note when using the comma form is that it can only be used for print printing, and assignment operations will generate tuples:
>>> a, b('hello', 'world')
direct connection
The third type, whether there are spaces in the middle of the direct connection can be:
print('hello' 'world')print('hello''world')
%
The fourth is to use the% operator.
Before Python 2.6, the% operator was the only way to format strings, and it can also be used to concatenate strings.
print('%s %s'% ('hello','world'))
format
Fifth, use the format method.
The format method is a string formatting method that replaces the% operator in Python 2.6, and can also be used to concatenate strings.
print('{}{}'.format('hello', 'world')
join
Sixth, use the join built-in method.
String has a built-in method join whose parameter is a sequence type, such as an array or tuple.
print('-'.join(['aa','bb','cc']))
f-string
Seventh, use the f-string method.
In Python 3.6, Formatted String Literals (literal formatted strings), abbreviated as f-string, is introduced in Python 3.6. f-string is an evolutionary version of the% operator and the format method, using f-string to connect strings and using the% operator The format method is similar.
>>> aa, bb ='hello','world'>>> f'{aa} {bb}''hello world'
*
Eighth, use the * operator.
>>> aa ='hello'>>> aa * 3'hello hello hello '
summary
When concatenating a small number of strings
The + operator is recommended.
If you have high performance requirements and the python version is 3.6 or higher, f-string is recommended. For example, f-string is much more readable than the + sign in the following situations:
a = f'Name: {name} Age: {age} Gender: {gender}'b ='Name:' + name +'Age:' + age +'Gender:' + gender
When concatenating a large number of strings
It is recommended to use join and f-string methods. The choice still depends on the Python version you are using and your readability requirements.
A TPU Screen Protector made of the super toughness of the honeycomb structure. Its unique ultra-soft properties allow it to cover the most complex curves and contours in a device.
The self-healing design of the Hydrogel Screen Protector can protect the display screen of the device from damage, leave no air bubbles, and maintain the sensitivity of the touch screen. Advanced anti-fingerprint and dust- and oleophobic overlays keep your screen smudge- and dirt-free. This overlay is also important in providing maximum touch sensitivity for improved high-speed glide and optimal touch response.
The optical transparency of the Hydrogel Film is more than 90%, showing you the most original screen color and bringing the most realistic visual experience.
If you want to know more about the product information of the Hydrogel Screen Protector for iPhone, please click the product details to view the parameters, model, picture, price and other information of the iPhone Screen Protector.
Whether you are a group or an individual, we will do our best to provide you with accurate and comprehensive information about Hydrogel Screen Protectors!
Screen Protector For iPhone,Hydrogel Film for iPhone,Hydrogel Screen Protector For iPhone,TPU Screen Protector For iPhone,iPhone Screen Protector
Shenzhen Jianjiantong Technology Co., Ltd. , https://www.jjttpucuttingplotter.com