Variables
Now that you have some idea of what statements are in Python, we can start getting our hands dirty with variables.
Variables are containers for information. We assign values to variables. These variables then hold the values we assign to them for when we need to use or change them later.
You can name a variable almost anything you want.
However, variables must start with a letter
or underscore character
. You cannot start your variable name with a number
!
Variable names can only contain alpha-numeric characters and underscores (A-Z
, a-z
, 0-9
, and _
). You cannot use spaces
in your variable name.
There are also slight differences in the style you define your variables. We will go over some examples below.
In programming, we refer to giving a variable a value assignment.
Example
# Assign a variable named company with a string value
company = "Elispy"
# Use underscores between words in your variable name to write using snake_case
company_name = "Elispy"
# Capitalize the second word in your variable name to write using camelCase
companyName = "Elispy"
# Sometimes, you may want to write in all capital letters for CONSTANTS
COMPANY_NAME = "Elispy"
As a general rule-of-thumb, write your variables in snake_case in Python.