In real life, different companies design different designer bags. All of these have different characteristics but all have the same objective; carrying and storing things. In Python, variables act like the designer bags and are the fundamental of every other topic within Python. Variables store all sorts of data: text, numbers, booleans (true and false values) and so much more. They all have their own names, just like how designer bags have their own distinct designs, which allows for the data they are carrying to be used.
Example:
country = "USA"
age = 20
is_single = True
etc...
A variable must have two attributes. It must contain it's name on the left side of the equals to sign and it's value or the data it's carrying on the right side of the equals to sign.
Example:
show = "friends"
Variables are honestly this basic, however, there are some things we must take note of when working with variables. First of all, if a variable is assigned an operation, then the operation will be completed and that will be the value of the variable.
Example:
my_number = 40 + 2
#here, the result of my_number will be 42
Additionally, there are rules to naming variables which we must keep in consideration while naming variables. The most common way to name a variable with many words is to put an underscore between the words which make up the variable's name.
Example:
southern_europe = "italy, spain, malta and turkey"
#here, the words "southern" and "europe" have been seperated by an underscore.
While naming a variable, the name cannot start with a number at the very beginning of the name, so as the first letter. Additionally, variable names cannot contain spaces. Both of these issues will result in errors.
Example:
1st_letter = "A" # will give an error
north america = "The USA and Canada" # will give an error
Although it may seem unrelated to variables, an important thing a beginner in Python must know is the print function. When you type something (say, a variable) in between the print function, it will output the value of the variable directly to the screen, as demonstrated below:
food = "Pizza"
print(food)
Output:
"Pizza"
You have been searching for a brand new job all over the place, and luckily for you, your application as a software developer for your local tech startup has been accepted! Now, they want you to give your creditentials to them, but in a way a true programmer would. They want you to write down all of your information in the way of variables and send them the code so they can get to know you even further. You must send them a code file which contains variables with regards to:
1 - Your name
2 - Your age
3 - Your gender
4 - Your city
5 - Your field
6 - Years in field
7 - How you work (remotely or in person)
It's your job to write down the code that you will send the company later.
Please type all code on your preferred code editor
Please note that this is just a suggested answer and any code which completes the same function is valid
name = "David Green"
age = 28
gender = "Male"
city = "Seattle"
field = "Industrial engineering"
years_in_field = 4
works_remotely = True
You have reached the end of Section 1: Variables!