Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


type () 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

Remember! 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