New Training: Python Operators
In this 6-video skill, CBT Nuggets trainer Ben Finkel covers the four types of operators available in the Python language: Arithmetic, Logical, Relational, and Bitwise. Gain an understanding of what a programming language is and why they work the way they do. Watch this new Programming and Development training.
Learn Programming and Development with one of these courses:
This training includes:
- 6 videos
- 50 minutes of training
You’ll learn these topics in this skill:
- Python Operators
- Assignment Operator
- Arithmetic Operators
- Relational Operators
- Combination, String, and Bitwise Operators
- Making Change
What is a Logical Operator?
All programming languages have logical operators. Logical operators are an important way for programming languages to work with multiple data sets. So, what is a logical operator?
A logical operator is your 'And or 'Or' keywords. They are commonly used with comparison operators. More often than not logical operators, when used with comparison operators, are used to control the flow of a program.
For instance, let's say that you have two variables: X and Y. Both X and Y have a value of 0. You want to check to see if both variables have the same value (in this case 0) and if they do, do something.
Let's look at this in pseudo code:
If (X == 0 AND Y==0) Then doSomeThings…
In this case, doSomeThings will only work if both X and Y equal 0.
Likewise, if you only need to do something if either X or Y has a value of 0, but you don't care which one, then you can use the 'Or' logical operator:
If (X == 0 OR Y==0) Then doSomeThings…
In that example, doSomethings will work whether X or Y equal 0 without requiring both to have that value.