Java is overwhelmingly the number of steps and time I have written so far. I'm studying Python because it's cool these days. I want to make a note as soon as I understand the difference from Java.
There is no increment operator (++) in python.
python is an overloaded method (same name but different argument structure Method) cannot be created.
Java
for(int i=0;i<10;i++){
//processing
}
Python
for i in range(10):
#processing
In python, the first argument of the class method is its own object, It is customary to use self.
When python uses instance variables, explicitly even in the class Must be qualified with a variable name that indicates a class object. (Same for instance methods)
Java
class Hoge{
int arg1;
private void func(){
arg1=0;
}
}
Python
class Hoge:
def func(self):
self.arg1=0
When using class variables, python must explicitly qualify with the class name even within the class.
Python
class Test:
a="Class variables"
def test(self):
self.a="Instance variables"
#Class variables are displayed (either way of writing is possible)
print(Test.a)
print(type(self).a)
#Instance variables are displayed
print(self.a)
test=Test()
test.test()
Instance variable if the object to qualify is an instance If it is a class, it is treated as a class variable.
Recommended Posts