#burnsteem || PYTHON PROGRAMMING CLASS (THE BASICS) || DAY 6 - PYTHON OPERATORS | WEEK 1 || 25% @null

in CampusConnect2 years ago (edited)

python class day 6.PNG


Good day everyone!
Hope you're doing great!! Today is the sixth day of the Python Programming class week 1. If you read my first introductory article for week 1, you will know our sixth topic for the day 6 and all we have to cover for day 6. Please if you have not read the first article please do well to read it here so that you will know what we have for each day of the week.

I brought out this idea of teaching python on steemit because of the need for python programming skills in the world of technology today. This is the new trend in tech now because python can be used for various purposes in many applications ranging from web development, automation, artificial intelligence, software testing to many others. I decided to start this programming class on steemit communities because the communities comprise mainly of people who are still eager to learn new skills. Developers and non-developers alike can use this python.

Note: The English language used in this class is literally understandable by a layman. So let's begin...


PYTHON OPERATORS

Operators as the name implies is used to operate on some given input data. In other-words, it is used to perform operations on variables and values. It is used to perform logical or arithmetic operations on operands. We have different types of operators in Python. Let's list the following types of Python operators below.

Types of Operators:

  • Arithmetic operators
  • Logical operators
  • Comparison operators
  • Assignment operators
  • Membership operators
  • Bitwise operators
  • Identity operators

We will start with the first one on the list, which is "Arithmetic operators".


ARITHMETIC OPERATORS
Arithmetic operators is a type of Python operator used in performing mathematical operations on variables and values. And their operations are mainly operated upon numerical values. Arithmetic operators can be used to perform addition, multiplication, division, subtraction operations e.t.c.

Operator Name Description Syntax
+ Addition Adds two operands x+y
- Subtraction Subtracts right operand from the left operand x-y
* Multiplication Multiplies two operands x*y
/ Division Divides left operand by the right one (always results into float) x/y
% Modulus Divides the left operand by right operand and returns the remainder x + y
// Floor division Divides the first operand by the second operand and rounds the quotient to the nearest lowest integer x//y

For Example,

