- 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:

推薦閱讀
- 數(shù)據(jù)運(yùn)營(yíng)之路:掘金數(shù)據(jù)化時(shí)代
- 數(shù)據(jù)挖掘?qū)嵱冒咐治?/a>
- Apache Spark Deep Learning Cookbook
- 統(tǒng)計(jì)學(xué)習(xí)理論與方法:R語(yǔ)言版
- Docker High Performance(Second Edition)
- JavaScript典型應(yīng)用與最佳實(shí)踐
- 網(wǎng)絡(luò)安全管理實(shí)踐
- 中國(guó)戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·智能制造裝備
- 電腦上網(wǎng)輕松入門
- R Machine Learning Projects
- Machine Learning Algorithms(Second Edition)
- 人工智能:智能人機(jī)交互
- Learning Cassandra for Administrators
- 樂(lè)高創(chuàng)意機(jī)器人教程(中級(jí) 上冊(cè) 10~16歲) (青少年iCAN+創(chuàng)新創(chuàng)意實(shí)踐指導(dǎo)叢書)
- Hands-On Microservices with C#