0% found this document useful (0 votes)
3 views1 page

49 The Python Type

The document explains how Python's 'type' function can be used to determine the type of variables and function returns. It provides examples showing the types of a string, integer, and NoneType. The author shares a personal experience of using this feature to troubleshoot database issues.

Uploaded by

bhavishmatli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

49 The Python Type

The document explains how Python's 'type' function can be used to determine the type of variables and function returns. It provides examples showing the types of a string, integer, and NoneType. The author shares a personal experience of using this feature to troubleshoot database issues.

Uploaded by

bhavishmatli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The Python Type

You may not know this, but Python may just be your type. Yes, Python can tell
you what type of variable you have or what type is returned from a function.
It’s a very handy little tool. Let’s look at a few examples to make it all clear:

x = "test"
y = 7
z = None

print(type(x))
# <class 'str'>

print(type(y))
# <class 'int'>

print(type(z))
# <class 'NoneType'>

As you can see, Python has a keyword called type that can tell you what is
what. In my real-life experiences, I’ve used type to help me figure out what is
going on when my database data is corrupt or not what I expect. I just add a
couple lines and print out each row’s data along with its type. This has helped
me a lot when I’ve been dumbfounded by some stupid code I wrote.

You might also like