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

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.'
主站蜘蛛池模板: 芒康县| 宁蒗| 鹤壁市| 南漳县| 厦门市| 阳原县| 通州区| 扶绥县| 大田县| 来宾市| 达拉特旗| 天祝| 开封市| 锡林浩特市| 海宁市| 轮台县| 佛冈县| 黎城县| 黎川县| 甘肃省| 永康市| 宝山区| 栾城县| 吉安市| 年辖:市辖区| 铁力市| 杭锦旗| 鹤岗市| 汤阴县| 农安县| 盐山县| 乾安县| 区。| 和静县| 潞西市| 东辽县| 夏河县| 宜丰县| 富平县| 万宁市| 介休市|