In the last video,
you saw this line of Python that computes the sum of 3 and 5.
The plus sign and this line is an arithmetic operator.
Python has several arithmetic operators
most of which follow the usual rules of Mathematics.
Let’s look at the first four,
in Python addition and subtraction are performed with the usual symbols, plus and minus.
Multiplication uses an asterisk,
and division uses a forward slash.
Here you can see that multiplication happens before addition.
This is because Python follows
Mathematical Order of Operations which you can get a refresher on in the notes below.
If you want addition to come first,
you can enclose this part in parentheses.
Moving on from those four,
here’s the operator for exponentiation.
You can raise one number to the power of another with two asterisks.
For example, this line prints three to the power of two which results in nine.
There’s another operator that is sometimes
mistaken for the exponentiation operator. The caret.
This actually performs a more obscure operation called bitwise XOR.
This is an arithmetic operator that doesn’t follow the usual rules of Mathematics.
Bitwise operators are not something you need to know for this course but,
if you’re interested there’s information about this in the notes below.
All you need to remember is that if you perform exponentiation,
you use two asterisks and not with
a caret or you’ll accidentally produce very confusing results.
Another useful operator is this percent sign which performs the modulo operation.
It returns the remainder after you’ve divided the first number by the second.
In this example, nine divided by two is four with a remainder of one.
So this line would print one since modulo gives us the remainder.
You might also find use for integer division denoted by two forward slashes.
It divides one integer by another but rather than giving the exact answer,
it rounds down the answer down to an integer.
Seven divided by two is three point five which rounds down to three.
Notice it rounds down even if the answer is negative.
In this case, negative three point five was rounded down to negative four.
There are other categories of operators that we’ll learn about
soon but these are all the arithmetic operators in Python.
지난 영상에서는
3과 5의 합을 계산하는 이 파이썬 라인을 보셨을 겁니다.
더하기 기호와 이 줄은 산술 연산자입니다.
Python에는 여러 산술 연산자가 있습니다.
대부분은 수학의 일반적인 규칙을 따릅니다.
처음 4가지를 살펴보자면,
파이썬에서 더하기와 빼기는 일반적인 기호인 더하기와 빼기로 수행됩니다.
곱셈은 별표를 사용하고,
나눗셈은 슬래시를 사용합니다.
여기에서 곱셈이 더하기 전에 발생하는 것을 볼 수 있습니다.
이것은 파이썬이 다음을 따르기 때문입니다.
아래 메모에서 복습할 수 있는 수학적 연산 순서입니다.
덧셈을 먼저 하고 싶다면,
이 부분을 괄호로 묶을 수 있습니다.
그 4가지에서 넘어가면,
여기에 지수 연산자가 있습니다.
별표 두 개를 사용하여 한 숫자를 다른 숫자의 거듭제곱으로 올릴 수 있습니다.
예를 들어, 이 줄은 3을 2의 거듭제곱으로 인쇄하여 9가 됩니다.
때때로 다른 연산자가 있습니다.
지수 연산자로 착각합니다. 캐럿.
이것은 실제로 비트 XOR이라는 더 모호한 연산을 수행합니다.
이것은 수학의 일반적인 규칙을 따르지 않는 산술 연산자입니다.
비트 연산자는 이 과정에서 알아야 할 사항은 아니지만,
관심이 있는 경우 아래 메모에 이에 대한 정보가 있습니다.
기억해야 할 것은 지수를 수행하면
두 개의 별표를 사용하고
캐럿 또는 실수로 매우 혼란스러운 결과를 생성합니다.
또 다른 유용한 연산자는 모듈로 연산을 수행하는 이 백분율 기호입니다.
첫 번째 숫자를 두 번째 숫자로 나눈 후 나머지를 반환합니다.
이 예에서 9를 2로 나누면 4이고 나머지는 1입니다.
모듈로가 나머지를 제공하므로 이 줄은 하나를 인쇄합니다.
두 개의 슬래시로 표시된 정수 나눗셈을 사용할 수도 있습니다.
그것은 하나의 정수를 다른 정수로 나눕니다. 그러나 정확한 답을 주기보다는,
답을 정수로 내림합니다.
7을 2로 나누면 3.5가 되어 3이 됩니다.
답이 음수인 경우에도 반올림됩니다.
이 경우 음수 3.5는 음수 4로 반올림되었습니다.
우리가 배울 다른 범주의 연산자가 있습니다.
곧 파이썬의 모든 산술 연산자입니다.




댓글을 달려면 로그인해야 합니다.