์ƒˆ์†Œ์‹

๐ŸŽ/Python

[Python] join ํ•จ์ˆ˜

  • -

๋ฆฌ์ŠคํŠธ โ‡’ ๋ฌธ์ž์—ด

๋งค๊ฐœ๋ณ€์ˆ˜ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ์š”์†Œ๋ฅผ ํ•ฉ์ณ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜

 

''.join(๋ฆฌ์ŠคํŠธ)

๋ฆฌ์ŠคํŠธ ์š”์†Œ๋“ค์„ ํ•ฉ์ณ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

*๊ตฌ๋ถ„์ž๊ฐ€ ๊ณต๋ฐฑ์ธ ํ˜•ํƒœ

#์›๋ณธ ๋ฆฌ์ŠคํŠธ list = ['I', 'will', 'dive', 'into', 'you'] result = ''.join(list) print(result)
#์ถœ๋ ฅ Iwilldiveintoyou

 

'๊ตฌ๋ถ„์ž'.join(๋ฆฌ์ŠคํŠธ)

๋ฆฌ์ŠคํŠธ ์š”์†Œ๋“ค ์‚ฌ์ด์— ๊ตฌ๋ถ„์ž๋ฅผ ๋„ฃ์–ด์„œ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

#์›๋ณธ ๋ฆฌ์ŠคํŠธ list = ['I', 'will', 'dive', 'into', 'you'] result1 = ' '.join(list) print(result1) result2 = '_'.join(list) print(result2) result3 = '.\n'.join(list) print(result3)
#์ถœ๋ ฅ #result1 I will dive into you #result2 I_will_dive_into_you #result3 I. will. dive. into. you.

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ ๋ณต์‚ฌ ์™„๋ฃŒ! ๐ŸŒˆ

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐโค๏ธโ€๐Ÿ”ฅ๋ถ€ํƒ ๋“œ๋ ค์š” (โˆ—โ›โŒ„โ›โˆ—)