To customize the workflow:
The code structure should be made as simple as possible at the outset. Do all the work in one file as soon as possible, and make sure everything is running correctly before moving the class into a separate module. If you like how modules and files interact, you can try to store the classes in the module at the beginning of the project. Find out how you can write workable code, and then try to make your code more organized.
Class encoding Style:
You must be familiar with some coding style issues related to classes, especially when you are writing a program that is more complex.
The class name should use the Hump naming method to capitalize the first letter of each word in the class name instead of underlining. Instance names and module names are in lowercase and underlined between words.
For each class, you should immediately include a document string after the class definition. This document string briefly describes the functionality of the class. and follows the formatting conventions used when writing a function's document string. Each module should also contain a document string. Describes what classes can be used to do.
You can use a blank line to organize your code, but do not misuse it. In a class, you can use a blank line to separate the method, whereas in a module, you can use two blank lines to separate classes.
When you need to import both the modules in the standard library and the modules you write, write an import statement that imports the standard library module, add a blank line, and then write an import statement that imports the modules you write yourself. In a program that contains multiple import statements, this makes it easier to understand where the various modules used by the program come from.
Instance:
"""A class that can be used to represent a car"""classCar ():"""a simple attempt at simulating a car""" def __init__(self,make,model,year):"""Initialize description of car properties"""Self.make=Make Self.model=Model Self.year=Year self.odometer_reading=0defGet_descriptive_name (self):"""returns a neat descriptive name"""Long_name= str (self.year) +' '+ Self.make +' '+Self.modelreturnLong_name.title ()defRead_odometer (self):"""print a message stating the mileage of the car""" Print("This car has"+ STR (self.odometer_reading) +"miles on it.") defUpdate_odometer (self,mileage):"""set the odometer reading to a specified value refuse to dial the odometer back""" ifMileage >=self.odometer_reading:self.odometer_reading=MileageElse: Print("You can ' t Roll back an odometer!") defIncrement_odometer (self,miles):"""increase the odometer reading by the specified amount"""self.odometer_reading+ = Miles
Coding styles like Python basics