IT 및 코딩/파이썬(Python)

<꿀팁모아 : 91번째 포스팅> 파이썬 연산자

희망주기 2021. 12. 22. 20:38
반응형

<꿀팁모아 : 91번째 포스팅> 파이썬 연산자 

안녕하세요 꿀팁모아 희망주기입니다

 

오늘 알아볼 주제는 파이썬 연산자입니다

 

1 파이썬 연산자 

연산자는 변수 및 값에 대한 작업을 수행하는데 사용이 됩니다. 파이썬은 다음 그룹에서 연산자를 분할을 하게 되는데요. 어떤 것들이 있을까요? 

 

1) 산술 연산자

2) 할당 연산자

3) 비교 연산자

4) 논리 연산자

5) ID 연산자

6) 멤버쉽 연산자

7) 비트 와이즈 연산자 

 

2 파이썬 산술 연산자 

Operator 이름
+ 덧셈 x + y
- 뺄셈 x - y
* 곱셈 x * y
/ 나눗셈 x / y
% 나머지 x % y
** 지수 x ** y
// x // y

3 파이썬 할당 연산자

할당 연산자는 변수에 값을 할당하는데 사용이 됩니다 

 

Operator Same as
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *=3 x = x * 3
/= x / = 3 x = x / 3
%= x %= 3 x = x % 3
//= x //= 3 x = x // 3
**=  x ** = 3 x = x ** 3
&= x & = 3 x = x & 3
l= x l = 3 x = x l 3
^= x ^= 3 x = x ^ 3
>>=  x >>= 3 x = x >> 3
<<= x <<= 3 x= x << 3

4 파이썬 비교 연산자 

비교 연산자는 다음 두 값을 비교하는데 사용이 된다 

 

Operator Name Example
== Equal x == y
!= Not Equal x != y
> Greater than x > y
Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

5 파이썬 논리 연산자

논리 연산자는 조건부 문을 결합하는데 사용이 된다 

 

Operator Description Example
and Returns True if both statements are true x < 5 and x < 10
or Returns True if one of the statements is true x < 5 or x < 4 
not Reverse the result, returns False if the result is true not(x<5 and x< 10) 

6 파이썬 ID 연산자

ID 연산자는 객체가 같을 경우가 아니라 실제로 동일한 개체인 경우 동일한 메모리 위치를 사용하는데 사용이 되요

 

Operator Description Example
is Returns True if both variables are the same object x is y 
is not Returns True if both variables are not the same object  x is not y 

7 파이썬 멥버쉽 운영자 

멤버 자격 연산자는 개체에 시퀀스가 표시되는지 테스트하는데 사용이 된다 

 

Operator Description Example
in Returns True if a sequence with the specified value is present in the object x in y
not in Returns True if a sequence with the specified value is not present in the object x not in y

8 파이썬 비트와이즈 연산자

Bitwise 연산자는 바이너리 숫자를 비교하는데 사용이 된다 

 

Operator Name Description
& AND Sets each bit to 1 if both bits are 1
l OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1 
NOT Invents all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and left the leftmost bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the letf, and let the rightmost bits fall off 

 

반응형