- Python Programming with Raspberry Pi
- Sai Yamanoor Srihari Yamanoor
- 142字
- 2021-07-02 23:48:44
Concatenating strings
In the preceding example, we printed the user inputs in combination with another string. For example, we took the user input name and printed the sentence as My name is Sai. The process of appending one string to another is called concatenation.
In Python, strings can be concatenated by adding + between two strings:
name = input("What is your name? ")
print("My name is " + name)
It is possible to concatenate two strings, but it is not possible to concatenate an integer. Let's consider the following example:
id = 5
print("My id is " + id)
It would throw an error implying that integers and strings cannot be combined:

An exception
It is possible to convert an integer to string and concatenate it to another string:
print("My id is " + str(id))
This would give the following result:

推薦閱讀
- 電氣自動化專業英語(第3版)
- 大學計算機基礎:基礎理論篇
- 空間機器人遙操作系統及控制
- Apache Hive Essentials
- Hands-On Linux for Architects
- Photoshop CS3圖像處理融會貫通
- Implementing Oracle API Platform Cloud Service
- Cloudera Administration Handbook
- 數據掘金
- 步步圖解自動化綜合技能
- 在實戰中成長:C++開發之路
- Learning Linux Shell Scripting
- 強化學習
- Dreamweaver+Photoshop+Flash+Fireworks網站建設與網頁設計完全實用
- 筆記本電腦使用與維護