Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

RUBY

Operator 모듈 본문

프로그래밍 언어/Python

Operator 모듈

ruby-jieun 2023. 1. 4. 15:24

 

 

Operator 모듈

 


  • 모듈이란, 프로그램을 구성하는 구성 요소로, 관련된 데이터와 함수를 하나로 묶은 단위이다.
    수학 연산 관련 모듈, 난수 관련 모듈, 연산자 관련 모듈 등...

 

  • 산술 연산자 관련 함수
연산자 operator 함수
+ operator.add()
- operator.sub()
* operator.mul()
/ operator.truediv()
% operator.mod()
// operator.floordiv()
** operator.pow()

 

import operator

num1 = 8
num2 = 3

print('{} + {} : {}' .format(num1, num2, operator.add(num1, num2)))
print('{} - {} : {}' .format(num1, num2, operator.sub(num1, num2)))
print('{} * {} : {}' .format(num1, num2, operator.mul(num1, num2)))
print('{} / {} : {}' .format(num1, num2, operator.truediv(num1, num2)))
print('{} % {} : {}' .format(num1, num2, operator.mod(num1, num2)))
print('{} // {} : {}' .format(num1, num2, operator.floordiv(num1, num2)))
print('{} ** {} : {}' .format(num1, num2, operator.pow(num1, num2)))
8 + 3 : 11
8 - 3 : 5
8 * 3 : 24
8 / 3 : 2.6666666666666665
8 % 3 : 2
8 // 3 : 2
8 ** 3 : 512

 

 

  • 비교 연산자 관련 함수
연산자 operator 함수
== operator.eq()
!= operator.ne()
> operator.gt()
>= operator.ge()
< operator.lt()
<= operator.le()

 

import operator

num1 = 8
num2 = 3

print('{} == {} : {}' .format(num1, num2, operator.eq(num1, num2)))
print('{} != {} : {}' .format(num1, num2, operator.ne(num1, num2)))
print('{} > {} : {}' .format(num1, num2, operator.gt(num1, num2)))
print('{} >= {} : {}' .format(num1, num2, operator.ge(num1, num2)))
print('{} < {} : {}' .format(num1, num2, operator.lt(num1, num2)))
print('{} <= {} : {}' .format(num1, num2, operator.le(num1, num2)))
8 == 3 : False
8 != 3 : True
8 > 3 : True
8 >= 3 : True
8 < 3 : False
8 <= 3 : False

 

 

  • 논리 연산자 관련 함수
연산자 operator 함수
and operator.and_()
or operator.or_()
not operator.not_()
import operator

flag1 = True
flag2 = False

print('{} and {} : {}' .format(flag1, flag2, operator.and_(flag1, flag2)))
print('{} or {} : {}' .format(flag1, flag2, operator.or_(flag1, flag2)))
print('not {} : {}' .format(flag1, operator.not_(flag1)))
True and False : False
True or False : True
not True : False

 

 

 

 

 

'프로그래밍 언어 > Python' 카테고리의 다른 글

조건문(if문)  (0) 2023.01.04
조건식  (0) 2023.01.04
논리 연산자  (0) 2023.01.03
비교 연산자 2  (0) 2023.01.03
비교 연산자  (0) 2023.01.03
Comments