MapleStory Finger Point

๐Ÿ’Ž Python/๐Ÿ“šํŒŒ์ด์ฌ for Beginner (2ํŒ)

ch 8 ์—ฐ์Šต๋ฌธ์ œ ํ’€์ด - ํŒŒ์ด์ฌ for Beginner (2ํŒ)

HYEJU01 2024. 3. 28. 04:01

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)