Python Type Function with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-type-function-examples/
PINTEREST
PINTEREST
INSTAGRAM

Python provides a lot of different types for programming purposes. While using these structs we may need to decide which variable or identifier is which type. Python provides builtin type function in order to decide given identifier types. We just need to provide the identifier to the type function.

Identify Type

We will provide our identifier or variable like below and type function will return related type.

We can see that name is a string object or class type

Check Type

We can check type returned types with is keyword. We will first provide type function and its parameter identifier or variable and than put is and as the latest type we want to check. In this example we will check if given identifier is string. This will return a boolean result like True or False .

Is List

We can check whether given identifier or variable is a list like below.

Is Dictionary

We can check whether given identifier or variable is a dictionary like below.

Is String

We can check whether given identifier or variable is a string like below.

Is Integer

We can check whether given identifier or variable is a integer like below.

LEARN MORE  How To Get Length and Size Of The List In Python?

Is Object

We can check whether given identifier or variable is a object like below.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-type-function-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)