0% found this document useful (0 votes)
85 views13 pages

Python Oops Concepts

The document provides an overview of Object-Oriented Programming (OOP) concepts in Python, highlighting key principles such as classes, objects, inheritance, encapsulation, and polymorphism. It explains how to define classes and create instances, as well as the use of functions, arguments, and various types of operators in Python. Additionally, it covers data types, variable naming conventions, and the input function for user interaction.

Uploaded by

an8439809697
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)
85 views13 pages

Python Oops Concepts

The document provides an overview of Object-Oriented Programming (OOP) concepts in Python, highlighting key principles such as classes, objects, inheritance, encapsulation, and polymorphism. It explains how to define classes and create instances, as well as the use of functions, arguments, and various types of operators in Python. Additionally, it covers data types, variable naming conventions, and the input function for user interaction.

Uploaded by

an8439809697
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/ 13
oe eee iddddscreceeec ython OOPS Concepts Objet Oriented Frogramming J Pymon fe a mutiparadigm progromming language. It Supports adéferent Progvammlng appyoches One of pre most popular approches 40 solve programming Problem by Creating objets. Tris Is jkndWn as objet Ortented Programming» ( 00P). “OOP hae 400 characteristics D> Attrioures 2) Behavior Syample* A parrot Is an object, as it has Following Properties. * name, age, Color as attyioures. + Singing , dandng af behavior. The conupts of ors In Fypmon focuses on creating yeusable Code. This Concept js also known Qs DPY CDon't Repeat Yourself). # Class is a blueprint for the object. We can think of class as a skech of parrot With labels. [F contains gil derails Chout tne name, colors, size ete. ey: Class forrot: “ ita aadeee eee Hese clacs Keyedrd define on empty class parrot Prom “Jas; We construc Instances (-In insrane Is @ Specitle oObjut created yom a Particujar class (Oye | fn objec Cinstane) }s an instantiation pf a class. bihen is defined only the ahreription $08 phe Class objet te defined. Thereore, nO memory ox storage is allocated exi- Obj = Parrot ¢ ) TELEY RIN- NAS GALLERY Here Objew F< On objet of class parrot: Suppose We have details of parrots. alow We axe gdng 70 shod how +0 bulld the class and objec of parrots. we can actess the Class attribure using — Class_ Species - Gonerirane Is a Hay of creating new class for aslng details of an existing class Lolpout modifying it. The newly formed class fs derived class, Similarly , +he oxisting class Is a base class. €x> Use of Innevipana In python- Class Biyd: def Init_ Coe); Print (" Bird ts yeady") def culm (cele ); Print (" Goan Fasper") Class Penguin ( Birs)? eof — Init ( sere) + SUPEY( D,-Init_( ) Sh yun (tee): Print (“Run Fast") Pe fen Garay INKED IAL) « Outpur Sustm Faster yun Fact lale can use the fupey () Functton Inside ¢ne—Init_C) Method: This alloWs us fo yun — inlt_() method. [Brcapeuiacion =| Using OOP #n python , We can yettriee access 40 methods and VJarlables. phic prevents deta From dive moxification Which is cated encapsulation. In python We donate privere attribute using — ars the prefix i.e Jingle — ov Louble —- Glass Computer: def__fnit.- Csue): Sttk__ Maxprice = 900 Sek setmoarprite ( seit , Price oe fuk, 5 Maxpsice = price. C= cComputer( ) C.-- Moxpri.jo00 C. Cet max Prix (100) ble used_init.-( ) method fo etore the maximum felling Price of Computer: C. Max price +1060 Class Member cess from own | Accesstbte access spettley | Clase from serlved _|from Object a Ve anes | Aaa | UNA a aa Rs iiiclsereececee Reena a areccttteee Polymorphism fe an abttity fo uLe a Common Interface for mutiple forms (data types) Polymorpritm in python defines methods jn phe child class thet have the same name ar the method tn phe parent’ Class [ph 1s possible f2 Modify 4 method In @ child class thet it has Inhertied from child class. Parent class Class parrot + def Fly (ser): Print (" Paryot conFty") det swim (+e) Print (“parrot can't cusim") Clase penguin: def ly ( sete): Print ("Penguin can't Fug") dol wim ser): Print ("Penguin can stolm") dee Fuying_test (bird): birdflyl ) biue = Parrott ) peg = penguin () FlyIng— test ( blu). Flying — test (feg) Outpus: Payren Can Fly. Penguin Can't Py. ATUL ermag CLINKEDIN). eens iduddsenncecececee PyHON FUNCTIONS lAlhat ave Functions ? A Fanlon jt q block of lode only yuns when Ie called - In Python a Function ie detined using pne der keyword . def my— Funetton (7: print ("“yeno*) Arguments Jn a Function Frrouments are Spedified after the function name, inside the parentheses. Yeu can add 45 many argumentr as you Want Lepavate them with q Comma. def my — Function CF name) Print (fname +" Refsnes") my_ Funeton ("Emi") my - Funeton ("Tobias") my - Function Cinus") THELOAN MET GaceeRy. Arbitary Arguments STE you do not know how many arguments ¢hat Lo!!! be passed into your Funution, add a before the Prrmeter NIne In the Fanetion sefinition. de my Funurton (kids ) ‘ print ("The youngest clid is" + kid sl2) My fancelon(" sour” "y0d1", “txpark") WN eeccccdemereccece SecA - Keyword Arguments ( Kwargs) You can also send arguments tolth phe Key = Value fyntax dee my funcelon (ontids, cMid2 , Oily) : Prine ("gre Youngest crtid it" cid 3) muy — Fanceton Cchiidy = "mcb" childa = "bea", criss ="bee") = Ame Kor ‘LIMKEOIAL) - Arbitary Keyword Arguments ** Koargs EP you do not Know ho? many Keyword arguments that wii) be pacred Into your Function, add 70 asterisk: * * before the parameter name }n the Functlon definition . def my— Function (** Kid ): Print ("Hic last name se" Kid E“sname ")) my Aunetton (Frame = “Tobias”, tnome = “keFenes “Sy L KomAak CLINKEDIN). Pyrnoy Mloies UBLES 8 DATADPE Variable 1s 4 name that Is used to veer to memory jocatton . Python fs alse Knoton ag an jdentifier and Used to nold value. ‘In python , we don't need to tpeciFy tne type BF variavte python it infer and smart enough to get vaviable type. example t x =|0 name = Atul kumar" value = 12-2 Brutomag (Linc edi ). NOTES GALLERY (TELEGRAM) Variable are the example of identifier. An Identifier tr used to Identify the literals used In the Program. Rules t© name an identifier — The First chavatrey OF the variable must be alphabet or underscore (_), © All characrer except First chavatrey moy be an alphabe (A-2) , (@-z) or digit (0-9). Continue —> [OPerators in Python “The operator can be defined as 4 symbol which fs responsible for particular eperatlon between 0 operand - Operator are used tO perform operariont on variable and value. * Arithmetic operator * Assignment operator. © Comparison opesator * Jogical operaror © fdentity opevotor © Birwise Operator * Membership operator. Assignment Oferatoy Assignment operator ave used tO assign yasue to variable Deseriftion Raumns fwe IP both staremenrare hue] XeSana xe | Retums true IF one of starement tx true Reverse the yetulh, Rerums bolse ime | not(x>5 result 1S true. andX >I0 ) @ Ydentifer name must not contain any white space or

You might also like