Login

Search

Learn 🇰🇷
2022.08.10 18:21

1.1 파이썬 맛보기

Views 139 Votes 0 Comment 0

파이썬을 본격적으로 알아보기 전에 먼저 파이썬에서 사용하는 연산자들부터 알아보겠습니다. 


덧셈

>>> 1 + 2

 

 

 

위와 같이 쓰고 Enter키를 눌러보세요. 답이 나오나요?

 


뺄셈

 

>>> 50 - 4
46

 

 


곱셈

>>> 12345678 * 3
37037034

 


컴퓨터에서는 *가 곱하기를 뜻한답니다. 나누기는요?

 


나눗셈

 

/ 가 나누기 입니다. 

 

>>> 5000 / 3
1666.6666666666667
>>> 5000 // 3
1666

 

 

 

 

 

나머지
 

나머지를 구할 땐 %라는 연산자를 씁니다. 예를 들어서, 50을 8로 나눈 나머지는?

 

>>> 50 % 8
2

 


50을 8로 나눈 몫은 6이고 나머지는 2니까 50 % 8의 결과는 2가 됩니다.

 


몫과 나머지를 한 번에 구하기

>>> divmod(50, 8)
(6, 2)

 

 

다음과 같이 divmod() 함수를 써서 몫과 나머지를 한 번에 계산할 수도 있답니다.

 


List of Articles
No. Subject Author Date Views
Notice Learn What is Python? admin 2024.10.19 330
44 Learn 8.1 Exception handling (try, except) admin 2024.11.17 225
43 Learn 7.1 Class and Instance admin 2024.11.17 226
42 Learn 6.1 Text file admin 2024.11.17 216
41 Learn 5.3 Different modules admin 2024.11.17 237
40 Learn 5.2 Import modules admin 2024.11.17 234
39 Learn 5.1 What is module? admin 2024.11.17 123
38 Learn 4.5 Set admin 2024.11.17 133
37 Learn 4.4 Dictionary admin 2022.09.29 127
36 Learn 4.3 Tuple admin 2024.11.17 134
35 Learn 4.2 String and List admin 2024.11.17 139
34 Learn 4.1 Data types admin 2024.11.17 131
33 Learn 3.4 Lambda admin 2024.11.17 129
32 Learn 3.3 Global and local variables admin 2024.11.17 139
31 Learn 3.2 return statement admin 2022.11.29 131
30 Learn 3.1 Function admin 2022.11.27 146
29 Learn 2.3 Iterative statements using for loop admin 2022.11.26 125
28 Learn 2.2 if-elif-else statements admin 2022.11.22 116
27 Learn 2.1 Iterative statements using while admin 2022.11.19 140
26 Learn 1.4 Interpreter and Compiler admin 2022.11.05 133
25 Learn 1.3 LIst admin 2022.11.03 139
Board Pagination Prev 1 2 3 Next
/ 3