官术网_书友最值得收藏!

Concatenation (+) and repetition (*)

Next, comes concatenation and repetition. Refer to the following code:

>>> 3 * 'hi' + 'hello'
'hihihihello'

In the preceding example, we are doing string concatenation and repetition. 3 * 'hi' means hi gets printed 3 times and, using the + sign, we are joining the hello string next to hi.

We can automatically concatenate two strings just by writing them next to each other. These two strings must be enclosed between quotes, as shown here:

>>> 'he' 'llo'
'hello'

This feature is really helpful when you have long strings and you want to break them. Here is an example:

>>> str = ('Several strings'
... 'joining them together.')
>>> str
'Several strings joining them together.'
主站蜘蛛池模板: 中山市| 克什克腾旗| 闻喜县| 思南县| 海淀区| 莲花县| 宁远县| 井陉县| 扎兰屯市| 河源市| 普格县| 崇州市| 长兴县| 凉城县| 凤山市| 潮安县| 二连浩特市| 三门县| 景谷| 枝江市| 阿克| 横峰县| 吐鲁番市| 崇左市| 太原市| 东明县| 浪卡子县| 凤庆县| 陕西省| 称多县| 拉孜县| 中西区| 宁安市| 汶上县| 廉江市| 墨脱县| 盐亭县| 清原| 伊春市| 临城县| 阳曲县|