[go: up one dir, main page]

0% found this document useful (0 votes)
24 views6 pages

Python Oops Concepts & Functions

The document discusses Object-Oriented Programming (OOP) concepts in Python, emphasizing the creation of reusable code through classes and objects. It covers key principles such as encapsulation, inheritance, and polymorphism, providing examples of class definitions and method overrides. Additionally, it touches on functions, arguments, and the use of keyword and arbitrary arguments in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Python Oops Concepts & Functions

The document discusses Object-Oriented Programming (OOP) concepts in Python, emphasizing the creation of reusable code through classes and objects. It covers key principles such as encapsulation, inheritance, and polymorphism, providing examples of class definitions and method overrides. Additionally, it touches on functions, arguments, and the use of keyword and arbitrary arguments in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
dl ython OOPS Concepts Objet Oriented Brgramming | Pyymon is a multiparadignm programming language. It Sepports atferent Progrvammng approches. One of pre moc popular approcher fo solve programming Problem by Creating objers. Tats Is known as obfet Ortenjed programming + ( oor). “OOP has 90 characterisHes D> Attributes 2). Behavior Example * fe parrot Is an objed’, as it has Following Properties. + name, age, Color as attyfoures. + Ginging , dancing af behavior. The conupts ef oor: Ip Python focuses on Creating reusable Code. Tilt Concept js also Known Qs DPY CDon't Repeat Yourselt). A Class is a blueprint for the object. pwle can think of class as a skech of parrot with fabs. [r Contains ail derals Bhout the name, colors, size ete. oy. Class farrot: TEE ean” NOTES ORCERY. posuvvuunuuncasacaseddreeeeter z — WLLL LLL ELeaddddeae Here class Keyword define on empty class parrot From class We conttrue Instances (-)n inshancee fs @ Specifle Objut created Fyom 4 Particujar class. Ds TELE RAN NOS CALERY. (Oreject =| fm objet Cnspane) 3s an instantiation of a class. When Class js defined only the discription F058 pre class objet te defined. Theretore, nO memory ox storege is allocated ex ie Obj = Parrot ¢ ) Here Objet ts @n Objet oF class parrot: Suppose We hove details of parrots. alow 102 are gang to show howd 40 bulld the class and objet of parrots. we can acters the Class attribute using — Class speuies - Goneriranee 3s a Way of creating new class for using idotails of an extszing class wlpouk modifying it. The nebly formed class fs cevived class, Simillarty , +2 existing class Is a base class. Ex> Use OF Jnnerifanu in Python. Class Bird: def_ Init_ (cere)? Print ("Bird is ready") dof ctolm (cell): Print (" susim Facper") Class Penguin ( Bira)? of —Init ( sere) + SUEY ( D,-Init_( ) Seé wun (eye): nt ( q Pz Penguin an Bete CG Run Fate IY) f. svinc) ALE D IAL) « RO ddd ddeWeemecoeser Output Stim Paster yun Fast lle can use the fuper () Function Inside yne—}alt_ ) Method> This aYoUsS us fo yun _ ini€_() method. Using OOP ?n python , we can yechriet access 40 methods and VJayiahles. This prevents deta From dive mosification Which Is called encapsulation . In python We donate private attslbute using — as the prefix. fe Single — ov double —- Class Compute def__fnit_. Cser): Sak MAxprite = 900 SH setmoxpriee ( sett , Price ): ek, © mayxprice = price, C= Computer( ) €.-- Mexpri& = j000 C. Cet max Prix (100) We used_init_-( ) method fo etore the maximum selling Prie of Computer. C. — Max price =1000 Method Class Member |Aecess fromown| Accesstbte pecessible access spectthey from Objet. NOOUUOL LL LLL Le cede dedveneneeeeee Poly moxprism fr an abitity fo ue a Common Interface for mutiple forms (data types) Polymorphism in python defines methods jn the child class thet have the same name ar the method in phe pasent’ Class. fh is possible 40 modify 9 Method In @ child class thet Ir has inhertted From child class ,. Parent class. Class parrot : def Fly (selp): Print (" paryot conFig") def swim (+e) Print (“parrot can't sesim") Clase penguin: def fly (sete): Print ("Penguin can't uy") del rwlm( see): Print ("Penguin can sesim") dee Eying_ test (bird): bird. Fly( 7 biue = Parrocl ) peg = Penguin () Fiytng— test (blu) Flying — test (Peg) Output Porren Can Fly. Penguin Can't Pry. ATU Lieumag CLINKEDIN): NS UUU ULL U ad add dduWeveemeraceade lthat ave Funcetons ? A Fanelon icq glock of Code only rans when ty called + Dn Python a Function is defined using phe dek keyrsord . def my — Function ()* print ("“Heno") Arguments fn a Function Frrouments are spedfled after the Function name, inside the parentheses. Yeu can add 46 many argument as you tant Leparate ¢hem edith q Comma. der my — bunetton CF name) Print (fname + “ Refsnes") my Fanetton ("Emit") my - Ranetton ("Tobias") my — Function Citnus") eat ne a Arbitary Arguments - gE you do not know how mang arguments that oil) be passed into your Function, Add a belore the parameter name In the function efinition . dF my. Fanution (kids) : print ("the youngest child is" + kissla) Mg fanitlen("Sour" “godt”, “expark") KK CUNIKEDIN) . dddddduddeorereser RCs = Keyword Arguments ( Kwargs) You can algo send arguments toith phe Key = Value Synrox » dbek my fanetton (enilas, chida , Bids) 2 Pant (“Tre Youngest aia is"+ Chld3) My - Runetion Cohsidy = "mcb" childa = "bea", Childs = “bec") Arbitary Keyword Arguments ** koargs TP you do not Know ho? many Keyword arguments that will be pacred Inte your Funct{on, add 72 asterisk: * * before the parameter name }n the Functton definition . de my Fanttion (** id ): Print ("Hic last name re"t Kid Et name By) my - Punution (Frame = “Tobias”, 1name = “ReFenes Atul Kumar CLINKEDIA).

You might also like