Login

Search

Learn
2022.11.01 22:17

1.1 Getting into Python

Views 2013 Votes 0 Comment 0

Before we dive into Python, let's start with the operators used in Python.

 

Addition

>>> 1 + 2

 

 

 

 

 

Try writing the above and pressing enter. Do you get an answer?

 

 

Subtraction

>>> 50 - 4
46

 

 

 

 

 

Multiplication

>>> 12345678 * 3
37037034

 

 

 

 

 

Computers know that * means multiply. What about division?

 

 

division

/ is division.

 

 

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

 

 

 

 

 

 

 

Remainder

To get the remainder, use the % operator. For example, the remainder of 50 divided by 8 is ?

 

>>> 50 % 8
2

 

 

 

 

 

The quotient of 50 divided by 8 is 6 and the remainder is 2, so the result of 50% 8 is 2.

 

 

Finding the quotient and remainder at once

 

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

 

 

 

 

You can also use the divmod() function to calculate the quotient and remainder at once, like this

 

List of Articles
No. Subject Author Date Views
Notice Learn What is Python? admin 2024.10.19 3102
» Learn 1.1 Getting into Python admin 2022.11.01 2013
43 Learn πŸ‡°πŸ‡· 1.1 파이썬 맛보기 admin 2022.08.10 1285
42 Learn 1.2 Variable admin 2022.11.03 2033
41 Learn πŸ‡°πŸ‡· 1.2 λ³€μˆ˜ admin 2022.08.13 1438
40 Learn 1.3 LIst admin 2022.11.03 1360
39 Learn πŸ‡°πŸ‡· 1.3 리슀트 admin 2022.08.13 1351
38 Learn 1.4 Interpreter and Compiler admin 2022.11.05 1300
37 Learn πŸ‡°πŸ‡· 1.4 인터프리터와 컴파일러 admin 2022.08.19 1251
36 Learn 2.1 Iterative statements using while admin 2022.11.19 1428
35 Learn πŸ‡°πŸ‡· 2.1 while을 μ‚¬μš©ν•˜λŠ” 반볡문 admin 2022.08.23 1198
34 Learn 2.2 if-elif-else statements admin 2022.11.22 1366
33 Learn πŸ‡°πŸ‡· 2.2 쑰건문 (if-elif-else) admin 2022.08.23 1626
32 Learn πŸ‡°πŸ‡· 2.3 forλ₯Ό μ‚¬μš©ν•˜λŠ” 반볡문 admin 2022.08.24 1321
31 Learn 2.3 Iterative statements using for loop admin 2022.11.26 1447
30 Learn 3.1 Function admin 2022.11.27 1306
29 Learn πŸ‡°πŸ‡· 3.1 ν•¨μˆ˜ admin 2022.09.01 1274
28 Learn 3.2 return statement admin 2022.11.29 1421
27 Learn πŸ‡°πŸ‡· 3.2 λ°˜ν™˜(return)λ¬Έ admin 2022.09.10 1125
26 Learn 3.3 Global and local variables admin 2024.11.17 1346
25 Learn πŸ‡°πŸ‡· 3.3 μ§€μ—­λ³€μˆ˜, μ „μ—­λ³€μˆ˜ admin 2022.09.15 1251
Board Pagination Prev 1 2 3 Next
/ 3