Difference between java and python (memo)

Introduction

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.

Increment

There is no increment operator (++) in python.

Overload

python is an overloaded method (same name but different argument structure Method) cannot be created.

for statement

Java


for(int i=0;i<10;i++){
  //processing
}

Python


for i in range(10):
    #processing

Class method arguments

In python, the first argument of the class method is its own object, It is customary to use self.

Instance variables

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

Class variable (class variable)

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

Difference between java and python (memo)
Difference between Ruby and Python split
Difference between list () and [] in Python
Difference between == and is in python
Difference between python2 series and python3 series dict.keys ()
[Python] Difference between function and method
Python --Difference between exec and eval
[Python] Difference between randrange () and randint ()
[Python] Difference between sorted and sorted (Colaboratory)
difference between statements (statements) and expressions (expressions) in Python
Differences in syntax between Python and Java
Difference between PHP and Python finally and exit
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
[Python] Difference between class method and static method
[Python Iroha] Difference between List and Tuple
[python] Difference between rand and randn output
[python] Difference between variables and self. Variables in class
[Python] Conversion memo between time data and numerical data
About the difference between "==" and "is" in python
Difference between process and job
Difference between "categorical_crossentropy" and "sparse_categorical_crossentropy"
Difference between regression and classification
Python and ruby slice memo
I compared Java and Python!
Difference between np.array and np.arange
Difference between MicroPython and CPython
Difference between ps a and ps -a
Difference between return and print-Python
Difference between Ruby and Python in terms of variables
Difference between return, return None, and no return description in Python
Java and Python basic grammar comparison
Difference between SQLAlchemy filter () and filter_by ()
Python memo
Python module num2words Difference in behavior between English and Russian
python memo
Python> Difference between inpbt and print (inpbt) output> [1. 2. 3.] / array ([1., 2., 3.], dtype = float32)
Memorandum (difference between csv.reader and csv.dictreader)
Python memo
List concatenation method in python, difference between list.extend () and “+” operator
(Note) Difference between gateway and default gateway
Cooperation between python module and API
Difference between Numpy randint and Random randint
Differences between Python, stftime and strptime
Difference between sort and sorted (memorial)
python memo
Python memo
Python memo ① Folder and file operations
I tried to enumerate the differences between java and python
Difference between SQLAlchemy flush () and commit ()
Python memo
Python memo
Difference in how to write if statement between ruby ​​and python
Transcendental simple and clear! !! Difference between single quotes and double quotes in Python
Python / Numpy> Link> Difference between numpy.random and random.random> thread-safe or not
File open function in Python3 (difference between open and codecs.open and speed comparison)
Communicate between Elixir and Python with gRPC
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Statistical basics and Python, graphing, etc. (memo)