1) ์ถ๋ ฅ ๋ด์ฉ ์์ธก
ss = "python"
ss[0] (0 ์ถ๋ ฅ) p
ss[1:2] (1๋ถํฐ 1๊น์ง) y
ss[-3:-1] (๋ค์์ 3๋ฒ์งธ~ 2๋ฒ์งธ ) ho
ss[3:] (3 ๋ถํฐ ๋๊น์ง) hon
2) ์ค๋ฅ ๋ฐ์ํ๋ ๊ฒ ๊ณ ๋ฅด์์ค
ss1 = 'Python'
ss2 = 'Good'
2๋ฒ 4๋ฒ
๋ฌธ์์ด๋ผ๋ฆฌ - , / ์ฐ์ฐ์ ๋ถ๊ฐ๋ฅํ๋ค.
3) ๋น์นธ์ฑ์ฐ๊ธฐ :: ๋ฌธ์์ด ์ค๊ฐ๋ง๋ค $ ๋ฃ๊ธฐ
ss = 'Python'
for i in range(0,len(ss)) :
print(ss[i]+"$",end='')
4) ๋น์นธ์ฑ์ฐ๊ธฐ :: ๋ฌธ์์ด ๋ฐ๋ ์์๋ก ์ถ๋ ฅ
inStr, outStr = "Python", ""
strLen = len(inStr)
for i in range(0,strLen):
outStr += inStr[0-(i+1)]
print("๋ด์ฉ ๊ฑฐ๊พธ๋ก ์ถ๋ ฅ -> %s" % outStr)
5) ํจ์ ๊ฒฐ๊ณผ ์์ธก
Str = 'Hanbit'
Str.upper() => HANBIT
lower => banbit
swapcase => hANBIT
title => Hanbit
6) ํจ์๊ฒฐ๊ณผ ์์ธก
Str = 'Hanbit Media, Hanbit Academy,Hanbit Life'
count ('Hanbit') => 3 // ์ฐพ์ ๋ฌธ์์ด์ด ๋ช๊ฐ์ธ์ง ๊ฐ์
find ('Hanbit',2) => 14 // ์ผ์ชฝ 0๋ฒ๋ถํฐ ๋ช๋ฒ์งธ ์์นํ์ง ์ฐพ์ (๋ฌธ์์ด์์ผ๋ฉด -1 ๋ฐํ)
rindex('Media') => 7 // ์ฐพ๋๊ฑด ๋ค์์๋ถํฐ ๊ฒฐ๊ณผ๊ฐ๋ 7
startswith('Hanbit') => True // ์ฐพ์๋ฌธ์์ด๋ก ์์ํ๋ฉด True ๋ฐํ ์๋๋ฉด False
7) ๋ฌธ์์ด์์ ์ซ์ ์ญ์ ํ๋ ํ๋ก๊ทธ๋จ ์์ฑ
inStr,outStr = "", ""
inStr = input("๋ฌธ์์ด => ")
for i in range(0,len(inStr)) :
if (inStr[i].isdigit() == True):
pass
else :
outStr += inStr[i]
print("์ซ์์ ๊ฑฐ => %s" % outStr)
8) ์ซ์, ์๋ฌธ, ํ๊ธ, ๊ธฐํ ๋ฌธ์ ๊ฐ์ ์ธ๋ ํ๋ก๊ทธ๋จ ์์ฑ
inStr,outStr = "", ""
Ucnt,Lcnt,Ncnt,Kcnt,cnt=0,0,0,0,0
inStr = input("๋ฌธ์์ด => ")
for ch in inStr :
if (ord(ch)>=ord("A") and ord(ch) <=ord("Z")):
Ucnt += 1
elif (ord(ch)>=ord("a") and ord(ch) <=ord("z")):
Lcnt += 1
elif (ord(ch)>=ord("0") and ord(ch) <=ord("9")):
Ncnt += 1
elif (ord(ch)>=ord("ใฑ") and ord(ch) <=ord("ํฃ")):
Kcnt += 1
else :
cnt += 1
print("๋๋ฌธ์ = %d" % Ucnt)
print("์๋ฌธ์ = %d" % Lcnt)
print("์ซ์ = %d" % Ncnt)
print("ํ๊ธ = %d" % Kcnt)
print("๊ธฐํ = %d" % cnt)