Open In App

Operator Functions in Python | Set 2

Last Updated : 15 Jul, 2022
Comments
Improve
Suggest changes
88 Likes
Like
Report

Operator Functions in Python | Set 1

More functions are discussed in this article.

1. setitem(ob, pos, val) :- This function is used to assign the value at a particular position in the container. 
Operation - ob[pos] = val

2. delitem(ob, pos) :- This function is used to delete the value at a particular position in the container. 
Operation - del ob[pos]

3. getitem(ob, pos) :- This function is used to access the value at a particular position in the container. 
Operation - ob[pos]
 

Output: 
 

The original list is : 1 5 6 7 8 
The modified list after setitem() is : 1 5 6 3 8 
The modified list after delitem() is : 1 6 3 8 
The 4th element of list is : 8


4. setitem(ob, slice(a,b), vals) :- This function is used to set the values in a particular range in the container. 
Operation - obj[a:b] = vals

5. delitem(ob, slice(a,b)) :- This function is used to delete the values from a particular range in the container. 
Operation - del obj[a:b]

6. getitem(ob, slice(a,b)) :- This function is used to access the values in a particular range in the container. 
Operation - obj[a:b]
 

Output: 
 

The original list is : 1 5 6 7 8 
The modified list after setitem() is : 1 2 3 4 8 
The modified list after delitem() is : 1 2 8 
The 1st and 2nd element of list is : [1, 2]


 
7. concat(obj1,obj2) :- This function is used to concatenate two containers. 
Operation - obj1 + obj2

8. contains(obj1,obj2) :- This function is used to check if obj2 in present in obj1
Operation - obj2 in obj1
 

Output: 
 

The concatenated string is : geeksforgeeks
geeksfor contains geeks


 9. and_(a,b) :- This function is used to compute bitwise and of the mentioned arguments. 
Operation - a & b

10. or_(a,b) :- This function is used to compute bitwise or of the mentioned arguments. 
Operation - a | b

11. xor(a,b) :- This function is used to compute bitwise xor of the mentioned arguments. 
Operation - a ^ b

12. invert(a) :- This function is used to compute bitwise inversion of the mentioned argument. 
Operation - ~ a
 

Output: 
 

The bitwise and of a and b is : 0
The bitwise or of a and b is : 1
The bitwise xor of a and b is : 1
The inverted value of a is : -2


 


Python Operator Functions - Part 2
Article Tags :
Practice Tags :

Similar Reads