โถ ๋ฌธ์์ด ๊ฐ๋
- ๋ฌธ์์ด์ '' , "" ์ผ๋ก ๋ฌถ์ด์ ํํํจ ⇒ print()๋ฅผ ํ๋ฉด ์์๋ฐ์ดํ('')๋ก ํ์๋๋ค.
- ๋ฆฌ์คํธ๋ ๋๊ดํธ [] ↔ ๋ฌธ์์ด์ ์์๋ฐ์ดํ '' ์ถ๋ ฅ๋จ
-
- ๊ธฐํธ๋ ๋ฌธ์์ด์ฐ๊ฒฐ
-
- ๋ ๋ฌธ์์ด ๋ฐ๋ณต
aa=[1,2,3]
ss="ํ์ด์ฌ๊ฟ์ผ"
aa[0] #1
aa[1:3] #[2,3]
ss[0] #'ํ'
ss[1:3] #'์ด์ฌ'
#๋ฌธ์์ด ๋ง์
ss = 'ํ์ด์ฌ' + '์ต๊ณ ' #'ํ์ด์ฌ์ต๊ณ '
#๋ฌธ์์ด ๊ณฑ์
ss = 'ํ์ด์ฌ' * 3 #'ํ์ด์ฌํ์ด์ฌํ์ด์ฌ'
[SELF STUDY 8-1]
ss = 'ํ์ด์ฌ์์์ ์ฌ๋ฏธ์์ด์'
sslen = len(ss)
for i in range(0,sslen) :
if i % 2 == 0 :
print(ss[i],end='')
else :
print('#',end='')
#end = '' ๋ ์ค ๋ฐ๋๋๊ฑฐ ๋ฐฉ์งํด์ฃผ๋ ๊ฒ
[ํ๋ก๊ทธ๋จ 1]
## ๋ณ์ ์ ์ธ ๋ถ๋ถ ##
inStr, outStr = "", ""
count, i = 0, 0
## ๋ฉ์ธ ์ฝ๋ ๋ถ๋ถ ##
inStr = input("๋ฌธ์์ด์ ์
๋ ฅํ์ธ์ : ")
count = len(inStr)
for i in range(0, count) :
outStr += inStr[count - (i + 1)]
print("๋ด์ฉ์ ๊ฑฐ๊พธ๋ก ์ถ๋ ฅ --> %s" % outStr)
โถ ๋ฌธ์์ด ํจ์
- len() ํจ์ : ๋ฆฌ์คํธ or ๋ฌธ์์ด ๊ฐ์ ์
- ๋ฌธ์์ดํจ์ (๋์๋ฌธ์๋ณํ) : upper(),lower(),swapcase(),title()
- (๋ฌธ์์ด์ฐพ๊ธฐ) : count(), find() rfind() ๋ฑ๋ฑ...
- (๋ฌธ์์ด ๊ณต๋ฐฑ,์ญ์ ,๋ณ๊ฒฝ) strip(), rstrip() ๋ฑ๋ฑ...
- # 8-4 ์์ฉ ( ๋ฌธ์์ด ๊ณ์ ๋ฐ๊ธฐ ) while (1) : inStr=input(str()) outStr= "" for i in range (0,len(inStr)) : if inStr[i] != ' ': outStr += inStr[i] print("์๋ ๋ฌธ์์ด ===>" + '['+inStr+']') print("๊ณต๋ฐฑ ์ญ์ ๋ฌธ์์ด ==> " + '['+outStr+']') if inStr == 'Q' : break;
[SELF STUDY 8-2]
#[SELF STUDY 8-2]
while (1) :
inStr=input(str())
outStr= ""
for i in range (0,len(inStr)) :
if inStr[i] != "<" and inStr[i] !=">":
outStr += inStr[i]
print("์๋ ๋ฌธ์์ด ===>" + '['+inStr+']')
print("๊ณต๋ฐฑ ์ญ์ ๋ฌธ์์ด ==> " + '['+outStr+']')
if inStr == 'Q' :
break;
[SELF STUDY 8-3]
#[SELF STUDY 8-3]
ss = input(str("๋ฌธ์์ด ์
๋ ฅ :"))
if ss.isalpha() == True:
print("๊ธ์์
๋๋ค")
elif ss.isdigit() == True :
print("์ซ์์
๋๋ค.")
elif ss.isalnum() == True :
print("๊ธ์+์ซ์์
๋๋ค")
else :
print("๋ชจ๋ฅด๊ฒ ์ต๋๋ค.")
[ํ๋ก๊ทธ๋จ 2]
import turtle
import random
from tkinter.simpledialog import *
##์ ์ญ ๋ณ์ ์ ์ธ ๋ถ๋ถ##
inStr = ''
swidth, sheight = 300, 300
tX,tY,txtSize =[0] * 3
##๋ฉ์ธ ์ฝ๋ ๋ถ๋ถ##
turtle.title('์ํ์ฃผ ๋ฌธ์์ด ์ฐ์ต')
turtle.shape('turtle')
turtle.setup( width = swidth + 50, height = sheight + 50)
turtle.screensize( swidth, sheight)
turtle.penup()
inStr = askstring('๋ฌธ์์ด ์
๋ ฅ','๊ฑฐ๋ถ์ด ์ธ ๋ฌธ์์ด์ ์
๋ ฅ')
for ch in inStr :
tX = random.randrange(-swidth / 2, swidth / 2)
tY = random.randrange(-sheight / 2,sheight / 2)
r = random.random(); g = random.random(); b = random.random()
txtSize = random.randrange(10,50)
turtle.goto(tX,tY)
turtle.pencolor((r,g,b))
turtle.write(ch,font=('๋ง์ ๊ณ ๋',txtSize,'bold'))
turtle.done()
[์์ฉ ์์ 01]
##์ ์ญ ๋ณ์ ์ ์ธ ๋ถ๋ถ##
inStr, outStr = "", ""
ch = ""
count, i =0, 0
## ๋ฉ์ธ ์ฝ๋ ๋ถ๋ถ ##
if __name__ == "__main__" :
inStr = input("๋ฌธ์์ด์ ์
๋ ฅํ์ธ์")
count = len(inStr)
for i in range(0,count):
ch = inStr[i]
if (ord(ch) >= ord("A") and ord(ch) <= ord("Z")) :
newCh = ch.lower()
elif (ord(ch) >= ord("a") and ord(ch) <= ord("z")) :
newCh = ch.upper()
else :
newCh = ch
outStr += newCh
print("๋์๋ฌธ์ ๋ณํ ๊ฒฐ๊ณผ -> %s" %outStr)
[practice 7]
outStr = ''
inStr = input('๋ฌธ์์ด-->')
for i in range(0, len(inStr)):
if inStr[i].isdigit() == False:
outStr += inStr[i]
print('์ซ์ ์ ๊ฑฐ-->', outStr)