Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 2 KB

003-Variables.md

File metadata and controls

50 lines (36 loc) · 2 KB

Variables in Python

Python is a dynamically typed programming language meaning that you do not need to tell the script or program exactly what type of value a variable holds. There are many types of 'values' which we discuss in the values chapter. A variable holds onto information using a key word. You can find a word, and assign information to that word, and then call upon that word multiple times for use throughout the program.

How to make a variable

A variable is created by giving it a name and then assigning its contents to it with a single equals sign, for example:

example = "value"

What information can variables hold?

Variables can hold several different types of values and information, each of which will have its very own chapter in the coming series, however here they are in simple bullet form.

  • Intergers
  • Floats
  • Strings
  • Boolean

What can be the value of a variable be used for?

Variables can be called upon in order to use the values for various parts of a program, depending on how you intend to use the information. Mathematics is one of the main uses of variable values, but there are many things we can use the stored information for.

How to format a variable

Variables should stick to specific formatting rules, so that your code not only works, but can also be read by other users. To assign a variable, remember that the letters are CASE SENSITIVE. So:

cat = "paws"

is completely different to:

Cat = "paws"

Variables should always start with a letter, can never have an empty space and can contain numbers. If spaces are needed to make the variable more understandable use an underscore like this example:

my_first_variable = "I did it!"

For strings, add quote marks around the string (see string chapter for more info on this.) For numbers there is no need for quotes, for example:

numbers = 132
more_numbers = 567
even_more_numbers = 3.5632
and_again = 1
string = "Strings have single or double quotes around them"