Python provides a way to perform in-place operations in its definition by using the "operator "ModulesAssignments and calculations in a single statement. For example.
x += y is equivalent to x = (x, y)
Some important in situ operations:
1. iadd() :- This function is used toAssigning and adding current values. The operation performs "a+=b "Operation. In the case of immutable containers (such as strings, numbers, and tuples)(negative prefix)Execute the distribution.
2. iconcat() :- This function is used to concatenate a string at the end of the second one.。
# Python code that demonstrates how iadd() and iconcat() work # importing operator to handle operator operations import operator # Use iadd() to add and assign values x = (2, 3); # Print the modified value print ("The value after adding the assignment is:", end="") print (x) # Initialized values y = "geeks" z = "forgeeks" # Use iconcat() to concatenate sequences y = (y, z) # Use iconcat() to concatenate sequences print ("The spliced string is:", end="") print (y)
Output:
The value after adding the assignment is: 5
The spliced string is: geeksforgeeks
3. isub() :- This function is used toAssigning and subtracting current values. The operation performs "a-=b "Operation. In the case of immutable containers (such as strings, numbers, and tuples)(negative prefix)Execute the distribution.
4. imul() :- This function is used toAssign and multiply by the current value. This operation performs the " a=b* " operation. In the case of immutable containers (such as strings, numbers, and tuples)(negative prefix)Execute the distribution.
# Python code that demonstrates how isub() and imul() work # importing operator to handle operator operations import operator # Subtract and assign using isub() x = (2, 3); # Print the modified value print ("Value after subtraction operation:", end="") print (x) # Multiply and assign using imul() x = (2, 3); # Print the modified value print ("Value after multiplication:", end="") print (x)
Output:
Value after subtraction operation: -1
Value after multiplication: 6
5. itruediv() :- This function is used to perform a check on theAssigning and dividing by the current value. This operation performs "a/=b "Operation. In the case of immutable containers (such as strings, numbers, and tuples)(negative prefix)Execute the distribution.
6. imod() :- This function is used toDistribution and return of residuals. The operation performs "a%=b "Operation. In the case of immutable containers (such as strings, numbers, and tuples)(negative prefix)Execute the distribution.
# Python code that demonstrates how itruediv() and imod() work # importing operator to handle operator operations import operator # Use itruediv() for division assignment x = (10, 5); # Print the modified value print ("Value after division assignment:", end="") print (x) # Use imod() to take a modulus and assign it to a value. x = (10, 6); # Print the modified value print ("The value after taking a modal assignment:", end="") print (x)
Output:
Value after division assignment: 2.0
Value after modulo assignment: 4
This article on the use of Python operators Inplace operator tutorial article is introduced to this, more related Python Inplace operator content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future!