Code Style

Understand the importance of code style.

We'll cover the following...

Python code with style issues

Code style is very important for readability. Consider the following code:

Press + to interact
from fruits import orange
import numpy as np
from fruits import apple
def p(list):
#print list
for i in len(list):
print(list[i])
apple_varieties_list = ["pink lady",
"empire",
"fuji", "gala",
"golden delicious", "granny smith", "honeycrisp", "mcintosh", "red delicious", "ginger gold", "jersey mac", "paula red", "ambrosia"]
for a in apple_varieties_list:
print(a)
p(apple_varieties_list)
# handle oranges
# do something with numpy

Do you see any issues? There are several here, including the following:

  • The two imports from fruits are in lines 1 and 3 when they could have been on the same line (e.g., from fruits import apple, orange) or together.

  • There are no blank lines in the body of the code, which makes it harder to read. ...