
Strong Typing 이란?
Python은 object에 대해 Strong Typing을 채택하고 있다.
이는 Object가
mutable type이냐 immutable type이냐에 상관없이
implicit type conversion이 엄격하게 제한됨을 의미한다.
좀더 정확하게는 서로 다른 type의 object 간 연산 시 암묵적 변환이 제한됨
주의할 건, Object가 대상인 점이다.
Strong Typing을 채택한 Python에서의 관련 특징은 다음과 같음:
- 자동 변환 제한:
- Python은 정수와 부동소수점(float) 간의 연산처럼 안전한 변환만 자동으로 수행.
- 하지만 정수와 문자열처럼 다른 종류의 타입 간의 변환은 자동으로 이루어지지 않음.
- 명시적 변환 필요:
- 다른 타입 간의 연산이나 변환이 필요할 때 Explicit Casting이 요구됨.
- 유효하지 않은 변환은 오류 발생:
- 잘못된 변환 시 TypeError 또는 ValueError가 발생.
Python에서 Object란
Python에서 Object는 memory에 할당된 일종의 데이터 덩어리(chunk)로 최소한 다음을 가지고 있어야 한다.
1. Value
2. Unique ID (CPython에선 memory address) : id(target_obj)
3. Type (type에 의해 같은 value라도 다르게 해석됨) : type(target_obj)
4. Reference Count (Garbage Collection을 위해 필요.) : sys.getrefcount(target_obj)
동시에, Python 을 dynamically typed language이기 때문에
variable의 경우 type과 함께 선언되지 않고도 사용가능하며,
중간에 다른 type의 object를 자유롭게 reference할 수 있다.
Python에서 객체에 대한 정보를 확인하는 방법은 다음을 참고: https://ds31x.tistory.com/404
[Py] 객체(object)에 대한 정보 확인하기
Python에서 object(객체)란?type, id, refcount, value 를 속성으로 가지고 있는 a chunk of data.https://dsaint31.tistory.com/517 [Python] Variable (and Object)Variable (and Object)1. 정의Python에서 Variable은 Memory에 할당된 Object를
ds31x.tistory.com
결론
요약하면,
- Strong Typed 라는 관점은 Object에 대한 것으로 그들간의 연산에 적용되는 규칙에 대한 것이며,
- Dynamic (Typing) Language라는 관점은 Variable에 대한 것이다.
같이보면 좋은 자료들
Magic lies here - Statically vs Dynamically Typed Languages
Type Checking
medium.com
2023.06.11 - [Programming] - [Python] Dynamic Language vs. Static Language
[Python] Dynamic Language vs. Static Language
Python은 대표적인 dynamic (typed) langauge 이다. (dynamic language는 대부분 interpreter language 임.) 좀 더 엄밀하게 애기하면,Dynamic Language란 특정 동작이나 사항들이 runtime(실행 시간)에 결정되는 특징을 가
dsaint31.tistory.com
https://dsaint31.me/mkdocs_site/python/oop/oop_0_01_Object/#object
BME
object Object (객체) 란 보거나 만질 수 있는 사물 (공간을 차지하고 있는 물질적인 사물) OOP에선 Concept(개념) 도 Object 임. Application(응용프로그램)에서, 명확한 한계와 의미를 가지고 있는 사물 이나
dsaint31.me
Typing: dynamic vs. static and strong vs. weak
타입 검사는 프로그램의 type safety를 보장하기 위한 장치이며, 언제(컴파일/실행 시점) 검사하느냐와 얼마나 엄격하게 검사하느냐에 따라 프로그래밍 언어가 분류됨:Static vs Dynamic: 언제 타입을
ds31x.tistory.com
[Python] Programming Language and Introduction of Python.
Computer and Programhttps://dsaint31.tistory.com/436: computer 의 정의와 program 의 정의 [CE] Computer and Program.1. 정의: 개인적으로 선호하는 Computer의 정의는 다음과 같음 (wikipedia).A computer is a machine that can be program
ds31x.tistory.com
'Programming' 카테고리의 다른 글
| [Python] importlib.reload : module 재적재 (0) | 2023.06.18 |
|---|---|
| [Python] Exception 처리 (0) | 2023.06.16 |
| [Python] Variable (and Object) (0) | 2023.06.13 |
| [Python] Arithmetic in Python and Augmented Assignment (0) | 2023.06.12 |
| [Python] (Data) Type: Summary (0) | 2023.06.12 |
