Programming

Python print() function ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

๐Ÿง Yon 2023. 11. 11. 17:49
๋ฐ˜์‘ํ˜•

์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ„๋‹จํ•œ "hello, world" String์„ ์ถœ๋ ฅํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” print() function์€ ์–ด๋–ค ๊ตฌ์กฐ๋กœ ์ž‘์„ฑ๋˜์–ด ์žˆ์„๊นŒ?

print("Hello, World!")
print("This is my first python code")

# ์ถœ๋ ฅ ๊ฒฐ๊ณผ

Hello, World!
This is my first python code

Print() Function์˜ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 print(*objects, sep=' ', end='\n', file=None, flush=False)¶

print() ๋‚ด์—๋Š” ์œ„์™€ ๊ฐ™์€ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ default ๊ฐ’์œผ๋กœ ๋‚ด์žฅ๋˜์–ด ์žˆ๋Š”๋ฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค๋ช…๋˜์–ด ์žˆ๋‹ค.
"Print objects to the text stream file, separated by sep and followed by end. sep, end, file, and flush, if present, must be given as keyword arguments."

์ฆ‰,
(1) print ๋ฌธ ๋‚ด์— ์‚ฝ์ž…๋˜๋Š” ๋ชจ๋“  objects(*objects) ๋ฅผ Text ์ŠคํŠธ๋ฆผ ํŒŒ์ผ๋กœ ์ถœ๋ ฅํ•˜๋Š”๋ฐ
(2) sep=' ' ํŒŒ๋ผ๋ฏธํ„ฐ์— ์˜ํ•ด ๊ฐ object ์‚ฌ์ด์— ๊ณต๋ฐฑ์„ ์‚ฝ์ž…ํ•˜์—ฌ ๊ตฌ๋ถ„ํ•˜๊ณ 
(3) end='\n' ํŒŒ๋ผ๋ฏธํ„ฐ์— ์˜ํ•ด ๊ฐ print() function ์˜ ๋์—๋Š” ์ค„๋ฐ”๊ฟˆ์„ ํ•œ๋‹ค

๋”ฐ๋ผ์„œ, 2์ค„์˜ print ๋ฌธ์„ ์ž‘์„ฑํ•˜๋”๋ผ๋„, end ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์„ ๊ฐ•์ œ๋กœ ์ œ๊ฑฐํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•˜๋ฉด ๊ธฐ๋ณธ print() ๋™์ž‘์˜ ๊ฒฐ๊ณผ๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค.

print("Hello, World! ", end="")
print("This is my first python code")

# ์ถœ๋ ฅ ๊ฒฐ๊ณผ

Hello, World! This is my first python code

 

 

Reference: https://docs.python.org/3/library/functions.html#print

๋ฐ˜์‘ํ˜•