CARVIEW |
- CCNA online course
- Linux online course
- VMware ESXi online course
- Nmap online course
- MySQL online course
- Raspberry Pi online course
- Apache HTTP Server course
- VMware Player online course
- Splunk online course
- SQL online course
- Oracle VirtualBox online course
- Python online course
- Asterisk course
- VMware Workstation Player course
- Process Explorer course
- Pillow online course
- Create a web crawler in Python
- A short introduction to…
Arithmetic operators
The arithmetic operators in Python are used to perform math operations, such as addition, subtraction, multiplication, and division. Python also offers a number of libraries that enable you to perform more complex math tasks.
Here is a list of the arithmetic operators in Python:
- Addition (+) – adds two values together. Example: 3 + 2 = 5.
- Subtraction (-) – subtracts right hand operand from the left hand operand. 3 – 2 = 1.
- Multiplication (*) – multiplies the right operand by the left operand. Example: 3 * 4 = 12.
- Division (/) – divides the left operand by the right operand. Example: 9 / 3 = 3.
- Modulus (%) – divides the left operand by the right operand and returns the remainder. Example: 9 % 5 = 4.
- Exponent (**) – calculates the exponential value. Example: 3 ** 4 = 81.
- Floor Division (//) – performs integer division. Example: 9//2 = 4.
You are probably familiar with all operators mentioned above, except the modulus operator (%). The concept is actually simple – the modulus operator returns the remainder after integer division. Consider the following example:
20 % 3
The integer division of the numbers above will give the result of 6.
6 * 3 = 18.
This gives a reminder of 2 (18 + 2 = 20).
Another example:
5 % 2
Integer division = 2.
2*2 = 4.
The remider is 1. So 5 % 2 = 1.
One more example:
13 % 5
Integer division = 2
2 * 5 = 10
The reminder is 3.
Python course
- Introduction
- Python overview
- Install Python on Windows
- Install Python on Linux
- Add Python to the Windows Path
- Run Python code
- Interactive prompt
- IDLE editor
- Command line
- Help mode
- Basic programs
- Write your first program
- Use comments
- What are variables?
- Variable data types
- Variable names
- Numeric variables
- Strings
- Get the current date and time
- Operators overview
- Arithmetic operators
- Comparison operators
- Logical operators
- Assignment operators
- Membership operators
- Identity operators
- Conditional statements
- The if statement
- Get user input
- The if...else statement
- The if...elif statement
- Nested if statements
- Use logical operators
- Loops
- The for loop
- Use for loop with the range() function
- The break statement
- The continue statement
- The pass statement
- Use else statement in loops
- The while loop
- Nested loop statements
- Errors
- Types of errors
- Syntax and logical errors
- The try...except statements
- The try...except...else statements
- The try...except...finally statements
- Catch specific exceptions
- Raise exception
- Nest exception handling statements
- Modules
- What are modules?
- Import modules
- Find files on disk
- Display module content
- Strings
- What are strings?
- Escape characters
- Access individual characters
- String functions
- Search strings
- Concatenating strings
- Lists, sets, tuples, dictionaries
- What are lists?
- Modify lists
- Loop through a list
- Check whether a value is in a list
- Sorting lists temporarily
- Sorting lists permanently
- Obtaining the list length
- What are sets?
- What are dictionaries?
- Add new key-value pair to a dictionary
- Modify a value in a dictionary
- Delete a key-value pair in a dictionary
- Loop through a dictionary
- What are tuples?
- Looping over a tuple
- Working with files
- How to read and write files
- Read a file
- Read and write – with statement
- Make a list of lines from a file
- Functions
- What are functions?
- Return statement
- Positional arguments
- Keyword arguments
- Default values for parameters
- Flexible number of arguments
- Variable scopes