meong_j
기록하는 습관.
meong_j
전체 방문자
오늘
어제
  • 분류 전체보기 (176)
    • 개인 공부 정리 (0)
    • 서버 운영 (37)
      • Linux (36)
    • Frontend (11)
      • Vue.js (10)
    • Backend (70)
      • Java (4)
      • Python (22)
      • Django (38)
      • Spring (6)
    • Database (5)
      • Oracle (4)
      • MySQL (1)
      • MariaDB (0)
    • Android (14)
      • Kotlin (6)
    • 배포 (9)
      • Docker (8)
      • AWS (1)
    • IT_study (29)
      • Coding test (17)
      • 알고리즘 (5)
      • 스터디 (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • github

인기 글

반응형

태그

  • dockersecret
  • 리눅스방화벽
  • 개발자도서
  • django
  • 코틀린자료형
  • Proxy
  • 이차원배열정렬
  • router-link
  • Kotlin
  • 안드로이드adaptor
  • 중첩라우트
  • SASS Variables
  • 리눅스인증
  • 테크커리어
  • dp #알고리즘
  • cpu사용률
  • 배포인프라
  • DHCP
  • gabagecollecter
  • docker

최근 댓글

최근 글

250x250
hELLO · Designed By 정상우.
meong_j

기록하는 습관.

파이썬 흐름제어 (1) - if 문
Backend/Python

파이썬 흐름제어 (1) - if 문

2021. 9. 14. 18:44
728x90
반응형
 if 구문 - 출력하기
#파이썬 제어문
# IF 실습

#기본 형식
print(type(True)) # 0이 아닌 수, "abc" , [1,2,3,...] , (1,2,3,...) ...
print(type(False)) # 0, "" , [] ,() , {} ...

# 예1

if True:
    print('Good') #  파이썬은 들여쓰기 (indent) 안하면 에러

if False:
    print('Bad')

# 예2
if False:
    print('Bad!!!')
else:
    print('Good!!!')


# 관계 sep연산자
# > , >=, < , <=, ==, !=
x = 15
y = 10

#양변이 같은 경우 참
print(x == y)

#양변이 다를 때  참
print(x != y)

print(x > y)

print(x <= y)

print()

city = ""

if city:
    print("You are in : ", city)
else:
    print("Please enter your city")


city2 = "seoul"

if city2:
    print("You are in : ", city2)
else:
    print("Please enter your city")


print()

 

 

 

 

논리연산자 - and, or, not
#논리연산자(중요)
# and, or, not

a = 75
b = 40
c = 10

print('and:', a > b and b > c) # a > b > c
print('or:', a > b or b > c)
print('not:', not a > b)
print('not:', not b < c)
print(not True)
print(not False)

print()

# 산술, 관계, 논리 우선 순위
# 산술 > 관계 > 논리
print('e1:', 3+12 > 7+3)
print('e2:', 5+10*3 > 7 +3*20)
print('e3:', 5+10 > 3 and 7+3 == 10)
print('e4:', 5+10 > 0 and not 7+3 ==10)


print()

 

 

 

 

 

score1 = 90
score2 = 'A'


# 예4
#복수의 조건이 모두 참일 경우에 실행
if score1 >= 90 and score2 == 'A':
    print('Pass')
else:
    print('Fail')

print()

 

 

 

 

# 예5
id1 = 'vip'
id2 = 'admin'
grade = 'platinum'

if id1 == 'vip' or id2 == 'admin':
    print('관리자 입장')


if id2 == 'admin' and grade == 'platinum':
    print('최상위 관리자')

 

 

 

 

# 예6
# 다중조건문

num = 90

if num >= 90:
    print('Grade : A')
elif num >= 80:
    print('Grade : B')
elif num >= 70:
    print('Grade : C')
else:
    print('과락')
    

print()

#중첩 조건문

grade = 'A'
total = 95

if grade == 'A':
    if total >= 90:
        print('장학금 100%')
    elif total >= 90:
        print('장학금 80%')
    else:
        print('장학금 50%')
else:
    print('장학금 없음')


print()

#in, not in

q = [10,20,30]
w = {70,80,90,100}
e = {"name":"Lee","city":"seoul","grade":"A"}
r = (10,12,14)

print(15 in q)
print(90 in w)
print(12 not in r)
print("name" in e)
print("seoul" in e.values())

 

 

반응형

'Backend > Python' 카테고리의 다른 글

파이썬 흐름제어 (3) - while 문  (0) 2021.09.14
파이썬 흐름제어 (2) - for 문  (0) 2021.09.14
파이썬 기초 자료형 (8) - 집합(Set)  (0) 2021.09.13
파이썬 기초 자료형 (7) - 딕셔너리(Dictionary)  (0) 2021.09.13
파이썬 기초 자료형 (6) - 튜플(Tuple)  (0) 2021.09.13
    'Backend/Python' 카테고리의 다른 글
    • 파이썬 흐름제어 (3) - while 문
    • 파이썬 흐름제어 (2) - for 문
    • 파이썬 기초 자료형 (8) - 집합(Set)
    • 파이썬 기초 자료형 (7) - 딕셔너리(Dictionary)
    meong_j
    meong_j
    #it #개발일기 #개발공부 #개발자 #백앤드 #생각정리 #시간은 실력에 비례한다 #뭐든지 꾸준히 열심히 #오늘의 내가 내일의 나를 만든다

    티스토리툴바