Skip to content

Latest commit

ย 

History

History
47 lines (35 loc) ยท 1.66 KB

README.md

File metadata and controls

47 lines (35 loc) ยท 1.66 KB

3.9. ๋ฌธ์ž์—ด(Strings) ํ™œ์šฉ

๋ฌธ์ž์—ด์€ ํŒŒ์ด์ฌ์—์„œ ๊ฐ€์žฅ ์ธ๊ธฐ์žˆ๋Š” ์ž๋ฃŒํ˜•์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž๋ฅผ "" (์Œ๋”ฐ์˜ดํ‘œ), ''(์ž‘์€๋”ฐ์˜ดํ‘œ) ๋กœ ๋ฌถ์–ด ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Œ๋”ฐ์˜ดํ‘œ์™€ ์ž‘์€๋”ฐ์˜ดํ‘œ๋ฅผ ํ˜ผ์šฉํ•  ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค. ํฐ๋”ฐ์˜ดํ‘œ ์•ˆ์— ์ž‘์€๋”ฐ์˜ดํ‘œ๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๊ณ , ๋ฐ˜๋Œ€๋กœ ์ž‘์€๋”ฐ์˜ดํ‘œ ์•ˆ์— ํฐ๋”ฐ์˜ดํ‘œ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

var1 = 'Hello World!'
var2 = "It's a good thing"

๋ฌธ์ž์—ด ๋ถ€๋ถ„์ง‘ํ•ฉ์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด ๋Œ€๊ด„ํ˜ธ์™€ ๋ฌธ์ž์—ด ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ๋ถ€๋ถ„์„ ๊ฐ€์ ธ์˜ค๋ฉด ๋ฉ๋‹ˆ๋‹ค.

var1 = 'Hello World!'
var2 = "Python Programming"
print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]
#์ถœ๋ ฅ๋œ ๊ฒฐ๊ณผ
var1[0]:  H
var2[1:5]:  ytho

๋ณ€์ˆ˜๋ฅผ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์— ํ• ๋‹นํ•˜์—ฌ ๊ธฐ์กด ๋ฌธ์ž์—ด์„ "์—…๋ฐ์ดํŠธ"ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ ๊ฐ’์€ ์ด์ „ ๊ฐ’ ๋˜๋Š” ์™„์ „ํžˆ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด๊ณผ ๊ด€๋ จ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด

var1 = 'Hello World!'
print "Updated String :- ", var1[:6] + 'Python'
#์ถœ๋ ฅ๋œ ๊ฒฐ๊ณผ
Updated String :-  Hello Python

์—ฌ๋Ÿฌ ์ค„์˜ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•  ๋•Œ๋Š” """ ํฐ๋”ฐ์˜ดํ‘œ 3๊ฐœ๋‚˜, ''' ์ž‘์€๋”ฐ์˜ดํ‘œ 3๊ฐœ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. \n ์œผ๋กœ ํ‘œ์‹œ๋˜๋Š” ๋ถ€๋ถ„์ด newline๋ฌธ์ž๋กœ ์—ด์„ ๋ฐ”๊ฟ”์ฃผ๋Š” ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž์ž…๋‹ˆ๋‹ค.

para_str = """this is a long string that is made up of
several lines and non-printable characters such as
TAB ( \t ) and they will show up that way when displayed.
NEWLINEs within the string, whether explicitly given like
this within the brackets [ \n ], or just a NEWLINE within
the variable assignment will also show up.
"""
print para_str