250x250
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
| 29 | 30 | 31 |
Tags
- 자료구조
- 어플리케이션 클래스 로더
- 컴포넌트 스캔
- 파이썬
- 코딩테스트
- Spring
- java
- 백준
- 알고리즘
- AWS SAA-C03 합격후기
- getreference
- 플랫폼 클래스 로더
- BFS
- 스프링 컨테이너
- 스프링
- 파이썬 리스트 메서드
- dfs
- python
- 딕셔너리
- 부트스트랩 클래스 로더
- stop the world
- 객체지향
- 다이렉트 레퍼런스
- 자바
- 클래스 로더 계층
- 2026 AWS SAA-C03
- 파이썬 문자열 메서드
- aws saa-c03
- 심볼릭 레퍼런스
- python list method
Archives
- Today
- Total
클라우드 낚시꾼
파이썬 타입 판별 방법 (정수 판별, 실수 판별 등등) 본문
728x90
파이썬 주어진 데이터의 타입을 판별하는데는 다양한 방법이 있다. 가장 일반적인 방법 3가지를 알아보자.
type() 함수를 이용해 타입 확인하기
num = 42
print(type(num)) # <class 'int'>
num_float = 3.14
print(type(num_float)) # <class 'float'>
isinstance(확인하려는 데이터, 타입 or 타입 튜플)를 활용
y = 3
if isinstance(y, int):
print("integer")
else:
print("float") # here
string = "hello!"
if isinstance(string, (int,str,list)):
print("match") # here
else:
print("no-match")
int()를 이용해 정수 판별하기
x = 3
if x == int(x):
print("integer") #here
else:
print("float")728x90
'Programming Language > Python 활용' 카테고리의 다른 글
| [Python3] 딕셔너리 정렬하기 with lambda (0) | 2024.03.20 |
|---|---|
| [Python3] Python 출력문 정리 (0) | 2024.03.15 |
| [Python3] Python 대소문자 관리 (upper, lower) (0) | 2024.03.15 |
| [파이썬] 리스트 곱은 요소를 반복한다. (0) | 2024.01.24 |
| [파이썬] 문자열 join 메서드 사용법 + 예제 (0) | 2024.01.24 |