Values and Data TypesΒΆ

A value is one of the fundamental things — like a word or a number — that a program manipulates. The values we have seen so far are 5 (the result when we added 2 + 3), and "Hello, World!". We often refer to these values as objects and we will use the words value and object interchangeably.

Note

Actually, the 2 and the 3 that are part of the addition above are values(objects) as well.

If you are not sure what class a value falls into, Python has a function called type which can tell you.




(ch02_1)

Not surprisingly, strings belong to the class str and integers belong to the class int.

Note

When we show the value of a string using the print function, such as in the third example above, the quotes are no longer present. The value of the string is the sequence of characters inside the quotes. The quotes are only necessary to help Python know what the value is.




(ch02_2)

What about values like "17" and "3.2"? They look like numbers, but they are in quotation marks like strings.




(ch02_3)

They’re strings!

Strings in Python can be enclosed in either single quotes (') or double quotes ("), or three of each (''' or """)




(ch02_4)




(ch02_5)

Triple quoted strings can even span multiple lines:




(ch02_6)




(ch02_7)

Next Section - Type conversion functions