Python加成
示例
a, b = 1, 2 # Using the "+" operator: a + b #=3 # Using the "in-place" "+=" operator to add and assign: a += b #a=3(相当于a=a+b) import operator #包含2个参数算术函数的示例 operator.add(a, b) #=5,因为在此行之前将a设置为3 # The "+=" operator is equivalent to: a = operator.iadd(a, b) #a=5,因为在此行之前将a设置为3
可能的组合(内置类型):
int和int(给出int)
int和float(给afloat)
int和complex(给acomplex)
float和float(给afloat)
float和complex(给acomplex)
complex和complex(给acomplex)
注意:该+运算符还用于连接字符串,列表和元组:
"第一个字符串 " + "second string" # = '第一个字符串 second string' [1, 2, 3] + [4, 5, 6] #=[1、2、3、4、5、6]
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短