So for this session
what we are going to be doing is
we are going to be checking out for variables, data types, and operators.
now let us go back to our VS code and alright
um I’m going to show you how to actually declare variables in Python.
this is our second second session.
so let’s say for example
you want to actually give maybe your name
name = "akin"
this is a string variable.
now let me say I also want to call my age as a variable
age = 25
this is a number (integer) variable.
now the next thing is
I also want to call maybe a float variable
height = 5.9
this is a float variable.
now let’s take for example I also want to call a boolean type of variable
is_true = True
this is a boolean variable (True/False).
👉 in everything you’ve seen here, we used the assignment operator (=).
Python automatically detects data types.
let me show you the types:
x = 10 # this is an integer (int)
y = 3.14 # this is a float (decimal number)
z = "hello" # this is a string (str)
👉 anything inside quotation marks (single or double) is a string.
person = {
"name": "Hakim",
"age": 25
}
comes in pairs (key: value).
uses curly braces { }.
multi-dimensional, like JavaScript objects.
numbers = [1, 2, 3]
a single dimensional array.
uses square brackets [ ].
coordinates = (4, 5, 6)
also a single dimensional array.
uses normal brackets ( ).
unique_numbers = {1, 2, 3, 4}
uses curly braces { }, but no pairs.
stores unique items.
operators are categorized into groups.
num1 = 10
num2 = 30
👉 = assigns values.
Addition
print("Addition:", num1 + num2) # 40
Subtraction
print("Subtraction:", num2 - num1) # 20
Multiplication
print("Multiplication:", num1 * num2) # 300
Division
print("Division:", num2 / num1) # 3.0
Floor Division
print("Floor Division:", num2 // num1) # 3
Modulus
print("Modulus:", num2 % num1) # 0
Exponent
print("Exponent:", num1 ** 2) # 100
Greater than
print(num1 > num2) # False
Less than
print(num1 < num2) # True
Equal to
print(num1 == num2) # False
Greater or equal
print(num1 >= num2) # False
print(True and False) # False
print(True or False) # True
print(not True) # False
in this section, we learned:
how to declare variables using the assignment operator.
the data types in Python: int, float, string, dictionary, list, tuple, set.
the operators: assignment, arithmetic, comparison, and logical.
the next session (Lesson 3) will be on Control Flow:
conditional statements (if, else, elif)
loops.
see you in the next session.
Not a member yet? Register now
Are you a member? Login now