![]() ![]() # 7 of # # Basic info and the first 4 items in the queue: # print (Q1.pr(4)) # Queue Q1: 7 item/s in queue. name = name return name def pr ( self, numberToBePrinted = 0 ) : ''' # # method Queue.pr(numberToBePrinted) # This method returns a string containing contents of queue and suitable for printing: # # Q1 = Queue('1234567') # # Basic info about Q1 # print (Q1.pr(-4)) If numberToBePrinted is negative, only one line is printed. v = name = '' for v in globals () : if globals () = self : name = v break if not name : name = str ( self ) self. name except : status = 1 if status : # Determine this queue's global name. queue = list ( itemsForQueue ) return def getName ( self ) : status = 0 try : name = self. typesAllowed = eval ( v2 ) status = 0 for type_ in tA : if isinstance ( itemsForQueue, type_ ) : status = 1 break if not status : print ( 'Queue._init_ : Input must be 1 of ', tA, sep = '' ) return if isinstance ( itemsForQueue, Queue ) : self. split ( ' \n ' ) : if 'typesAllowed' in line : line1 = line break v1, equal, v2 = line1. append # typesAllowed = (list, tuple, str, bytes, bytearray, Queue ) # ''' def _init_ ( self, itemsForQueue = ): line1 = '' for line in self. ''' # class Queue # To create a new class: # Q1 = Queue() # Q1 = Queue() # Q1 = Queue('12345') # To add to the queue: # Q1.append() # To get length of queue: # Q1.size() # To get data from the queue: # v1, = Q1.get() # v1,v2,v3 = Q1.get(3) # To empty the queue: # L1 = Q1.get(Q1.size()) # To get a string containing contents of queue and suitable for printing: # Q1.pr() # Q1.pr(5) # Q1.pr(Q1.size()) # For. In python you define a class method (an action, event, or function)Ĭlass Queue : # The following comment may be accessed via the class's. Instead of writing code separately for each car we could create a class called 'Car' that will be the blueprint for each particular car.Ĭonstructing a class Ĭlass is the name given to a generic description of an object. Each car has different characteristics like mileage, color, and top speed, but lucky for us they all can perform some common actions like braking, accelerating, and turning. ![]() ![]() Lets say you're writing a program where you need to keep track of multiple cars. OOP is a programming approach where objects are defined with methods (functions, actions or events) and properties (values, characteristics), resulting in more readable, more reusable code. The real power of python lies in the fact that each user of python may create new classes as simply as writing new functions.Īnd each new class easily encapsulates features that enhance the class. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |