Python中的Inplace运算符-iadd(),isub(),iconcat()
在本文中,我们将学习Python3.x中可用的一些inplace运算符。或更早。
Python提供了一些方法来执行就地操作,即借助“operator”模块在单个语句中同时执行赋值和计算。在这里,我们将讨论iadd(),isub()和iconcat()函数。
我加()
此功能使我们可以分配和添加当前值。此操作的行为类似于“a+=b”操作。如果数据类型是不变的,例如字符串和元组,则不能执行分配。
示例
import operator as op
# using iadd() to add
int1 = op.iadd(786,0);
# displaying value
print ("The value : ", end="")
print (int1)输出结果
The value : 786
isub()
此功能使我们可以分配和减去当前值。此操作的行为类似于“a-=b”操作。如果数据类型是不变的,例如字符串和元组,则不能执行分配。
示例
# using isub() to subtract
int2 = op.isub(57,34)
print ("The value : ", end="")
print (int2)输出结果
: The value : 23
iconcat()
此函数使我们可以在第二个字符串的末尾连接一个字符串,就像对字符串的加法运算符一样。
示例
str1 = "tutorials"
str2 = "point"
# using iconcat() to concatenation
str1 = op.iconcat(str1, str2)
# displaying value
print ("The string becomes: ", end="")
print (str1)输出结果
The string becomes: nhooo
结论
在本文中,我们了解了Python中Inplace运算符的用法和实现-iadd(),isub(),iconcat()。
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练