If you have programed with languages other than Python like C, C++, Java or if you are an oldie then Pascal, you would be used to declaring a variable in a similar format:
*type variableName = value;
☕️*
Python however is interesting; you really don’t need to specify a type(int, string, float…).
So instead you do: *variableName = value
🐍*
Now that I created a variable, its essentially created a space that holds a known or unknown value. Just to clarify, you can define an unknown variable by *var = None*
<aside> 💡 Takeway: Variables are just placeholders for values. If the type of the value is changed then the variable also changes.
</aside>
Common variable types
similar to arrays, these can hold many types of variables. Lists have more functionalities compared to Arrays. However Arrays can be more efficient when working with large data as they don’t exhaust the memory consumption. Here is what you can do with lists:
mylist = []
mylist.append(1)
print(mylist[0])
for x in mylist: #to print out all elements
print(x)
Python follows the human rules when it comes to mathematical order of operations. So it first will do 2*3, then divide by 4.0, and then add the one
number = 1 + 2 * 3 / 4.0
print(number)
The square root in python is indicated through ** sign
squared = 7 ** 2
cubed = 2 ** 3
print(squared)
print(cubed)