Python의 데이터 유형에는 숫자(int), 부동 소수점(float), 문자열(str), 목록(list), 튜플(tuple), 사전(dict), 집합(set)이 포함됩니다.
일반 다음 방법:
1, isinstance(매개변수 1, 매개변수 2)
설명: 이 함수는 변수(매개변수 1)가 type()
과 유사한 알려진 변수 유형(매개변수 2)인지 확인하는 데 사용됩니다.Parameter 1: 변수
파라미터 2: 직접 또는 간접 클래스 이름, 기본 유형 또는 이들로 구성된 튜플일 수 있습니다.
반환값: 객체의 유형이 매개변수 2의 유형(classinfo)과 동일하면 True를 반환하고, 그렇지 않으면 False를 반환합니다.
예:
#判断变量类型的函数 def typeof(variate): type=None if isinstance(variate,int): type = "int" elif isinstance(variate,str): type = "str" elif isinstance(variate,float): type = "float" elif isinstance(variate,list): type = "list" elif isinstance(variate,tuple): type = "tuple" elif isinstance(variate,dict): type = "dict" elif isinstance(variate,set): type = "set" return type # 返回变量类型 def getType(variate): arr = {"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"} vartype = typeof(variate) if not (vartype in arr): return "未知类型" return arr[vartype] #判断变量是否为整数 money=120 print("{0}是{1}".format(money,getType(money))) #判断变量是否为字符串 money="120" print("{0}是{1}".format(money,getType(money))) money=12.3 print("{0}是{1}".format(money,getType(money))) #判断变量是否为列表 students=['studentA'] print("{0}是{1}".format(students,getType(students))) #判断变量是否为元组 students=('studentA','studentB') print("{0}是{1}".format(students,getType(students))) #判断变量是否为字典 dictory={"key1":"value1","key2":"value2"} print("{0}是{1}".format(dictory,getType(dictory))) #判断变量是否为集合 apple={"apple1","apple2"} print("{0}是{1}".format(apple,getType(apple)))
Return:
2. 알려진 유형 비교
예:
#判断变量类型的函数 def typeof(variate): type1 = "" if type(variate) == type(1): type1 = "int" elif type(variate) == type("str"): type1 = "str" elif type(variate) == type(12.3): type1 = "float" elif type(variate) == type([1]): type1 = "list" elif type(variate) == type(()): type1 = "tuple" elif type(variate) == type({"key1":"123"}): type1 = "dict" elif type(variate) == type({"key1"}): type1 = "set" return type1 # 返回变量类型 def getType(variate): arr = {"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"} vartype = typeof(variate) if not (vartype in arr): return "未知类型" return arr[vartype] #判断变量是否为整数 money=120 print("{0}是{1}".format(money,getType(money))) #判断变量是否为字符串 money="120" print("{0}是{1}".format(money,getType(money))) money=12.3 print("{0}是{1}".format(money,getType(money))) #判断变量是否为列表 students=['studentA'] print("{0}是{1}".format(students,getType(students))) #判断变量是否为元组 students=('studentA','studentB') print("{0}是{1}".format(students,getType(students))) #判断变量是否为字典 dictory={"key1":"value1","key2":"value2"} print("{0}是{1}".format(dictory,getType(dictory))) #判断变量是否为集合 apple={"apple1","apple2"} print("{0}是{1}".format(apple,getType(apple)))
반환:
보충:
isinstance() 및 type() 차이점:
type()은 하위 클래스를 상위 클래스 유형으로 간주하지 않으며 그렇지 않습니다. 상속 관계를 고려하십시오.
isinstance()는 하위 클래스를 상위 클래스 유형으로 간주하고 상속 관계를 고려합니다.
두 유형이 동일한지 확인하려면 isinstance()를 사용하는 것이 좋습니다.
관련 튜토리얼 권장 사항: Python 비디오 튜토리얼
위 내용은 Python은 변수의 유형을 결정합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Arraysinpython, 특히 비밀 복구를위한 ArecrucialInscientificcomputing.1) theaRearedFornumericalOperations, DataAnalysis 및 MachinELearning.2) Numpy'SimplementationIncensuressuressurations thanpythonlists.3) arraysenablequick

Pyenv, Venv 및 Anaconda를 사용하여 다양한 Python 버전을 관리 할 수 있습니다. 1) PYENV를 사용하여 여러 Python 버전을 관리합니다. Pyenv를 설치하고 글로벌 및 로컬 버전을 설정하십시오. 2) VENV를 사용하여 프로젝트 종속성을 분리하기 위해 가상 환경을 만듭니다. 3) Anaconda를 사용하여 데이터 과학 프로젝트에서 Python 버전을 관리하십시오. 4) 시스템 수준의 작업을 위해 시스템 파이썬을 유지하십시오. 이러한 도구와 전략을 통해 다양한 버전의 Python을 효과적으로 관리하여 프로젝트의 원활한 실행을 보장 할 수 있습니다.

Numpyarrayshaveseveraladvantagesstandardpythonarrays : 1) thearemuchfasterduetoc 기반 간증, 2) thearemorememory-refficient, 특히 withlargedatasets 및 3) wepferoptizedformationsformationstaticaloperations, 만들기, 만들기

어레이의 균질성이 성능에 미치는 영향은 이중입니다. 1) 균질성은 컴파일러가 메모리 액세스를 최적화하고 성능을 향상시킬 수 있습니다. 2) 그러나 유형 다양성을 제한하여 비 효율성으로 이어질 수 있습니다. 요컨대, 올바른 데이터 구조를 선택하는 것이 중요합니다.

tocraftexecutablepythonscripts, 다음과 같은 비스트 프랙티스를 따르십시오 : 1) 1) addashebangline (#!/usr/bin/envpython3) tomakethescriptexecutable.2) setpermissionswithchmod xyour_script.py.3) organtionewithlarstringanduseifname == "__"

numpyarraysarebetterfornumericaloperations 및 multi-dimensionaldata, mumemer-efficientArrays

numpyarraysarebetterforheavynumericalcomputing, whilearraymoduleisiMoresuily-sportainedprojectswithsimpledatatypes.1) numpyarraysofferversatively 및 formanceforgedatasets 및 complexoperations.2) Thearraymoduleisweighit 및 ep

ctypesallowscreatingandmanipulatingC-stylearraysinPython.1)UsectypestointerfacewithClibrariesforperformance.2)CreateC-stylearraysfornumericalcomputations.3)PassarraystoCfunctionsforefficientoperations.However,becautiousofmemorymanagement,performanceo


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
