๐ŸŒฑ ํŒŒ์ด์ฌ[Python] ๋ฌธ์ž/์ˆซ์ž ํ™•์ธํ•˜๊ธฐ!

sh_awtylol4ยท2022๋…„ 7์›” 27์ผ
0

๐ŸŒฑ Today I Learn

๋ชฉ๋ก ๋ณด๊ธฐ
12/16
post-thumbnail

๐Ÿค” ๋ฌธ์ž or ์ˆซ์ž๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ!

[isalpha] ๋ฌธ์ž์—ด์˜ ๊ตฌ์„ฑ์ด ์•ŒํŒŒ๋ฒณ or ํ•œ๊ธ€์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•.

isalpha() ๋ฌธ์ž์—ด์— ๊ณต๋ฐฑ, ๊ธฐํ˜ธ, ์ˆซ์ž๊ฐ€ ์žˆ์„์‹œ False๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

# Example for isalpha

check1 = 'A'
check2 = 'S520'
check3 = 'ํ•ญ์ƒํ–‰๋ณตํ•˜์ž'
check4 = 'happy_love'
check5 = 'happy love'

print(check1.isalpha()) # True
print(check2.isalpha()) # ์ˆซ์ž ํฌํ•จ False
print(check3.isalpha()) # True
print(check4.isalpha()) # ๊ธฐํ˜ธ ํฌํ•จ False
print(check5.isalpha()) # ๊ณต๋ฐฑ ํฌํ•จ False

[isdigit] ๋ฌธ์ž์—ด์˜ ๊ตฌ์„ฑ์ด ์ˆซ์ž์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•.

isdisit() ๋ฌธ์ž์—ด์— ๊ณต๋ฐฑ, ๊ธฐํ˜ธ, ์ˆซ์ž๊ฐ€ ์žˆ์„์‹œ False๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

# Example for isdigit

check1 = '123'
check2 = '010-1234-1234'
check3 = '์ „ํ™”010'
check4 = '010 1234 1234'

print(check1.isdigit()) # True
print(check2.isdigit()) # ๊ธฐํ˜ธ ํฌํ•จ False
print(check3.isdigit()) # ๋ฌธ์ž ํฌํ•จ False
print(check4.isdigit()) # ๊ณต๋ฐฑ ํฌํ•จ False

[isalnum] ์•ŒํŒŒ๋ฒณ(ํ•œ๊ธ€) ๋˜๋Š” ์ˆซ์ž์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•.

# Example for isalnum

check1 = '1234'         
check2 = 'happy'		
check3 = 'happy1234'	
check4 = 'happy_1234'	
check5 = 'happy 1234'

print(check1.isalnum())	# True
print(check2.isalnum())	# True
print(check3.isalnum())	# True
print(check4.isalnum())	# ๊ธฐํ˜ธ ํฌํ•จ False
print(check5.isalnum())	# ๊ณต๋ฐฑ ํฌํ•จ False
profile
ํฌ๊ธฐํ•˜๋Š” ๊ทธ ์ˆœ๊ฐ„์ด ๋ฐ”๋กœ ์‹œํ•ฉ์ข…๋ฃŒ์˜ˆ์š”...

0๊ฐœ์˜ ๋Œ“๊ธ€