Basic Python Structure

Python is an object-oriented language. An object is a virtual entity combining structured data and the methods in which the data can be manipulated. A method is a procedure for manipulating data, and an argument defines how the method is carried out. A simplistic but effective analogy is that of basic grammar: An object can be equated with a noun, a method with a verb, and an argument with an adjective or adverb. For example, consider the following:

car = Factory.Produce(vehicleXL)

In this case, the variable car is the result of the object factory being acted upon by the method produce as modified by the argument vehicleXL (the make and model). To put it in lay terms, the car’s existence and everything about the car depends on the factory being told to produce a car of a specified make and model. Consider how the value of the variable car can differ based on the following examples:

car = Mechanic.Repair(car, transmission)

car = Junkyard.Salvage(vehicleXL)

car = CarThief.Steal()

In the first example the car argument is passed in, modified by the Mechanic’s Repair method, and returned as a working car. The last example contains no argument. In this case, the car thief may not take external input to decide which car to steal. Again, the object defines a structured set of data, the method is what the object does, and any arguments describe how the method is performed.

The data can be virtually anything including letters, numbers, files, etc. As you begin to think of data in terms of objects and manipulating objects, you will find it far easier and faster to write Python scripts.

© 2020-2021 Bondware, Inc. Last updated November 23, 2021