How to check the type of a Python variable

silencement
Release: 2020-09-19 13:08:20
Original
17110 people have browsed it

Methods to view Python variable types: 1. Use type(), the syntax "type(object)", to return the type of variable object; 2. Use isinstance(), the syntax "isinstance(object,classinfo)" , check whether the variable object is a known type.

How to check the type of a Python variable

How Python determines the type of a variable

There are two ways to determine the type of a variable in Python: type() and isinstance()

How to use

For basic data types, both have the same effect

type()

Return the type of object

How to check the type of a Python variable

isinstance()

isinstance() function to determine whether an object is a known type, similar to type() .

How to check the type of a Python variable

The difference

The difference between isinstance() and type() is:
type() The subclass will not be considered to be a parent class type
isinstance() will consider the subclass to be a parent class type

How to check the type of a Python variable

The above is the detailed content of How to check the type of a Python variable. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!