Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBenjamin Hedgepeth
5,672 Pointstype () function in Python
The purpose of using the type() function is to identify the type of data being used. A data type identifies the types of values that are permitted for a particular data type and the type of operations that may be performed.
Given a class is simply a template for creating instances (objects) of that class I'm confused why class is returned from the type() function.
Why does Python return <class 'str'> instead of <type 'str'> when calling this function?
>>> type('hello')
<class 'str'>
1 Answer
justin chow
61 PointsRemember! Everything in Python is Object. Everything you create should belong to some class if itself is not a class.
So, you created something like a = "name" Here a is an object of the class String. Because that's how it's working. Let's just assume that type() function is used to understanding of humans.. and not programs