<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>classes in python Archives -</title>
	<atom:link href="https://mitindia.in/tag/classes-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/classes-in-python/</link>
	<description></description>
	<lastBuildDate>Tue, 22 Oct 2019 10:56:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>classes in python Archives -</title>
	<link>https://mitindia.in/tag/classes-in-python/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Object Oriented Programming with Python</title>
		<link>https://mitindia.in/object-oriented-programming-with-python/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Tue, 22 Oct 2019 10:54:35 +0000</pubDate>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[classes in python]]></category>
		<category><![CDATA[object oriented in python]]></category>
		<category><![CDATA[objects in python]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=1006</guid>

					<description><![CDATA[<p>Class, Objects, and Methods in Python A class is a template for creating objects or a collection of objects. Objects have member variables and methods associated with them. In python, a class is created by using keyword class. An object is created using the constructor of the class. This object will then be called the [&#8230;]</p>
<p>The post <a href="https://mitindia.in/object-oriented-programming-with-python/">Object Oriented Programming with Python</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Class, Objects, and Methods in Python</h1>
<p><span style="color: #003366;">A class is a template for creating objects or a collection of objects.</span><br />
<span style="color: #993300;">Objects have member variables and methods associated with them. In python, a class is created by using keyword class. An object is created using the constructor of the class. This object will then be called the instance of the class.</span></p>
<h2><span style="color: #ff0000;"><strong># using OOP &#8211; Class example in Python</strong></span></h2>
<p>class Emp:<br />
def __init__(self, name, age):<br />
self.name = name<br />
self.age = age</p>
<p># object is being created here as e1.<br />
e1 = Emp(&#8220;Ram&#8221;, 31)</p>
<p># printing all class members<br />
print(e1.name)<br />
print(e1.age)</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Ram<br />
31</p></blockquote>
<p><span style="color: #ff0000;"><strong># Python class with Method body</strong></span><br />
class TestClass:</p>
<p>def func1(self):<br />
print(&#8216;Inside the function 1, part of TestClass &#8216;)<br />
print(&#8216;Function 1 over!!!!&#8217;)</p>
<p>def func2(self):<br />
print(&#8216;Inside the function 2, part of TestClass &#8216;)<br />
print(&#8216;Function 2 over!!!!&#8217;)</p>
<p># create a new TestClass object<br />
ob = TestClass()</p>
<p># Calling functions through class instance<br />
ob.func1()<br />
ob.func2()</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Inside the function 1, part of TestClass<br />
Function 1 over!!!!<br />
Inside the function 2, part of TestClass<br />
Function 2 over!!!!</p>
<p>&nbsp;</p></blockquote>
<p><span style="color: #ff0000;"><strong># class with method</strong></span><br />
class Emp:<br />
def __init__(self, name, age):<br />
self.name = name<br />
self.age = age</p>
<p>def myfunc(self):<br />
print(&#8220;Hello my name is &#8221; , self.name,&#8221;and I am&#8221;,self.age,&#8221;year old&#8221; )</p>
<p>e1 = Emp(&#8220;Ram&#8221;, 32)<br />
e1.myfunc()</p>
<p>&nbsp;</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Hello my name is Ram and I am 32 year old</p></blockquote>
<p><span style="color: #ff0000;"><strong># class with methods to raise salary by 5%</strong></span><br />
class employee:<br />
def __init__(self, first, last, sal):<br />
self.fname=first<br />
self.lname=last<br />
self.sal=sal<br />
self.email=first + &#8216;.&#8217; + last + &#8216;@mitindia.in&#8217;</p>
<p>def detail(self):<br />
return &#8216;{}&#8217;.format(self.email)</p>
<p>def apply_hike(self):<br />
self.sal=int(self.sal*(5/100)+self.sal)</p>
<p>emp1=employee(&#8216;Venkat&#8217;,&#8217;joshi&#8217;,35000)<br />
emp2=employee(&#8216;Sham&#8217;,&#8217;KK&#8217;,15000)</p>
<p>print(emp1.detail())</p>
<p>print(&#8216;Before Hike:&#8217;,emp1.sal)<br />
emp1.apply_hike()<br />
print(&#8216;After Hike:&#8217;,emp1.sal)</p>
<p>print(emp2.detail())<br />
print(&#8216;Before Hike:&#8217;,emp2.sal)<br />
emp2.apply_hike()<br />
print(&#8216;After Hike:&#8217;,emp2.sal)</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Venkat.joshi@mitindia.in<br />
Before Hike: 35000<br />
After Hike: 36750<br />
Sham.KK@mitindia.in<br />
Before Hike: 15000<br />
After Hike: 15750</p></blockquote>
<p><strong><span style="color: #ff0000;"># Class student example</span></strong></p>
<p>class Student:<br />
def __init__(std, roll, sname, course):<br />
std.roll=roll<br />
std.sname=sname<br />
std.course=course</p>
<p>s1=Student(1002, &#8216;Aditya&#8217;, &#8216;PGP-Business Analytics&#8217;)</p>
<p>print(&#8216;Roll Number:&#8217;, s1.roll)<br />
print(&#8216;Name:&#8217;,s1.sname)<br />
print(&#8216;Course:&#8217;, s1.course)</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Roll Number: 1002<br />
Name: Aditya<br />
Course: PGP-Business Analytics</p></blockquote>
<p><span style="color: #ff0000;"><strong># class without init method and use of pass keyword for not declaring method in class</strong></span><br />
class Student:<br />
pass</p>
<p># Creating objects s1 and s2 here on class Student<br />
s1=Student()<br />
s2=Student()</p>
<p>s1.fname=&#8217;Vasudeva&#8217;<br />
s1.course=&#8217;Business Intelligence&#8217;</p>
<p>s2.fname=&#8217;John&#8217;<br />
s2.course=&#8217;Artificial Intelligence&#8217;</p>
<p>print(&#8216;Student 1 Details&#8217;)<br />
print(s1.fname)<br />
print(s1.course)</p>
<p>print(&#8216;Student 2 Details&#8217;)<br />
print(s2.fname)<br />
print(s2.course)</p>
<blockquote><p><span style="color: #0000ff;"><strong>OUTPUT:</strong></span></p>
<p>Student 1 Details<br />
Vasudeva<br />
Business Intelligence<br />
Student 2 Details<br />
John<br />
Artificial Intelligence</p></blockquote>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fobject-oriented-programming-with-python%2F&amp;linkname=Object%20Oriented%20Programming%20with%20Python" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fobject-oriented-programming-with-python%2F&amp;linkname=Object%20Oriented%20Programming%20with%20Python" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fobject-oriented-programming-with-python%2F&#038;title=Object%20Oriented%20Programming%20with%20Python" data-a2a-url="https://mitindia.in/object-oriented-programming-with-python/" data-a2a-title="Object Oriented Programming with Python"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/object-oriented-programming-with-python/">Object Oriented Programming with Python</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
