- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 123字
- 2021-07-02 14:00:20
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.'
推薦閱讀
- HornetQ Messaging Developer’s Guide
- Advanced Quantitative Finance with C++
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- 數據結構(Python語言描述)(第2版)
- Python 3網絡爬蟲實戰
- PHP 編程從入門到實踐
- 機械工程師Python編程:入門、實戰與進階
- Kinect for Windows SDK Programming Guide
- 小程序開發原理與實戰
- Android玩家必備
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(2)
- 機器學習微積分一本通(Python版)
- Instant Apache Camel Messaging System
- Hands-On Robotics Programming with C++