python3----連接字符串數組(join)


join 方法用於連接字符串數組

1 s = ['a', 'b', 'c', 'd']
2 print(''.join(s))
3 print('-'.join(s))
4 
5 results:
6 
7 abcd
8 a-b-c-d

 

使用 % 連接多個變量

1 a = 'hello'
2 b = 'python'
3 c = 1
4 print('%s %s %s %s' % (a, b, c, s))
5 
6 results:
7 
8 hello python 1 ['a', 'b', 'c', 'd']

 


免責聲明!

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



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