1/7
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress

Implicit Type Conversion
Implicit type conversion takes place at run time/ it is performed by python interpreter only/ automatic conversion of one data type into another takes place
THIS IS USED TO CONVERT VALUES
Example
convert integer to float/ do this by adding integer to a float
Num1 = 85
Num2 = 15.5
Add = num1 + num2
Print(add)
Print(type(add))
Output:
100.5


Explicit type conversion
Converting a value from one data type to another(manually) using built in functions such as tuple(), list(y), set(y), dict(y), ord(y), etc…
Example
Num1 = 85
Num2 = “55”
Print(“Data type of num1:” type(num1))
Print(“Data type of num2 before type casting:” type(num2))
Num2 = int(num2) //type casting
Print(“Data type of num2 after type casting:”, type(num2))
Add = num1 + num2

Data operators
Arithmetic operators
Addition+ /subtraction- /multiplication* division/ /modulus%/exponent**
Comparison(relational) operators
Assignment operators
Bitwise operators

Arithmetic operators - basic math to perform calculations
Addition + : it is used to find the sum of two numbers : num1 = 25 num2 = 15
num1+num2=40
Subtraction - : it is used to find the difference of two numbers : num1 = 25 num2 = 5
num1-num2 = 5
Multiplication * : it is used to find the multiplication of two numbers : num1 = 30 num2 = 3
num1*num2 = 90
Division / : it is used to find the divided result of 2 numbers : num1= 100 num2= 5
num1/num2 = 20
Modulus % : it is used to find the remainder of 2 numbers// divide first/ whatever the remainder is of the division is the answer
num1 = 50 num2= 20
num1%num2 = 10
Exponent ** multiply the base number by itself the number of times of the exponent
num1 = 5 num2= 7
num1**num2 = 78,125
Integer divide // divides the two values and only gives you the integer result, excludes the decimal result
x=50;y=4
x // y
12… actual answer is 12.5

Comparison operators - symbols used in math and programming to compare two values and return a Boolean result(true or false) = > < !
if both values are equal == // true
num1 = 25 num2 = 15
(num1 == num2) is false
if both values are not equal != // true
num1 = 25 num2 = 15
(num1 != num2) is true
if left operant is greater than right operant > // true
num1 = 25 num2 = 15
(num1 > num2) is true
if left operant is less than right operant < // false
num1 = 25 num2 = 15
(num1 < num2) is false
Greater than or equal to left operator >=
num1 = 25 num2 = 15
(num1 >= num2) is true
Less than or equal to operator <=
num1 = 25 num2 = 15
(num1 <= num2) is false

Assignment operator - this operator is used to assign values to the operands
= + - / % ** *
Equal to operator // =
It is used to assign values from right side operands into left side operands
num3 = num1 + num2 // assigns value of num1/2 into num3
Add AND operator // +=
It is used to add the value of the right operand to the left operand and assign the result to the left operand
num1 += num2 is equivalent to
num1 = num1 + num2
subtract AND operator // -=
It is used to subtract the value of the right operand from the left operand and assign the result of the left operand
num1 -= num2 is equivalent to
num1 = num1 - num2
Multiply AND operator *=
It is used to multiply the value of the right operand with the left operand and assign the result to the left operand
num1 *= num2 is equivalent to
num1 = num1 * num2
Divide AND operator /=
It is used to divide the value of the left operand with the right operand and assign the value to the left operand
num1 /= num2 is equivalent to
num1 = num1 / num2
Modulus AND operator
It is used to take the modulus using two operands and assign the result to the left operand
num1 %= num2 is equivalent to
num1 = num1 % num2
Exponents AND operator
It is used to perform the exponential(power) calculation on operators and assign the value to the left operand
num1 **= num2 is equivalent to
num1 = num1 ** num2
Bitwise operator - this operator is used to perform bit by bit operation & | ^ ~
Bitwise - example
num1 = 15 num2 = 8
Binary form will be
num1 = 00001111
num2 = 00001000
Divide your number by 2 until you get to the smallest number. However many times you divided it, is how many bits it is. look for the remainder after division and mark it 1, if there is no remainder mark it 0
Example - 15(odd number each division)
1111
Binary AND operator // &
This operator is used to copy a bit to the result if it exists in both operands. That means 1 AND 1 = 1
(num1 & num2) = 0000100
Binary OR operator // |
It Is used to copy a bit if it exists in either operand. That means 1 OR 0 = 1, 1 OR 1 = 1, 0 AND 1 = 1
(num1 | num2) = 00001111
Binary XOR operator // ^
It is used to copy the bit if it is set in one operand but not both. That means
1^1 = 0
Binary ones complement operator // |
It is unary and flips the values
(~num1) = 11110000