我目前开始使用python 2中的python 3.在Python 2中,字符串类型转换可以使用int()函数轻松完成,但我在Py3.5.3中遇到问题
current = input("Enter the Current price: ")
int(current)
print (type(current))
c = current - 24
Run Code Online (Sandbox Code Playgroud)
Class str即使在类型转换功能之后,电流仍然显示为.
错误是 TypeError: unsupported operand type(s) for -: 'str' and 'int'
我知道这只是一个小错误,但我在网上查看的例子都使用了我使用的int函数.这可能是什么问题
我试图在同一行上打印字符串和 int。但我得到一个错误。我知道解决这个错误的方法,但是为什么该行System.out.println("This is a string: %i", c2.a);给出错误而该行System.out.println("This is class method" + c2.a );给出正确的输出。下面是我的代码。
public class MyClass
{
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
// new method
public static void incrementBoth(MyClass c1) {
c1.a = c1.a + 1;
c1.b = c1.b + 1.0;
}
//pass by valuye therefore no change
public static void incrementA(int a)
{
a = a+1;
}
public static void main(String[] …Run Code Online (Sandbox Code Playgroud)