Primitive data types

The following table provides an overview of the most frequently used primitive data types in Python.

Variable type Example Usage comment
bool life_is_good = True hamsters_are_evil = False true/false values
int long size_of_shoes = 42 earth_population = 7000000000 various whole digits
float pi = 3.14159265359 not whole digits - with one or more signs after a dot
str chinese_hi = "嗨" any text
None my_new_book = None empty variable without any meaningful value

As you can see all primitive data types can be stored in a variable using an assignment operator: =.

When large text blocks need to be stored within Python code you may use multiline strings:

long_text = """ Line one
Line two
Line three
Line Four
"""

As you may see a multiline string is a normal string enclosed by triple quotes instead of single ones.

In Python it is possible to convert strings to integers and integers to strings:

>>> str(100)
'100'

>>> int("234")
234

Note, it is completely legal to use double " or singular ' quotes to denote string values. They are completely interchangeable. The only must is that the quotes must match.

E.g. the following ones are valid strings:

one = "foobar"
two = 'zooloo'
three = """long foobar"""
four = '''long zooloo'''

meanwhile the ones below are not:

one = "foobar'
two = '''zooloo"""

The following ones are legal strings though:

one = "'foobar'"
two = '"zooloo"'

It is just that their values include the respective quotes:

>>> print(one)
'foobar'

>>> print(two)
"zooloo"

Quiz

  1. What is the name of this = operator?
  2. How to convert a digit 3.14 into a string '3.14'?
  3. Whats wrong with the following piece of code: variable = "john smith'?
  4. What about this one: variable = "foobar"""

Quiz answers

  1. assignment operator
  2. str(3.14)
  3. singular and double quotes do not match each other
  4. the number of quotes does not match