Hello Guys!
I've started learning Python on my free time, and i wanted to teach you guys the basics.
Variables:
To declare a variable, its easier than C# and other languages.
All you have to do , is name the variable, and assign a value.
Example:
varA = 1
varB = 1.0
varC = "1"
In this case, we have declared the following.
varA is an integer. varB is a float. varC is a string.
Operators:
+ : This operator adds the value's on both sides of the operator.
Example:
1 + 2
Which will result in 3.
- : This operator substracts the right value, to the left value.
Example:
5 - 3
Which will result in 2.
* : This operator multiplies the value on both sides of the operator.
Example:
4 * 3
Which will result in 12.
/ : This operator will divide the left value, by the right value
Example:
12 / 3
Which will result in 4.
% : This operator will divide the left value, by the right value, and returns the remainder.
Example:
4 % 2
Which will result in 0.
Comparators:
== = If the value on the left side, and the right side are both equal, it returns true. Else, it returns false.
Example:
if varA == varB:
print("varA is equal to varB")
!= = If the value on the left side, and the right side are different, it returns true. Else, it returns false.
Example:
if varA != varB:
print("varA is different than varB")
> = If the value on the left side, is greater than the right value, it returns true. Else, it returns false.
Example:
if varA > varB:
print("varA is greater than varB")
else:
print("varB is greater or equal than varA")
< = If the value on the left side, is lower than the right value, it returns true. Else, it returns false.
Example:
if varA < varB:
print("varA is smaller than varB")
else:
print("varB is smaller or equal than varA")
>= = If the value on the left side, is greater or equal than the right value, it returns true. Else, it returns false.
Example:
if varA >= varB:
print("varA is greater or equal than varB")
else:
print("varA is smaller than varB")
<= = If the value on the left side, is smaller or equal than the right value, it returns true. Else, it returns false.
Example:
if varA <= varB:
print("varA is smaller or equal than varB")
else:
print("varA is greater than varB")
Statements:
if = Used to check wheter a condition is true or false
Example:
if varA == varB:
print("varA is equal than varB")
else = Used to check wheter a condition is true or false, when the IF was false
Example:
if varA == varB:
print("varA is equal than varB")
else:
print("varA is not equal than varB")
elif = Used to check wheter a condition is true or false, when the IF was false, and there are more than two results
Example:
if varA > varB:
print("varA is greater than varB")
elif varA < varB:
print("varA is smaller than varB")
else:
print("varA is equal than varB")
I will post part 2 in the future 🙂