- 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.'
推薦閱讀
- Mastering OpenCV Android Application Programming
- Power Up Your PowToon Studio Project
- C語言程序設計實踐教程
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- 用戶體驗增長:數字化·智能化·綠色化
- Android開發案例教程與項目實戰(在線實驗+在線自測)
- Learning R for Geospatial Analysis
- Kotlin開發教程(全2冊)
- Python網絡爬蟲技術與應用
- Windows Phone 8 Game Development
- Unity 5.X從入門到精通
- Spark技術內幕:深入解析Spark內核架構設計與實現原理
- Visual Basic語言程序設計上機指導與練習(第3版)
- Swift 2 Blueprints
- PHP程序設計經典300例