Login

Search

Learn
2022.11.01 22:17

1.1 Getting into Python

Views 757 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 2262
44 Learn πŸ‡°πŸ‡· 8.1 μ˜ˆμ™Έμ²˜λ¦¬(try, except) admin 2022.10.27 748
43 Learn 8.1 Exception handling (try, except) admin 2024.11.17 958
42 Learn πŸ‡°πŸ‡· 7.1. 클래슀(class)와 μΈμŠ€ν„΄μŠ€ admin 2022.10.27 808
41 Learn 7.1 Class and Instance admin 2024.11.17 1237
40 Learn πŸ‡°πŸ‡· 6.1 ν…μŠ€νŠΈ 파일 admin 2022.10.21 803
39 Learn 6.1 Text file admin 2024.11.17 1131
38 Learn πŸ‡°πŸ‡· 5.3 μ—¬λŸ¬ κ°€μ§€ λͺ¨λ“ˆ admin 2022.10.15 962
37 Learn 5.3 Different modules admin 2024.11.17 1196
36 Learn πŸ‡°πŸ‡· 5.2 λͺ¨λ“ˆ κ°€μ Έμ˜€κΈ°(import) admin 2022.10.07 887
35 Learn 5.2 Import modules admin 2024.11.17 1192
34 Learn πŸ‡°πŸ‡· 5.1 λͺ¨λ“ˆμ΄λž€ admin 2022.10.03 762
33 Learn 5.1 What is module? admin 2024.11.17 956
32 Learn πŸ‡°πŸ‡· 4.5 μ„ΈνŠΈ(set) admin 2022.10.02 848
31 Learn 4.5 Set admin 2024.11.17 902
30 Learn πŸ‡°πŸ‡· 4.4 λ”•μ…”λ„ˆλ¦¬(dict) admin 2022.09.30 822
29 Learn 4.4 Dictionary admin 2022.09.29 994
28 Learn πŸ‡°πŸ‡· 4.3 νŠœν”Œ(tuple) admin 2022.09.21 791
27 Learn 4.3 Tuple admin 2024.11.17 1016
26 Learn πŸ‡°πŸ‡· 4.2 λ¬Έμžμ—΄κ³Ό 리슀트 admin 2022.09.16 754
25 Learn 4.2 String and List admin 2024.11.17 1023
Board Pagination Prev 1 2 3 Next
/ 3