Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

Better

[codetree] python3 기초 - 03 연산자 본문

codetree

[codetree] python3 기초 - 03 연산자

doll2gom 2023. 3. 17. 22:09

1. 사칙연산

덧셈  +  뺄셈  -  곱셈 *  몫 //  나머지 % 

a, b = 9, 4
print(a + b, a * b, a - b, a // b, a % b, a / b, a**b)
// 13 36 5 2 1 2.25 6561

 

정수와 실수가 만나면 type이 실수가 됨

a = 3 / 3
b = 4
print(a + b)
// 5.0

2. 사칙연산 다른 표현법

a, b = 9, 4
a  = a + 5
a -= 5
a %= b
b *= 3

// 결과
14
9
1
12

3. 합과 평균

list의 합은 sum, 크기는 len이라는 이라는 built-in 함수 사용하여 구함

a, b, c, d = 9, 4, 5, 7
arr = [a, b, c, d]
print(sum(arr), sum(arr) / len(arr))

// 25 6.25

 

 

 

'codetree' 카테고리의 다른 글

[codetree] python3 기초 - 02 입출력  (0) 2023.03.08
[codetree] python3 기초 - 01 출력  (0) 2023.03.06