Python Values – Know the Type

Python values are basic things the language works with. Python values belong to different types. Use the Python interpreter to ask for the type of a given Python value.

Below are examples of input and output from asking Python for types of various Python values. The chevron prompt “>>>” is input for Python, and the line below is output from Python.

>>> type('Cookies')
<type 'str'>

>>> type(3)
<type 'int'>

>>> type(3.0)
<type 'float'>

>>>type('3.0')
<type 'str'>

 

The first type means string. After that it’s, integer, floating number, and string. Notice that if you put quotations around a number, it becomes a string.

While it might be habit, refrain from using commas with large numbers. It will cause a semantic error, because Python would interpret it as a comma separated sequence of numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *