Variables are named locations in memory used to store data. In this example we show how to create one, update it to a new value and then print it.

pythonVariables.png - 11/2015

Unlike many programming languages, Python does not require us to specify the data type of a variable when we create it.   However there are circumstances when we need to have all variables in the same type for example when printing. To cast between datatypes we can use the following commands:

  • Convert x from anything to a string = str(x)
  • Convert x from anything to a int = int(x)
  • Convert x from anything to a float = float(x)

Read more about standard variable types

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.