In the last session, we are discussing the python concepts. I hope all are understand good. Now, we are seeing some operator's examples and literal collections. The literal collections are the most important topic in python.
Let’s start,
Arithmetic operations using python
This is a very useful part. Because once we know how to handle the arithmetic operations means the data type concept over.
Simple calculation
OUTPUT
24
Print using format
OUTPUT
x=10
y=10
x=30
y=10
Basic Operations using python
OUTPUT
The number x is 16
The number y is 4
Addition:
x+y= 20
Subtraction:
x-y= 12
Multiplication:
x*y= 64
Division :
x/y= 4.0
Differnce Between / and //
OUTPUT
Division
Enter a number :40
Enter a number :4
a/b
Float value : 10.0
Integer value : 10
Differnce Between * and **
OUTPUT
2*5: 10
2**5: 32
Simple Calculation using BODMAS
OUTPUT
200-5*10+100 = 250
(200-5*10)+100 = 250
876-98*68+8/4 = -5786.0
del keyword
OUTPUT
n= 100
Traceback (most recent call last):
File "C:/Users/Name/Desktop/del.py", line 8, in <module>
print(n)
NameError: name 'n' is not defined
Comparison (Relational) Operators
Logical operators
Round off function
![]()
Underscore _ usage in python
![]()
TUPLE OPERATIONS
- It can be used to store various items in a single variable. It is enclosed by the parentheses ().
- The elements are separated by the special character like comma (,).
- It is considered to be immutable which means it can't be modified after creation.
- The (del) keyword can delete the tuple completely.
- Tuple items are indexed. For example, the first item is considered as the index [0], the second one as index [1], etc.
LIST OPERATIONS
- In this following operation, the list is the most versatile datatype available in the Python program which can be written as a list of comma-separated values
- It is enclosed by "square brackets [...]"
- It is considered to be mutable which means it can be modified after creation.
- We can add or remove the following items after the list has been created.
SET OPERATIONS
- It can be used to store multiple items in a single variable.
- A set is a collection of variables that is both "unordered" and "unindexed".
- It can be written with curly brackets "{…}"
- It having unique values and eliminate duplicate items.
DICTIONARY OPERATIONS
- Dictionary is considered to be an unordered set of a key-value pair of items.
- It is enclosed with the curly braces { ... }.
- It is very easy to add or delete the items,
I hope you understand about literals briefly. If you have any query please ask me anything. We'll see a more interesting topic in the future.