x = 6
y = 2
print("x + y = ", x + y)
print("x - y = ", x - y)
print("x * y = ", x * y)
print("x / y = ", x / y)
print("x % y = ", x % y)
print("x // y = ", x // y)

Output
x + y = 8

x - y = 4

x * y = 12

x / y = 3.0

x % y = 0

x // y = 3

Python Arithmetic operators
python arithmetic operators.PNG
Arithmetic operators on Vs code

From our code in the screenshot above, we have seen the various functions of the arithmetic operators in Python programming.

Note that the division (x / y) operation in our example above results to a floating point value, i.e. 3.0. The floor division (x // y) operation results to a round whole number, i.e. 3. (x % y) returns the remainder of the operation. Others are the normal mathematical operations we know right from our primary school.

NB: Copy the code in the example above and try it out in your text editor. Try this for different separate values for x and y!


LOGICAL OPERATORS
Logical operators include Logical AND, Logical OR, and Logical NOT. They're simply used to combine conditional statements.

Operator Description Syntax
and Logical AND: Returns True if both the conditions are true x and y
or Logical OR: Returns True if either of the conditions is true x or y
not Logical NOT: Returns True if the condition is false, and returns False if the condition is true (reverse the result) not x

For Example,

x = 6 > 2
y = 3 > 1
print(x and y)
print(x or y)
print(not(x and y))

Output
True
True
False

Python logical operators
python logical operators.PNG
Logical operators

From the code above, we can see that:

  • (x and y) returns True because 6 is greater than 3 and 3 is also greater than 1.
  • (x or y) returns True because 6 is greater than 3 or 3 is greater than 1 i.e. either of the condition is true.
  • (not(x and y)) returns False because as we have already seen in the AND operation, the result returns True, so negative of True is False, hence the result False.

NB: Copy the code in the example above, and try it out in your text editor. Please make sure to do it for other values respectively, i.e. change the 6, 3, and 1 for other values like 5, 7, 89, 4, and so on...



COMPARISON OPERATORS
Comparison operators are simply used to compare two given values, and it returns True or False according to the condition.

Operator Name Description Syntax
> Greater than Returns True if the left operand is greater than the right one x>y
>= Greater than or equal to Returns True if the left operand is greater than or equal to the right one x>=y
< Less than Returns True if the left operand is less than the right x<y
<= Less than or equal to Returns True if the left operand is less than or equal to the right x<=y
== Equal to Returns True if both operands are equal x==y
!= Not equal to Returns True if the two operands are not equal x!=y

For Example

x = 7
y = 20
print("x > y: ", x > y)
print("x >= y: ", x >= y)
print("x < y: ", x < y)
print("x <= y: ", x <= y)
print("x == y: ", x == y)
print("x != y: ", x != y)

Output
False
False
True
True
False
True

Python comparison operators
python comparison operator.PNG
Comparison operators

From our code above, we can see that:

  • (x > y) returns False because 7 is not greater than 20
  • (x >= y) returns False because 7 is not greater than or equal to 20
  • (x < y) returns True because 7 is less than 20
  • (x <= y) returns True because 7 is less than or equal to 20
  • (x == y) returns False because 7 is not equal to 20
  • (x != y) returns True because 7 and 20 are not equal

NB: Copy the code in the example above and try it out in your text editor. Please make sure to practice along as that is the only way to learn programming fast. Change the values used in this example during your own practice.



ASSIGNMENT OPERATORS
This operator is used for assigning values to a variable.

Operator Syntax Same As
= x = 7 x = 7
+= x += 7 x = x + 7
-= x -= 7 x = x - 7
*= x *= 7 x = x * 7
/= x /= 7 x = x / 7
%= x %= 7 x = x % 7
//= x //= 7 x = x // 7
**= x **= 7 x = x ** 7
&= x &= 7 x = x & 7
|= x |= 7 x = x | 7
^= x ^= 7 x = x ^ 7
>>= x >>= 7 x = x >> 7
<<= x <<= 7 x = x << 7

For Example,

x = 10
print(x)

Output
7


x = 10
x = x + 7
print(x)

Output
14


x = 10
x = x - 7
print(x)

Output
3


x = 10
x = x | 7
print(x)

Output
15


x = 10
x = x // 7
print(x)

Output
1


x = 10
x = x << 7
print(x)

Output
1280

The (x = x << 7) assignment operator
python assignment operators.PNG
The (x = x << 7) assignment operator

NB: Please for the sake of time and space, we cannot show the screenshot for all the assignment operators in our text editor here. But please try and check them out one by one in your text editor. Meanwhile, if you want to learn more about Python operators click here or here.



MEMBERSHIP OPERATOR
This operator is used to check if the given value is present in the sequence of values, and if it is present or not, it returns True or False. The two member operators are "in" and "not in".

Operator Description Syntax
in Returns True if the value/variable is found in the sequence x in y
not in Returns True if the value/variable is not present in the sequence x not in y

For Example,

x = [1, 2, 3, 5, 6, 7]
print(3 in x)

Output
True

python member operators.PNG

Note: It returns True because 3 is present in the list of integer numbers given in the example above.


x = [1, 2, 3, 5, 6, 7]
print(20 not in x)

Output
True

python membership operators.PNG

Note: It returns True because 20 is not present in the list of integer numbers given in the example above.

NB: Copy the code in the example above and try it out in your text editor. Please practice more with other list of numbers. Meanwhile, if you want to learn more about Python operators click here or here.



BITWISE OPERATORS
They operate on binary digits. They perform bit-by-bit operations in a program. This operators act on the binary equivalent of the operands as if they were strings of binary digits. For example 1 in binary is 0001, 4 in binary is 0100. I know you may not understand this particular one, but if you want to have more understanding on bitwise operations in computer click here or here.

Operator Name Description Syntax
& Bitwise AND Sets each bit to 1 if both bits are 1 x & y
| Bitwise OR Sets each bit to 1 if one of the two bits is 1 x | y
~ Bitwise NOT Inverts all the bits ~x
^ Bitwise XOR Sets each bit to 1 if only one of two bits is 1 x ^ y
>> Bitwise right shift Signed right shift x>>
<< Bitwise left shift Zero fill left shift x<<

For Example,

x = 6
y = 4
print(x & y)
print(x | y)
print(x ~ y)
print(x ^ y)
print(x>>)
print(x<<)

Output
4
6
-7
2
0
48

Python bitwise operators
python bitwise operators.PNG

The screenshot above shows the bitwise operations performed on the operands and their respective outputs.

NB: Copy the code in the example above and try it out in your text editor. I know this particular operator is a bit technical and not friendly but please make use of the following articles to learn more about the bitwise operations in computer.
Article 1 or Article 2.



IDENTITY OPERATOR
Identity operators are used to check if two values are located in the same memory location, and returns True or False. The identity operators used to achieve this are "is" and "is not". However, they are used to compare objects, not if they are equal, but if they are actually the same object referring to a value stored in the same part of the memory.

Operator Description Syntax
is True if the operands are identical (refer to the same object) x is True
is not True if the operands are not identical (do not refer to the same object) x is not True

For Example,

x = 5
y = 5
print(x is y)
a = "Anyiglobal"
b = "Anyiglobal"
print(a is not b)

Output
True
False

Python Identity operator
python identity operator.PNG
Identity operator

From the code in the screenshot above, we can see that:

  • (x is y) returns True because x and y refers to the same value in the same memory location, i.e. The operands are identical
  • (a is not b) returns False because the two operands are identical.

NB: Copy the code in the example above and try it out in your text editor. Meanwhile, you can learn more about Python operators to have broader knowledge of the topic here or here.

NB: THE EASIEST WAY TO LEARN IS TO PRACTICE ALONG.



Conclusion

In conclusion, we can say that Python operators is very crucial in python programming. They are used to perform many programming operations ranging from arithmetic operations to identity operations. As a programmer, you need to have a better knowledge of Python operators. I will advice you to always practice along with the teacher during every class so that you won't miss any bit of the information passed. Thank you very much and God bless you!



This is the end of this particular class. I believe that if you followed this class till the end, you must have grabbed one or more information from the class. Please make sure to practice along with your laptop and text editor to grab every bit of the information passed. Please I am so sorry that I didn't follow my course outline accordingly, please pardon me, it won't repeat itself in week 2.

Please do well to follow this blog, and also don't forget to resteem this post so that it can reach larger number of steemians who wants to learn this skill. Thanks very much to @steemcurator01 and @steemcurator02 for their constant support! Visit here to see the topics we have for this week.


Am glad you participated in this class! I believe you have learnt something new today.

I am @anyiglobal, a Computer Scientist, Software Engineer and a Blogger!



Cc:
@campusconnectng, @whitestallion, @kouba01, @pelon53, @reminiscence01, @steemchiller, @justyy

Sort:  
Your post has been successfully curated by our team via @fredquantum at 40%. Thank you for your committed efforts, we invite you to do more and keep posting high quality posts for a chance to win valuable upvotes from our team of curators and probable selection for an additional upvote later this week in the Top Seven. That being said, you should stop tagging the curators (SC01/SC02) in your articles, it's considered spamming.

received_388032689541375-1.jpeg

Note: You must enter the tag #fintech among the first 4 tags for your post to be reviewed.

Your post is manually rewarded by the @nftmc Community Curation Trail.


Join the NFTMC community to get rewarded.

USE TAG - #nftmc

Curation Trail- @nftmc
Discord- https://discord.gg/5P57gwYYcT
Twitter- https://mobile.twitter.com/NFTMC3

 2 years ago 

Thanks for your support

 2 years ago 

@anyiglobal, Thanks for sharing with us on @campusconnect , Continue sharing your quality contents with us here we love and appreciate your effort ,Thanks

REMARKS;

Plagiarism-freeYES
#steemexclusiveYES
#club5050YES
DelegationNO
Bot-freeYES
BENEFICIARYNO

 2 years ago 

Please permit me to correct you, I am a 500SP delegator on campusconnect. Thank you!

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.034
BTC 64333.84
ETH 2760.35
USDT 1.00
SBD 2.65