python连接字符串的方法小结

yipeiwu_com7年前Python基础

本文实例讲述了python连接字符串的方法。分享给大家供大家参考。具体如下:

方法1:直接通过加号操作符相加

复制代码 代码如下:
foobar = 'foo' + 'bar'

方法2:join方法
复制代码 代码如下:
list_of_strings = ['abc', 'def', 'ghi']
foobar = ''.join(list_of_strings)

方法3:替换
复制代码 代码如下:
foobar = '%s, %s' % ('abc', 'def')

希望本文所述对大家的python程序设计有所帮助。

相关文章

python使用内存zipfile对象在内存中打包文件示例

复制代码 代码如下:import zipfileimport StringIO class InMemoryZip(object):    def __in...

python中的线程threading.Thread()使用详解

python中的线程threading.Thread()使用详解

1. 线程的概念: 线程,有时被称为轻量级进程(Lightweight Process,LWP),是程序执行流的最小单元。一个标准的线程由线程ID,当前指令指针(PC),寄存器集合和堆栈...

python获取txt文件词向量过程详解

在读取https://github.com/Embedding/Chinese-Word-Vectors中的中文词向量时,选择了一个有3G多的txt文件,之前在做词向量时用的是word2...

python使用scrapy解析js示例

复制代码 代码如下:from selenium import selenium class MySpider(CrawlSpider):    name =...

Python对数据库操作

Windows下安装MySQL-python 下载地址:https://pypi.python.org/pypi/MySQL-python/1.2.5 安装到系统即可。 linux下...