Jake Rieger
Jake Rieger

Reputation: 69

Pythonic way of writing multiple functions?

I've been writing Python code for roughly 3-4 months now. I usually write in Atom but recently decided to try out PyCharm after seeing many good things about it. While writing some functions, I noticed I was getting errors and I didn't know why. According to PyCharm, functions should have two newlines after them?

I'd never seen this, or at least never noticed it before. I decided to Google some sample Python code and some pictures showed code with two newlines, but some only had one. Is there a generally accepted way of going about this or is it down to user preference?

Upvotes: 1

Views: 107

Answers (1)

Moinuddin Quadri
Moinuddin Quadri

Reputation: 48110

It is considered as a good practice. As per PEP-0008 document:

Surround top-level function and class definitions with two blank lines.

Method definitions inside a class are surrounded by a single blank line.

Extra blank lines may be used (sparingly) to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners (e.g. a set of dummy implementations).

Use blank lines in functions, sparingly, to indicate logical sections.

PEP-8 is a Style Guide for Python Code

Upvotes: 4

Related Questions