Does python have common methods?

Does python have common methods like Java? If you could link to a site that explains it.

+7
python generics
source share
2 answers

Not. Python is not a statically typed language, so there is no need for them. Java generators provide only compile-time type protection; they do nothing at runtime. Python has no compile-time type security, so it would be pointless to add generics to leverage compile-time type checks that Python does not exist.

The list, for example, is an untyped collection. There is no equivalent to the difference between List<Integer> and List<String> , because a Python list can store any type of object.

+14
source share

Python is a dynamically typed language, so it doesn’t need generics. He can do something like this.

 def addTen(inputData): if isinstance(inputData, int): return inputData + 10 elif isinstance(inputData, str): return int(inputData) + 10 else: return 10 

You can pass any data types to any function, and this function can handle different types of data in different ways.

+3
source share

All Articles