2019-02-19
阅读量:
786
python中的运算符重载是什么
运算符重载意味着赋予超出其预定义操作含义的扩展含义。例如,operator +用于添加两个整数以及连接两个字符串并合并两个列表。这是可以实现的,因为'+'运算符被int类和str类重载。您可能已经注意到,相同的内置运算符或函数对不同类的对象显示不同的行为,这称为运算符重载。
# Python program to show use of
# + operator for different purposes.
print(1 + 2)
# concatenate two strings
print("Geeks"+"For")
# Product two numbers
print(3 * 4)
# Repeat the String
print("Geeks"*4)
输出:
3
GeeksFor
12
GeeksGeeksGeeksGeeks






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论