๐ŸŒCoding/๐ŸŒŸPython3

[Python] list, tuple -> String

๋ฟŒ์•ผ._. 2021. 9. 1. 13:23

๐Ÿ‘‡์—ฌ๊ธฐ์„œ๋„๐Ÿ‘‡ ํ•œ๋ฒˆ ๊ธฐ๋กํ–ˆ๋˜ ์ ์ด ์žˆ์—ˆ์ง€๋งŒ, ์ข…์ข… ๊นŒ๋จน๊ธฐ์— ๋‹ค์‹œ ์ž‘์„ฑํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค 

 

https://melody-coding.tistory.com/46

 

[Python] list

Python3์˜ list์— ๊ด€ํ•ด ๋„์ ๋„์ โœ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 1) list  โ‘  list ์„ ์–ธx=[] #list ์„ ์–ธ ๋ฆฌ์ŠคํŠธ ์„ ์–ธ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์•„์ฃผ ๊ฐ„๋‹จ!! x=[i for i in range(5)] #[0, 1, 2, 3, 4]  ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ•

melody-coding.tistory.com

 

tuple์—์„œ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊ฟ”์•ผ ํ•  ์ผ์ด ์ƒ๊ฒผ๋‹ค

list์—์„œ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ๋˜ ๊ฒƒ๊ณผ ๋˜‘๊ฐ™์ด ํ•˜๋ฉด ๋˜๋Š” ๊ฒƒ ์•„๋‹Œ๊ฐ€?

 

๐Ÿ˜‰ list, tuple -> ๋ฌธ์ž์—ด

temp=['a','b','c'] #list
temp=('a','b','c') #tuple

print(''.join(temp)) #๊ฒฐ๊ณผ) abc

 

์œ„์™€ ๊ฐ™์ด join์„ ์‚ฌ์šฉํ•˜์˜€์ง€๋งŒ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. 

 

๋‚œ ์ €๋ฒˆ์˜ ์‹ค์ˆ˜๋ฅผ ๋˜‘๊ฐ™์ด ํ•˜์˜€๊ณ  ๋˜ ๊ฒ€์ƒ‰์˜ ๊ธธ๋กœ ๋น ์ ธ๋“ค์—ˆ๋‹ค.

์ด์œ ๋Š” ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ tuple์˜ ๊ฐ’์ด intํ˜•์ด์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด์—ˆ๋‹ค.

 

 

๐Ÿ˜‰ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•)

temp=(1,2,3)

print(' '.join(map(str,temp))) # 1 2 3

map์„ ํ™œ์šฉํ•˜์—ฌ str๋กœ ๋ฐ”๊ฟ”์ค€ ํ›„ join์„ ํ•ด์ค€๋‹ค.

'๐ŸŒCoding > ๐ŸŒŸPython3' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Python] ์•„์Šคํ‚ค์ฝ”๋“œ  (0) 2021.10.20
[Python] ์†Œ์ˆ˜์  ์ž๋ฆฌ ์ˆ˜ ์ถœ๋ ฅ  (0) 2021.10.04
[Python] heapq  (0) 2021.08.20
[Python] lambda  (0) 2021.07.29
[Python] ์ˆœ์—ด, ์กฐํ•ฉ  (0) 2021.05.16