python连接字符串的方法小结

yipeiwu_com6年前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的文件类型和字符串详解

基于Python的文件类型和字符串详解

1. Python的文件类型 1. 源代码--直接由Python解析 vi 1.py #!/usr/bin/python print 'hello world' 这里的1.py...

python定时检查启动某个exe程序适合检测exe是否挂了

详见代码如下: 复制代码 代码如下: import threading import time import os import subprocess def get_process_c...

Python Requests安装与简单运用

requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: python的标...

python为tornado添加recaptcha验证码功能

复制代码 代码如下:    from urllib.request import urlopen    from urllib...

python实现log日志的示例代码

源代码: # coding=utf-8 import logging import os import time LEVELS={'debug':logging.DEBUG,\...