728x90
1. 덧셈 ( + )
문자열도 덧셈가능.
>>> 2+3
5
>>> "hi"+"hello"
'hihello'
2. 뺄셈 ( - )
문자열은 뺄셈 불가.
>>> 2-3
-1
>>> "hi"-"hello"
Traceback (most recent call last):
File "<ipython-input-6-42d8c0eec2fe>", line 1, in <module>
"hi"-"hello"
TypeError: unsupported operand type(s) for -: 'str' and 'str'
3. 곱셈 ( * )
- 문자열도 정수와 곱셈 가능. 실수와는 곱셈 불가.
>>> 3*4
12
>>> "hi"*3
'hihihi'
>>> "hi"*3.0
Traceback (most recent call last):
File "<ipython-input-11-80e9c3f36b0c>", line 1, in <module>
"hi"*3.0
TypeError: can't multiply sequence by non-int of type 'float'
4. 나눗셈 ( / )
>>> 3/5
0.6
5. 거듭제곱 ( ** )
>>> 3**3
27
>>> 2**5
32
6. 몫 ( // )
>>> 10//3
3
>>> 5//2
2
7. 나머지 ( % )
>>> 10%3
1
>>> 5%3
2
728x90
'Python' 카테고리의 다른 글
[Python] 자료구조 : 해시(Hash) 개념 및 사용 (0) | 2023.02.17 |
---|---|
[Python] - 자료구조 : 스택(Stack) 개념 및 사용 (0) | 2023.02.13 |
[Python] - 아스키코드 ord(), chr() (0) | 2023.02.03 |
[Python] - 리스트 값 삭제 clear, pop, remove, del (0) | 2023.02.03 |
[Python] - 문자열(string) <-> 리스트(list) 변환 (0) | 2023.02.03 |