
- Learn about Operators in Python:
    - String Operators
    - Numeric Operators
    - List Operators
Operators and Expressions in Python
Let's start with the basics so we're on the same page.
Operator - is a special symbol or keyword that can be used to perform a specific operation on one or more variables (e.g. +, -, >, in,). They are used in expressions to perform arithmetic, comparison or logical evaluations.
Expression - is a piece of code that produces a value when evaluated. It can be as simple as adding 2 numbers together (e.g.2+2 or a+b ).
For example, we can define a few variables, and then calculate another one by creating an expression. In this case let's sum 2 numbers together.
Also note that you don't always have to assign your expression to a variable. You can use it directly as an argument in functions.
The only notable difference is that you will be able to reuse total variable later in the code if necessary. Otherwise it serves no purpose.
💡I know it's simple, but beginners start to get confused with this on bigger examples sometimes. So it's worth repeating.
Now let's go through the common DataTypes and look at their operators and what kind of results we can get. And why?

🔠String Operators
We are ready to dive into operators, and let's begin with String operators.
Firstly, you need to know that you can concatenate strings(fancy word meaning 'join' text in programming).
1.Join Strings:
Here's another example:
2.Multiple Strings:
You can also multiply your strings. Then they will be repeated n-times.
I often use it to create a long line of dashes in the console when I print.
💡Notice that \n is a special combination inside a string to create a New-Line.
3.Membership Operators:
Strings also have membership operators to check if certain value is part of another string. There are 2 keyword:
innot in
Here is how to use them:
💡Note that lowercase and uppercase are 2 different characters.
4.Equality Operators:
Similar to membership operators, we can also check if strings are equal or not equal. And we use the following symbols:
==- Equal!=- Not Equal
⚠️ Do not confuse double(==) and single(=) equal signs. One is used to assign data or expression to a variable the other is used in logical checks.
Here is an example:
🔢Numeric Operators
Now let's look into Numeric Operators.
There are 2 main categories:
Arithmetic Operators
Comparison Operators.
1.Arithmetic Operators:
Let's start with Arithmetic. It's simple mathematical operations to add, subtract values. I won't go into detail, you all already know it well:
However, notice that there are 3 new ones:
//- Floor division which rounds a value to a lower integer.%- Mod, which returns the remainder after the division.**- Power, which set the value in the power (2-square, 3-cube…)
The rest is just simple math.
2.Comparison Operators:
There are also comparison operators to create logical checks.
We will cover how to create logical statements in another lesson, for now just focus on the logical operators. The goal is to get True or False value from logical expression.
Here is an example:
💡 Also, do not confuse single(=) and double(==) equal signs. One is used to assign data to variables, the other to check if variables are equal.
📦List/Tuple Operators
Lastly, let's look into list and tuple operators and keep in mind that they use the same ones. So, I will only show examples using lists, and you can adjust them for tuples.
Lastly, let's also look into lists and we are going to begin with a basic one.
1.Join Lists (+)
You can take multiple lists and join them together using + symbol. Logical, right?
2.Membership Operators in Lists
Similar to strings we can also use Membership operators in lists using in and not in keywords. It works exactly the same:
3.Membership Operators in Lists
And we can also check if our lists are equal or not equal using == or != symbols.
Here is a comparison.
4.Membership with Nested Lists
Also, remember that you can create nested lists, and you can also check if certain list is a part of another list. But it only works if you have a list inside of a list.
If you are trying to check if all values of one list are inside of another list , then you would need to do it differently using loops. More on loops in another lesson…
Review the summary of this lesson and experiment with the operators in your own python code.
Try it out and see what you get. It's simple, but still worth a try to build up your muscle memory for Python.
Sposored by LearnRevitAPI.com
