Learn to program

 
  Finch assignments ::

 

 

 
 

What are variables?


Variables are names given to data that we need to store and manipulate in our programs.


For instance, suppose your program needs to store the speed that a robot must go.

..........You can name this data roboSpeed,  and define the variable roboSpeed using the following statement:
........................................roboSpeed = 0.5


Your program will store the variable name in a certain area in the storage space, and will store the value in a
different area in the storage space. You can then access and modify this data by using its name, roboSpeed.


You can also define multiple variables in one go:
................................roboSpeed, roboTime = 0.5, 8
This means that
................................robotSpeed = 0.5
................................roboTime = 8

A variable name in Python can only contain letters, numbers   or underscores.  Just remember that the first character
can’t be a number. So you can call your variables roboSpeed, robo_speed or roboSpeed2, but not 2robotSpeed.


You should also not use reserved words that already have meanings in the Python language. These reserved words
include print, input, if, while etc.


Variable names are case sensitive – username is not the same as userName.


There are two main conventions used for variable names in Python: camelbacking or using underscores.
CamelBacking or camel case is the practice of writing compound words with mixed cases, eg thisIsAVariableName.

You could also use underscores to write this_is_a_variable_name

Back to lesson 6

Partially plagiarized from the book 'Learn Python in One day and Learn it Well'.