您的位置:首页 > 编程语言 > Python开发

Python 5种连接字符串的方法

2017-12-20 19:48 274 查看

Python 5种连接字符串的方法

Talk is cheap, please show me the code.

print('python' 'best')                   #使用空格

print('python' + 'best')                 #使用+号

print('python', 'best')                  #使用,号 注意会有空格

str_list = ['python', 'best']            #使用空字符串join
str = ''
print(str.join(str_list))

str_list = ['python', 'best']            #使用空格join
str = ' '
print(str.join(str_list))

print('%s %s' %('python', 'best'))       #格式化输出 这个简直是凑数的=.=

#结果
pythonbest
pythonbest
python best
pythonbest
python best
python best
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: