Python Write Better Python Cleaner Code Function and Class Whitespace

starter.py

This code drive me nuts. How do i find the whitespace? Also the blank line at the end of the code does not work too. Either it is 0 1 or 2.

Your file has 5 error(s) on line(s) 10, 4, 13, 14: blank line contains whitespace; blank line at end of file; expected 2 blank lines, found 1.

starter.py
def first_function(arg1):
    return 'arg1 is {}'.format(arg1)

def second_function(arg1):
    return 'arg1 is {}'.format(arg1)


class MyClass:
    args = [1, 2, 3]

    def class_func(self):
        return self.args
Cheo R
Cheo R
37,150 Points

Some editors have an option to highlight white space/blank lines.

2 Answers

Peter Lawless
Peter Lawless
24,402 Points

Walk through your code with your arrow keys and see if there are spaces at the end of each line (including blank lines). Good news, though: In a text editor you can install plugins that will check your Python code (flake8 is an example) and will bring PEP8 violations to your attention as you write code, so you won't have to do this manually when you're writing code for development.

Ankoor Bhagat
Ankoor Bhagat
1,093 Points

Bummer! Your file has 1 error(s) on line(s) 11: blank line contains whitespace.

def first_function(arg1):
    return 'arg1 is {}'.format(arg1)


def second_function(arg1):
    return 'arg1 is {}'.format(arg1)


class MyClass:
    args = [1, 2, 3]

    def class_func(self):
        return self.args