Python

Read the latest updates about all things Python at Microsoft

Idiomatic Python: functions versus classes

In Python, everything is an object. Compared to Java which forces you to code everything in an object-oriented programming style but still has the concept of primitive types which are not objects on their own (although Java 5 added autoboxing to help hide this discrepancy), Python has no primitive types which aren't objects but provides the ...

Idiomatic Python: EAFP versus LBYL

One idiomatic practice in Python that often surprises people coming from programming languages where exceptions are considered, well, exceptional, is EAFP: "it's easier to ask for forgiveness than permission". Quickly, EAFP means that you should just do what you expect to work and if an exception might be thrown from the operation then catch ...

Idiomatic Python: boolean expressions

You might think that boolean expressions -- most frequently used as conditional guards which are the the bit of code that tests whether an or statement should execute -- are a fairly straight-forward concept and that there isn't really anything subtle to them at all. And while the general concept is simple, there are some idiomatic practices...

Idiomatic Python: comprehensions

We're lucky to have a few people on our team who have been programming in Python for quite a while (I myself have been using the language now for over 15 years). Over the course of time we have picked up various idioms for programming in Python that may not be obvious or widely known for various reasons. To help share some of this knowledge we...