Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 프로그래머스
- Spring Security
- 데이터
- Java
- 스프링
- 스프링부트
- 백준
- CS
- 리눅스
- CS지식
- python
- 자바
- 자료구조
- postgresql
- 플러터
- JPA
- backjoon
- baekjoon
- 시큐리티
- 자바스크립트
- springboot
- 네트워크
- DB
- Flutter
- Oracle
- javascript
- 파이썬
- 데이터베이스
- spring
- 스프링 부트 쇼핑몰 프로젝트 with JPA
Archives
- Today
- Total
Jin's Dev Story
[Python] 제어문 & 반복문 본문
if문
- 형식 1
if 조건:
실행할 문장
a = 15
if a > 10:
a = a - 10
print(a)
// 출력 결과 -> 5
- 형식 2
if 조건:
실행할 문장1
else:
실행할 문장2
a, b = 10, 20
if a > b:
cha = a - b
print(cha)
else:
cha = b - a
print(cha)
// 출력 결과 -> 10
- 형식 3
if 조건1:
실행할 문장1
elif 조건2:
실행할 문장2
elif 조건3:
실행할 문장3
else:
실행할 문장4
jum = 85
if jum >= 90:
print('학점은 A입니다.')
elif jum >= 80:
print('학점은 B입니다.')
elif jum >= 70:
print('학점은 C입니다.')
else:
print('학점은 D입니다.')
for문
- range를 이용하는 방식
for 변수 in range(최종값):
실행할 문장
for i in range(10):
sum += i
// 결과 -> 45
- 리스트(list)를 이용하는 방식
for 변수 in 리스트
실행할 문장
a = [35, 55, 65, 84, 45]
hap = 0
for i in a:
hap += i
avg = hap / len(a)
print(hap, avg)
// 결과 -> 284 56.8
While문
while 조건:
실행할 문장
i, happ = 0, 0
while i < 5:
i += 1
hap += i
print(hap)
// 결과 -> 25
클래스
class 클래스명:
실행할 문장
def 메소드명(self, 인수):
실행할 문장
return 값
class Cls:
x, y = 10, 20
def chg(self):
temp = self.x
self.x = self.y
self.y = temp
a = Cls()
print(a.x, a.y)
a.chg()
print(a.x, a.y)
// 결과
// 10 20
// 20 10
'Programming Language > Python' 카테고리의 다른 글
[Python] Math.gcd - 최대공약수 (0) | 2024.06.12 |
---|---|
[Python] 내장 함수 (0) | 2024.06.12 |
[Python] 데이터와 파일 입출력 (0) | 2024.06.12 |
[Python] 리스트, 튜플, 딕셔너리, 집합 (0) | 2024.06.12 |
[Python] 자료형 (0) | 2024.06.12 |