Peculiarities of Python

Hi all,

After a short hiatus because of my summer internship, I am back to blogging, and what better way to start again by summarizing the peculiarities of Python [for people coming from a Java/ C++ background]. So, tighten up your seatbelts, and here goes:

[1] Python supports multiple inheritence

[2] Python’s self is the same thing as C++/ Java/ C# this

[3] There is no function/ method overloading in Python

[4] All methods in Python are by default virtual, without the explicit use of the keyword

[5] Python has an in-built copy module that can copy arbitrary Python objects

[6] Object identity in Python is represented by the keyword is – unlike the == in Java. The == in Python always represents value equality

[7] Any class in Python can override the __len__ method, which can dictate what the len function returns. If a class defines the __cmp__ method, its objects can be compared using ==.

[8] There are wrapper classes like UserDict and UserString that extend/ modify the functionality of base classes like dict and string – you may not directly derive from dict and string

[9] Member variables are called data attributes, and they are defined inside the __init__ method. Static variables are called class attributes, they are defined outside the __init__ method, and do not have the static keyword

[10] There are no constants in Python

[11] Nothing is protected in Python

[12] Anything whose name starts with __ and does not end with it is private (function, method or attribute), and everything else is public – the keywords private and public are not used

This is just the beginning, more to come.

2 thoughts on “Peculiarities of Python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s