Python의 연산자 함수 | 세트 1

Python에는 'operator' 모듈 아래에 많은 수학적 논리적 관계형 비트별 연산을 위한 함수가 미리 정의되어 있습니다. 이 문서에서는 기본 기능 중 일부를 다룹니다. 1. 추가(a b) :- 이 함수는 다음을 반환합니다. 덧셈 주어진 인수 중. 작업 - a + b. 2. 하위(a b) :- 이 함수는 다음을 반환합니다. 차이점 주어진 인수 중. 작업 - 가-비. 3. 멀(ab) :- 이 함수는 다음을 반환합니다. 제품 주어진 인수 중. 작업 - a * b. Python
   # Python code to demonstrate working of    # add() sub() mul()   # importing operator module    import   operator   # Initializing variables   a   =   4   b   =   3   # using add() to add two numbers   print   (  'The addition of numbers is :'    end  =  ''  );   print   (  operator  .  add  (  a     b  ))   # using sub() to subtract two numbers   print   (  'The difference of numbers is :'    end  =  ''  );   print   (  operator  .  sub  (  a     b  ))   # using mul() to multiply two numbers   print   (  'The product of numbers is :'    end  =  ''  );   print   (  operator  .  mul  (  a     b  ))   
Output:
The addition of numbers is:7 The difference of numbers is :1 The product of numbers is:12  

4. 트루디브(ab) :- 이 함수는 다음을 반환합니다. 분할 주어진 인수 중. 작업 - a / b. 5. 플로어디브(ab) :- 이 함수는 주어진 인수의 나눗셈도 반환합니다. 그러나 값은 바닥 값입니다. 즉 가장 큰 작은 정수를 반환합니다. . 작업 - 에 // 비. 6. 펑(ab) :- 이 함수는 다음을 반환합니다. 지수화 주어진 인수 중. 작업 - a ** b. 7. 모드(ab) :- 이 함수는 다음을 반환합니다. 계수 주어진 인수 중. 작업 - a % b. Python
   # Python code to demonstrate working of    # truediv() floordiv() pow() mod()   # importing operator module    import   operator   # Initializing variables   a   =   5   b   =   2   # using truediv() to divide two numbers   print   (  'The true division of numbers is : '    end  =  ''  );   print   (  operator  .  truediv  (  a    b  ))   # using floordiv() to divide two numbers   print   (  'The floor division of numbers is : '    end  =  ''  );   print   (  operator  .  floordiv  (  a    b  ))   # using pow() to exponentiate two numbers   print   (  'The exponentiation of numbers is : '    end  =  ''  );   print   (  operator  .  pow  (  a    b  ))   # using mod() to take modulus of two numbers   print   (  'The modulus of numbers is : '    end  =  ''  );   print   (  operator  .  mod  (  a    b  ))   
Output:
The true division of numbers is: 2.5 The floor division of numbers is: 2 The exponentiation of numbers is: 25 The modulus of numbers is: 1  

8. lt(a b) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b보다 작은지 확인하세요. . a가 b보다 작으면 true를 반환하고 그렇지 않으면 false를 반환합니다. 작업 - 에이 < b . 9. 그(a b) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b보다 작거나 같은지 확인하세요. . a가 b보다 작거나 같으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 작업 - 에이 <= b . 10. eq(ab) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b와 같은지 확인하세요. . a가 b와 같으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 작업 - a == b . Python
   # Python code to demonstrate working of    # lt() le() and eq()   # importing operator module    import   operator   # Initializing variables   a   =   3   b   =   3   # using lt() to check if a is less than b   if  (  operator  .  lt  (  a    b  )):   print   (  '3 is less than 3'  )   else   :   print   (  '3 is not less than 3'  )   # using le() to check if a is less than or equal to b   if  (  operator  .  le  (  a    b  )):   print   (  '3 is less than or equal to 3'  )   else   :   print   (  '3 is not less than or equal to 3'  )   # using eq() to check if a is equal to b   if   (  operator  .  eq  (  a    b  )):   print   (  '3 is equal to 3'  )   else   :   print   (  '3 is not equal to 3'  )   
Output:
3 is not less than 3 3 is less than or equal to 3 3 is equal to 3  

11. gt(ab) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b보다 큰지 확인하세요. . a가 b보다 크면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 작업 - a > b . 12. 게(ab) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b보다 크거나 같은지 확인하세요. . a가 b보다 크거나 같으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 작업 - a >= b . 13.네(ab) :- 이 기능은 다음과 같은 용도로 사용됩니다. a가 b와 같지 않거나 같은지 확인하세요. . a가 b와 같지 않으면 true를 반환하고 그렇지 않으면 false를 반환합니다. 작업 - !=b . Python
   # Python code to demonstrate working of    # gt() ge() and ne()   # importing operator module    import   operator   # Initializing variables   a   =   4   b   =   3   # using gt() to check if a is greater than b   if   (  operator  .  gt  (  a    b  )):   print   (  '4 is greater than 3'  )   else   :   print   (  '4 is not greater than 3'  )   # using ge() to check if a is greater than or equal to b   if   (  operator  .  ge  (  a    b  )):   print   (  '4 is greater than or equal to 3'  )   else   :   print   (  '4 is not greater than or equal to 3'  )   # using ne() to check if a is not equal to b   if   (  operator  .  ne  (  a    b  )):   print   (  '4 is not equal to 3'  )   else   :   print   (  '4 is equal to 3'  )   
Output:
4 is greater than 3 4 is greater than or equal to 3 4 is not equal to 3