字符串的拼接python


數字可以強制轉換為字符串,但是字符串不能強制轉換為數字(會報錯)

a='abcs'

b='dsys'

方法一、a+b 最low的一個方法,因為每+一次內存重新開辟一塊空間

方法二、print '%s%s'%(a,b)

方法三、''.join([a,b])

方法四、'this is {0}{1}'.format('apple','bana')

print 'my name is {fruit},hehe,{apple}'.format(fruit='apple',apple='nihao')

print 'this is %(whose)s %(fruit)s'%{'whose':'my','fruit':'apple'}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM