Skip to main content
 首页 » 编程设计

java之Java 与 Python 中的 "+"运算符

2025年05月04日32emanlee

<分区>

有人可以解释为什么 Java 在以下示例中连接字符串和整数吗?

public class main { 
 
    public static void main(String[] args) { 
        System.out.println("test" + 5); 
        System.out.println(5 + "5"); 
    } 
 
} 

以及Python对+操作符的实现有什么不同。

在 Python 中,这会引发一个 TypeError:

"5" + 5