Skip to content

Latest commit

 

History

History
128 lines (87 loc) · 2.01 KB

checklist.md

File metadata and controls

128 lines (87 loc) · 2.01 KB

Сheck Your Code Against the Following Points

Code Efficiency

  1. Use the class name to get access to the class attributes:

Good example:

class Person:
    city = "Kyiv"

    def __init__(self, name: str):
        self.name = name
        
    @staticmethod    
    def print_city() -> None:
        print(Person.city)

liz = Person("Liz")
liz.print_city()  # Kyiv

Bad example:

class Person:
    city = "Kyiv"

    def __init__(self, name: str):
        self.name = name
        
    def print_city(self) -> None:
        print(self.city)

liz = Person("Liz")
liz.print_city()  # Kyiv
  1. You can change the bool value in one line:

Good example:

is_married = True

is_married = not is_married

Bad example:

is_married = True

if is_married:
    is_married = False
else:
    is_married = True
  1. Use the static method when needed.

Code Style

  1. Use annotation, it is a good practice:

Good example:

def multiply_by_2(number: int) -> int:
    return number * 2

Bad example:

def multiply_by_2(number):
    return number * 2
  1. Make sure you use the double quotes everywhere.

Good example:

greetings = "Hi, mate!"

Bad example:

greetings = 'Hi, mate!'
  1. Use interpolation instead of concatenation:

Good example:

def print_full_name(name: str, surname: str) -> str:
    return f"{{Name: {name}, surname: {surname}}}"

Bad example:

def print_full_name(name: str, surname: str) -> str:
    return "{" + "Name:" + name + ", surname:" + surname + "}"
  1. Use descriptive and correct variable names:

Good example:

def get_full_name(first_name: str, last_name: str) -> str:
    return f"{first_name} {last_name}"

Bad example:

def get_full_name(x: str, y: str) -> str:
    return f"{x} {y}"

Clean Code

Add comments, prints, and functions to check your solution when you write your code. Don't forget to delete them when you are ready to commit and push your code.