[Python] 파이썬 기초5. 조건문

[Python] 파이썬 기초5. 조건문

728x90

자바스크립트와 달리 is, is not 을 추가로 사용할 수 있다.

그리고 else if 대신 elif를 사용한다.

#조건문 def plus(a,b): if type(b) is str: return 'type is str' else: return a+b def plus(a,b): if type(b) is int or type(b) is float: return a+b else: return None print(plus(12,1.2)) print(plus(12,'10')) #2. def age_check(age) : print(f'you are {age}') if age < 18: print('you cant drink') else: print('enjoy your drink') age_check(18) #3. def age_check(age) : print(f'you are {age}') if age < 18: print('you cant drink') #else if === elif elif age ==18: print('you are new to this!') elif age > 20 and age < 25: print('you are still kind of young') else: print('enjoy your drink') age_check(23)

반응형

from http://codingbucks.tistory.com/263 by ccl(A) rewrite - 2021-12-31 16:27:20