In this series on Python, we've covered what Python is, installed software, and worked with operations. Now,
we'll be discussing variables.
What is a Variable?
A variable is a container where you can store values. For example, we can store 2 in a variable called "x".
Variables are useful because they allow us to change the value of the container, and we can use them in
operations. For instance, if we have x = 2 and y = 3, we can add them together: x + y = 5.
Variables can store different types of values, such as integers and strings. We don't need to define the type of
the variable since it automatically takes the value of whatever we assign to it.
Using Variables in Operations
We can use variables in operations just like we do with numbers. For example, we can change the value of x
from 2 to 9.
We can also use underscores to represent the output of the previous operation. For example, if we add x + 10,
we can use the output of that operation (19) in another operation: 19 + y = 22.
We can also fetch individual characters from a string stored in a variable using square brackets. The numbering
of characters starts at 0. For example, the first character of "youtube" is "y" and the last character is "e". We
can also use negative numbers to start counting from the end of the string.
Working with Strings in Python
Let's start by looking at how to access specific characters in a string using index values:
To access the first character, we use index 0.