Skip to content

Commit 015f78f

Browse files
SSwiniarskiDusch4593yangc95
authored
Python Operator plagiarism (Codecademy#499)
* Update operators.md * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update operators.md * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update operators.md * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> * Update operators.md * Update operators.md * Update operators.md * Update operators.md * Update operators.md * Update operators.md * Update content/python/concepts/operators/operators.md Co-authored-by: Brandon Dusch <[email protected]> Co-authored-by: Christine Yang <[email protected]>
1 parent 77b24aa commit 015f78f

File tree

1 file changed

+54
-41
lines changed

1 file changed

+54
-41
lines changed
Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Title: 'Operators'
3-
Description: 'Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values: py print(10 + 5) Python divides the operators in the following groups: - Arithmetic operators'
3+
Description: 'Operators are used to perform various operations on variables and values.'
44
Subjects:
55
- 'Computer Science'
66
- 'Data Science'
@@ -15,64 +15,77 @@ CatalogContent:
1515
- 'paths/data-science'
1616
---
1717

18-
Operators are used to perform operations on variables and values.
18+
Operators are used to perform various operations on variables and values. The standard arithmetic and assignment operators are the most familiar.
1919

20-
In the example below, we use the `+` operator to add together two values:
20+
## Syntax
2121

22-
```py
23-
print(10 + 5)
22+
The following code snippet uses the assignment operator, `=`, to set `my_variable` to the value of `num1` and `num2` with an arithmetic operator acting on them. For example, if `operator` represented `*`, `my_variable` would be assigned a value of `num1 * num2`.
23+
24+
```pseudo
25+
my_variable = num1 operator num2
2426
```
2527

26-
Python divides the operators in the following groups:
28+
Python operators can be organized into the following groups:
2729

28-
- Arithmetic operators
29-
- Assignment operators
30-
- Comparison operators
31-
- Logical operators
30+
- Arithmetic operators for performing traditional math evaluations.
31+
- Assignment operators for assigning values to variables.
32+
- Comparison operators for comparing two values.
33+
- Logical operators for combining boolean values.
3234

3335
## Arithmetic Operators
3436

35-
Arithmetic operators are used with numeric values to perform common mathematical operations:
37+
Python has the following arithmetic operators:
3638

37-
| Operator | Name | Example |
38-
| -------- | -------------- | -------- |
39-
| `+` | Addition | `a + b` |
40-
| `-` | Subtraction | `a - b` |
41-
| `*` | Multiplication | `x * y` |
42-
| `/` | Division | `x / y` |
43-
| `%` | Modulus | `x % y` |
44-
| `**` | Exponentiation | `x ** y` |
45-
| `//` | Floor division | `x // y` |
39+
- Addition, `+`, which returns the sum of two numbers.
40+
- Subtraction, `-`, which returns the difference of two numbers.
41+
- Multiplication, `*`, which returns the product of two numbers.
42+
- Division, `/`, which returns the quotient of two numbers.
43+
- Exponentiation, `**`, which returns the value of one number raised to the power of another.
44+
- Modulus, `%`, which returns the remainder of one number divided by another.
45+
- Floor division, `//`, which returns the integer quotient of two numbers.
4646

4747
## Assignment Operators
4848

49-
Assignment operators are used to assign values to variables:
49+
Python includes the following assignment operators:
5050

51-
- `+=`
52-
- `-=`
53-
- `*=`
54-
- `/=`
55-
- `%=`
51+
- The `=` operator assigns the value on the left to the variable on the right.
52+
- The `+=` operator updates a variable by incrementing its value and reassigning it.
53+
- The `-=` operator updates a variable by decrementing its value and reassigning it.
54+
- The `*=` operator updates a variable by multiplying its value and reassigning it.
55+
- The `/=` operator updates a variable by dividing its value and reassigning it.
56+
- The `%=` operator updates a variable by calculating its modulus against another value and reassigning it.
5657

5758
## Comparison Operators
5859

59-
Comparison operators are used to compare two values:
60+
Python has the following comparison operators:
6061

61-
| Operator | Name | Example |
62-
| -------- | ------------------------ | -------- |
63-
| `==` | Equal | `a == b` |
64-
| `!=` | Not equal | `a != b` |
65-
| `<` | Less than | `a < b` |
66-
| `>` | Greater than | `a > b` |
67-
| `<=` | Less than or equal to | `a <= b` |
68-
| `>=` | Greater than or equal to | `a >= b` |
62+
- Equal, `==`, for returning `True` if two values are equal.
63+
- Not equal, `!=`, for returning `True` if two values are not equal.
64+
- Less than, `<`, for returning `True` if left value less than right value.
65+
- Less than or equal to, `<=`, for returning `True` if left value is less than or equal to right value.
66+
- Greater than, `>`, for returning `True` if left value greater than right value.
67+
- Greater than or equal to, `>=`, for returning `True` if left value greater than or equal to right value.
6968

7069
## Logical Operators
7170

72-
Logical operators are used to combine conditional statements:
71+
Python has the following logical operators:
72+
73+
- The `and` operator returns `True` if both statements are `True`.
74+
- The `or` operator returns `True` if either statement is `True`.
75+
- The `not` operator returns `True` if its associated statement is `False`.
76+
77+
## Order of Operations
78+
79+
Python evaluates an expression in order of precedence as follows:
80+
81+
- Items in parentheses, (`(`...`)`), have the highest level of precedence, expressions within them are evaluated first.
82+
- Exponentiation (`**`)
83+
- Multiplication and division operators (`*`, `/`, `//` & `%`)
84+
- Addition and subtraction (`+` & `-`)
85+
- Comparison (`<`, `<=`, `>` & `>=`)
86+
- Equality (`==` & `!=`)
87+
- `not`
88+
- `and`
89+
- `or`
7390

74-
| Operator | Description | Example |
75-
| -------- | ------------------------------------------------------- | ------------------ |
76-
| `and` | Returns True if both statements are true | `x < 5 and x < 10` |
77-
| `or` | Returns True if one of the statements is true | `x < 5` or `x < 4` |
78-
| `not` | Reverse the result, returns False if the result is true | `not(x < 10)` |
91+
**Note:** Items at the same precedence are evaluated left to right. The exception to this is exponentiation, which evaluates right to left.

0 commit comments

Comments
 (0)