Login

Search

Learn 🇰🇷
2022.08.10 18:21

1.1 파이썬 맛보기

Views 1619 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 3742
44 Learn 8.1 Exception handling (try, except) admin 2024.11.17 1895
43 Learn 7.1 Class and Instance admin 2024.11.17 2110
42 Learn 6.1 Text file admin 2024.11.17 1961
41 Learn 5.3 Different modules admin 2024.11.17 2034
40 Learn 5.2 Import modules admin 2024.11.17 2110
39 Learn 5.1 What is module? admin 2024.11.17 1631
38 Learn 4.5 Set admin 2024.11.17 1664
37 Learn 4.4 Dictionary admin 2022.09.29 1742
36 Learn 4.3 Tuple admin 2024.11.17 1644
35 Learn 4.2 String and List admin 2024.11.17 1733
34 Learn 4.1 Data types admin 2024.11.17 1565
33 Learn 3.4 Lambda admin 2024.11.17 1536
32 Learn 3.3 Global and local variables admin 2024.11.17 1646
31 Learn 3.2 return statement admin 2022.11.29 1667
30 Learn 3.1 Function admin 2022.11.27 1620
29 Learn 2.3 Iterative statements using for loop admin 2022.11.26 1777
28 Learn 2.2 if-elif-else statements admin 2022.11.22 1663
27 Learn 2.1 Iterative statements using while admin 2022.11.19 1669
26 Learn 1.4 Interpreter and Compiler admin 2022.11.05 1574
25 Learn 1.3 LIst admin 2022.11.03 1594
Board Pagination Prev 1 2 3 Next
/ 3