Now that we understand the basic workflow of python (create code in text editor → execute in command prompt), we can start discussing the different functions and capabilities of Python. We can start this discussion with variables. You can think of variables as the objects that store information for our program. A variable has two basic parts; '''A name''' (which we will use to refer to the variable) and '''A value''' (the info we care about). Besides those two parts, variables can hold different types of information.
'''Types Of Variables
#Strings - A sequence of characters (ex: "Python is fun!")
#Integers - Whole numbers (ex: 3, 10, 999)
#Floats - Numbers w/ a decimal (ex: 1.0, 3.14, 7.77)
#Lists - An sequential list of other variables (floats, integers, strings, more lists, or a mix) (ex: ['cat', 'dog', 999, 3.14, variable1])
One of the great features of Python is that the built in compiler can intelligently figure out what type of variable your specified variables should be and takes care of this distinction '''automatically'''. This means defining variables is easier in Python than some other languages you may be familiar with. We define a variable by writing its name, followed by an equal sign, followed by the value of the variable (ex: pi=3.14, name="Dylan", eq="3+4"). We can also define variables without setting the values immediately. To do this we need to tell the compiler what type of variable we need (since it can't figure it out automatically) (ex: int pi, str myName)
Important Note: The standard naming convention of variables follows: The first word is always all lowercase then the proceeding words begin with an uppercase letter (ex: myVariable, reallyAwesomeInteger). You don't need to follow this convention, but it is worth knowing.
To update a variable (change it's value later on in the code) we simply need to redefine it's value. You can do this by:
variableName = [new value]
When we get into more complex implementations our variable type will become very important. Ask yourself 'what is the difference between these two codes?'
*int("1964") → 1964
== Other Educational Resources for Python ==
The official Python Documentation - https:/ /docs. python.org/3/* Tutorials - https://thepythonguru.com* Challenging Math/Computational Problems - https://projecteuler.net