Given a string, and we have to append more string (text) at the end of the string using += operator in Python.

给定一个字符串,我们必须在Python中使用+ =运算符在字符串的末尾附加更多字符串(文本)。

There are two methods to add string (text) at the end of the string:

有两种方法可以在字符串末尾添加字符串(文本):

  1. String.append() Method

    String.append()方法

  2. By using += operator

    通过使用+ =运算符

String.append() Method: Appends text at the end of the string. Read more: String.append() Method with Example

String.append()方法:在字符串末尾附加文本。 : 带示例的String.append()方法

Another way is to add text by using +=, this operator concatenates the text in the given string.

另一种方法是使用+ =添加文本,此运算符将给定字符串中的文本连接起来。

Example:

例:

Input:
str: 'New Delhi'
Concatenation of more text
str += ' ' #space
str += 'Chennai'
str += ' ' #space
str += 'Mumbai'
str += ' ' #space
str += 'Bangalore'
Output:
str: 'New Delhi Chennai Mumbai Bangalore'

Program:

程序:

# Python program to add strings
# to the string
str = 'New Delhi'
str += ' '    #adding space
str += 'Chennai'
str += ' '    #adding space
str += 'Mumbai'
str += ' '    #adding space
str += 'Banglore'
# print the string
print 'str:',str

Output

输出量

str: New Delhi Chennai Mumbai Banglore

翻译自: https://www.includehelp.com/python/appending-text-at-the-end-of-the-string-using-compound-assignment.aspx

Python | 使用+ =运算符在字符串末尾附加文本相关推荐

  1. Python rstrip()方法 删除 string 字符串末尾的指定字符(默认为空格).

    Python rstrip()方法  Python 字符串 描述 Python rstrip() 删除 string 字符串末尾的指定字符(默认为空格). 语法 rstrip()方法语法: str.r ...

  2. python转义符个数,python(五)——运算符、字符串、转义字符

    目录 运算符 位运算符: 逻辑与运算符 成员运算符   in  和 not in 身份运算符  is 和 is not 运算符优先级 字符串 python中字符串可以进行乘法运算 访问字符串中某一个字 ...

  3. 查找字符串末尾含关键字_Excel教程:用find函数带关键字提取杂乱文本

    教程领到手,学习不用愁!领↑↑↑ 还有朋友不知道知识兔吗?知识兔就是学习资源的网站,建议去搜索引擎搜索知识兔!知识兔是课程网站吗?知识兔有什么课程?知识兔领取下载兔费课程.知识兔上有大量各类视频教程课 ...

  4. python重载运算符乘法_Python | 使用乘法运算符创建一个字符串的多个副本

    python重载运算符乘法 Given a string and we have to create its multiple copies by using multiplication opera ...

  5. python使用加号运算符可以连接两个字符串_如何在Python连接两个字符串

    如何在Python连接两个字符串 Python字符串是Unicode字符的集合. Python提供了许多内置函数来进行字符串操作.字符串串联是一个字符串与另一字符串合并时的过程.可以通过以下方式完成. ...

  6. python字符串转化为long_Java带有运算符的字符串转换为Long型

    由于项目需要在配置文件中配置一个刷新时间,但是配置文件中取出来来的数据肯定是字符串,然后要将该带有运算符的字符串转换为Long型.具体代码如下: 配置文件中: reflash_time = (2*60 ...

  7. 【python cookbook】【字符串与文本】5.查找和替换文本

    问题:对字符串中的文本做查找和替换 解决方案: 1.对于简单模式:str.replace(old, new[, max]) 2.复杂模式:使用re模块中的re.sub(匹配的模式, newstring ...

  8. python 把txt变成字符串_如何通过 Python 如何写文件 ?

    大家好,我是室长~ 今天给大家讲讲如何通过 Python 来写文件.在日常开发中,将数据写入到文件中存储起来非常常见,废话不多说,开干! 一.开始 上一节 <Python 如何读取 txt 文件 ...

  9. python按位置从字符串提取子串的操作是_Python基础-字符串操作和“容器”的操作...

    星火:Python基础-IF和循环​zhuanlan.zhihu.com星火:Python基础-函数​zhuanlan.zhihu.com星火:Python基础-模块​zhuanlan.zhihu.c ...

最新文章

  1. 分支定界法上下界_分支定界(Branch-and-Cut)方法的逻辑
  2. linux下设置定时任务,linux下定时任务设置
  3. 系统架构师 项目经理 哪个更有前景_中央空调加地暖与五恒系统,哪个更省钱?...
  4. 面试官问你什么是Hash表
  5. 上海卓道医疗完成千万级Pre-A轮融资,幂方资本领投...
  6. 做了那么多营销,为什么没有效果?
  7. c#绝对值函数图像_图像处理评价指标之模糊度、清晰度(待更新)
  8. 关于WAP技术的介绍
  9. Windows文件传输小工具,网络传输文件,内网传输
  10. 《2020年中国互联网网络安全报告》:90%的小程序存在安全隐患
  11. 安卓各版本大变化(Android 6.0到10.0),兼容适配
  12. wath修改data中的值后更新
  13. Zeloof 自制芯片工艺
  14. java web atm机_Java项目实现模拟ATM机
  15. 人工学习之预测2023年考研英语答案分布
  16. 相对基址加变址寻址方式与其它寻址方式之间的变形关系
  17. 【LeetCode之栈和队列】:关于栈和队列经典的OJ题(用C语言实现,附图详解)
  18. uview Checkbox 复选框每一项增加删除功能
  19. C语言基础题-水仙花数
  20. python中tuple、list以及array(numpy的数据格式)的相互转换

热门文章

  1. 什么是机器人的五点校正法_机器人校正方法
  2. Oracle闪回报错,oracle 闪回区满了,ORA-19815
  3. python爬虫高级知识点_Python爬虫知识点梳理总结,殿堂级小白入门必读
  4. dev 中 gridcontrol1 滚动条重绘_浏览器的重绘和回流(Repaint amp; Reflow)
  5. 2021 最新 IDEA集成Gitee、Gitee迁移GitHub【图文讲解】
  6. Latex 插入目录 设置首页页码为空
  7. 认识VLAN,并学会VLAN的划分和网络配置实例
  8. 五阿哥钢铁电商平台Docker容器云平台建设实践——你想知道的都在这里!
  9. 我们正在经历一个应用疲惫时代?
  10. java api项目配置统一的错误返回json提示