Python Programming Language
Variables in Python
By Mark Ciotola
First published on February 27, 2019
Data Types and Variables
Programs manipulate and display data and information. Computers ultimately work with numbers, but words can be represented by numbers. High level computer programming languages translate words to and from numbers, so if you want to use words, you can usually do so without bothering with numbers. Most programmers will want to use both.
Some information does not change in a computer program. That information is called a constant. Words can be constants, but usually the term is applied to numbers, such as 7 (days in a week) or 12 (months in a year). Items that do change, such as days in a month or the current sum of a financial account, are called variables.
Variables are represented by names, such as MyDate or CurrentSum. There are rules about what names can be used.
In some programming languages, a variable must be declared and a type must be assigned before using it. In Python, variables are dynamically typed, which means that Python will guess what type is best based upon how you use it. You will often need to pay attention to this.
Python names must start with a letter or an underscore (“_”). Python variables should not start with a number, although they can contain numbers. Python variables are case sensitive, so “MyVariable” is not the same as “myvariable”.