There is no need to over-explain why writing human readable code is important. A human readable code is crucial for development, maintenance and reusing. Above are several posts talking about how to write the human readable code, and some examples for practice is provided below.
i = 1 a_list = [2, 3] even = i % 2 small_list = len(a_list) < 10 if even and small_list: pass
This is pretty useful when writing tutorial code. In any place you want to write a comment, you can write it as a function with appropriate name.
def shopping(): def buy_milk(): pass def buy_egg(): pass def buy_paper_towel(): pass
If a variable only plays role in a block, it should not appear outside the block.
import numpy as np a = np.random.randint(10) # right if a % 2 == 0: b = 3 a += b # wrong b = 3 if a % 2 == 0: a += b
a = 22 # bad age = 22 # good
# Usually class uses Camel name and with captial initial letter # Wrong class good_boy: pass # Right class GoodBoy: pass
# package use snake case in general, it is better to have only one word import async_timeout import numpy as np
# Constant, captial snacke case TIME_LIMIT = 10
# function, variable, snake case def wash_hand(): pass boy = GoodBoy()