Skip to Content
Learn Python by Building Data Science Applications
book

Learn Python by Building Data Science Applications

by Philipp Kats, David Katz
August 2019
Beginner
482 pages
12h 56m
English
Packt Publishing
Content preview from Learn Python by Building Data Science Applications

The type function

The type function returns the type of variable that was passed to it. As in the following example, for the string variable, it will return str; for the number variable, int or float, and so on and so forth: 

>>> type(‘Hello world')str

Here, the function returns the type of the Hello world value, which is a string. This function allows us to differentiate between values, even if this is not very clear. Take a look at the following example:

>>> type(101)int>> type('101')str

Here, type identifies the fact that similar looking values are an integer and a string. Often, however, we don't need to know the specific type of the value, but rather whether the value is of a certain type (and adjust our methods accordingly). For this, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Data Science

Python for Data Science

Yuli Vasiliev
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789535365Supplemental Content