<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: shashikantsingh</title>
    <description>The latest articles on DEV Community by shashikantsingh (@shashikant231).</description>
    <link>https://dev.to/shashikant231</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F497436%2F9c41bc10-8787-4878-87df-fe5db3eaed5a.png</url>
      <title>DEV Community: shashikantsingh</title>
      <link>https://dev.to/shashikant231</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shashikant231"/>
    <language>en</language>
    <item>
      <title>How to display all attributes of a class in python</title>
      <dc:creator>shashikantsingh</dc:creator>
      <pubDate>Sat, 07 Nov 2020 15:27:45 +0000</pubDate>
      <link>https://dev.to/shashikant231/how-to-display-all-attributes-of-a-class-17pj</link>
      <guid>https://dev.to/shashikant231/how-to-display-all-attributes-of-a-class-17pj</guid>
      <description>&lt;p&gt;To display all the attributes, let's create a class name Laliga,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Laliga:
    def __init__(self,team_name,star_palyer,coach,no_of_titles):
        self.team_name = team_name
        self.star_palyer = star_palyer
        self.coach = coach
        self.no_of_titles = no_of_titles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;init&lt;/strong&gt;_ method will accept the instance of that class as a self and we will have to pass the other 4 arguments.&lt;/p&gt;

&lt;p&gt;To understand self, first, create the instance of  our class, we call it "team1"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;team1 = Laliga("Real madrid","Eden hazard","Zinedine zidane",34)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so when we create method within class,it automatically receives instance of that class as the first argument which &lt;br&gt;
means calling self.team_name has the same meaning as calling team1.team_name.&lt;/p&gt;

&lt;p&gt;so now we have understood about self, go back to to printing all the attributes of team1 object to see what its attributes contain, and for that, we have to use &lt;strong&gt;dict&lt;/strong&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(team1.__dict__)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print the list of all attributes and values contained in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python class_self.py 
{'team_name': 'Real madrid', 'coach': 'Zinedine zidane', 'star_palyer': 'Eden hazard', 'no_of_titles': 34}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now you can see the attributes of team1 object .:)&lt;/p&gt;

</description>
      <category>python</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
