Variables

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 https://docs.python.org/2/library/stdtypes.html

About CDB 361 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


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