ํŒŒ์ด์ฌpython] ๋ฆฌ์ŠคํŠธ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๊ธฐ
ยท
Back-End/ํŒŒ์ด์ฌ
๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋ฆฌ์ŠคํŠธ์˜ ์š”์†Œ๋ฅผ ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•˜๊ณ , end=' '๋กœ ๊ณต๋ฐฑ์„ ๋„ฃ์–ด ์ถœ๋ ฅํ•ด์ค€๋‹ค. num = [1,0,0,1] for j in range(len(num)): print(num[j], end=' ') # 1 0 0 1 ๋ฐ˜๋ณต๋ฌธ์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ ์•ˆ๋˜๋Š”์ง€ ์ฐพ์•„๋ณด์•˜๋‹ค. ' '.join(list) ๋ฌธ์ž์—ด์ด ๋“ค์–ด์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋Š” ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์ˆซ์ž๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋Š” TypeError ๋ฐœ์ƒ ์ˆซ์žํ˜• ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค. ' '.join(num) # TypeError: sequence item 0: expected str instance, int found ' '.join(map(str,num) # 1 0 0 1 end='' sep='' print(num,end=',') # [1,0,0,1],..