๐Python
Welcome to Python : ์์ธ์ฒ๋ฆฌ
4:Bee
2023. 7. 25. 14:13
728x90
- ํด๋์ค : https://hi-code.tistory.com/123
- ๋ชจ๋ : https://hi-code.tistory.com/124
- ํจํค์ง : https://hi-code.tistory.com/125
- ์์ธ ์ฒ๋ฆฌ : https://hi-code.tistory.com/126
- ๋ด์ฅ ํจ์ : https://hi-code.tistory.com/127
- ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ : https://hi-code.tistory.com/128
- ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ :https://hi-code.tistory.com/129
| Title | Code | Console |
| try-expect |
try: 4 / 0
except ZeroDivisionError as e:
print(e)
|
division by zero |
| try-finally |
try: f = open('foo.txt', 'w')
finally:
f.close
|
|
| try-else |
try:
age = int(input('๋์ด๋ฅผ ์
๋ ฅํ์ธ์: '))
except:
print('์
๋ ฅ์ด ์ ํํ์ง ์์ต๋๋ค.')
else:
if age <= 18:
print('๋ฏธ์ฑ๋
์๋ ์ถ์
๊ธ์ง ์
๋๋ค.')
else:
print('ํ์ํฉ๋๋ค.')
|
|
| pass |
try: f = open("๋์๋ํ์ผ", 'r')
except FileExistsError:
pass
|
|
| raise |
class Bird: def fly(self):
raise NotImplementedError
class Eagle(Bird):
pass
eagle = Eagle()
eagle.fly()
|
raise NotImplementedError NotImplementedError |
| ์์ธ ๋ง๋ค๊ธฐ |
class MyError(Exception):
pass
def say_nick(nick):
if nick == "๋ฐ๋ณด":
raise MyError()
print(nick)
say_nick("์ฒ์ฌ")
say_nick("๋ฐ๋ณด")
|
์ฒ์ฌ raise MyError() __main__.MyError |
728x90