Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does python have generic methods? [closed]

Does python have generic methods like Java? If so could you refer to a site that explains it.

like image 984
TheProgrammer Avatar asked Dec 08 '13 03:12

TheProgrammer


1 Answers

No. Python is not a statically typed language, so there is no need for them. Java generics only provide compile time type safety; they don't do anything at runtime. Python doesn't have any compile time type safety, so it wouldn't make sense to add generics to beef up the compile time type checks Python doesn't have.

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

like image 174
John Kugelman Avatar answered Oct 02 '22 01:10

John Kugelman