<?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: Best Verie Iradukunda</title>
    <description>The latest articles on DEV Community by Best Verie Iradukunda (@bestverie).</description>
    <link>https://dev.to/bestverie</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%2F534989%2F9e83bab1-384e-4b9e-b202-07195f78d3f4.jpg</url>
      <title>DEV Community: Best Verie Iradukunda</title>
      <link>https://dev.to/bestverie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bestverie"/>
    <language>en</language>
    <item>
      <title>Exploring Python: Everything is an Object</title>
      <dc:creator>Best Verie Iradukunda</dc:creator>
      <pubDate>Thu, 14 Mar 2024 09:21:10 +0000</pubDate>
      <link>https://dev.to/bestverie/exploring-python-everything-is-an-object-549j</link>
      <guid>https://dev.to/bestverie/exploring-python-everything-is-an-object-549j</guid>
      <description>&lt;p&gt;&lt;strong&gt;ID and Type:&lt;/strong&gt;&lt;br&gt;
In Python, every object has an identity (&lt;code&gt;id&lt;/code&gt;) and a type. The &lt;code&gt;id&lt;/code&gt; uniquely identifies each object, acting as its address in memory. This means that even basic data types like integers, strings, and lists are treated as objects in Python.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example of getting ID and type of an object
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 42
print("ID:", id(x))
print("Type:", type(x))

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Results
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;ID: 140736591034160&lt;br&gt;
Type: &amp;lt;class 'int'&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutable Objects:&lt;/strong&gt;&lt;br&gt;
Some objects in Python are mutable, meaning they can be modified after creation. For instance, lists and dictionaries can have their elements or key-value pairs changed, added, or removed without changing their identity.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example of modifying a mutable object
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_list = [1, 2, 3]
my_list.append(4)
print(my_list)  # Output: [1, 2, 3, 4]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Immutable Objects:&lt;/strong&gt;&lt;br&gt;
On the other hand, immutable objects cannot be modified once they are created. Examples of immutable objects in Python include integers, strings, and tuples. Any attempt to change an immutable object results in the creation of a new object.&lt;/p&gt;

&lt;h5&gt;
  
  
  Example of trying to modify an immutable object
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_string = "Hello"
my_string += " World"
print(my_string)  # Output: Hello World

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Does it Matter and How Python Treats Mutable and Immutable Objects Differently:&lt;/strong&gt;&lt;br&gt;
Understanding the difference between mutable and immutable objects is crucial for writing efficient and bug-free Python code. Python treats mutable and immutable objects differently in terms of memory management and behaviour. Immutable objects ensure data integrity, while mutable objects offer flexibility but require careful handling to avoid unexpected changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Arguments are Passed to Functions and Implications for Mutable and Immutable Objects:&lt;/strong&gt;&lt;br&gt;
In Python, arguments are passed to functions by object reference. This means that when you pass an object to a function, you are passing a reference to the object rather than the object itself. For immutable objects, this is similar to passing by value, as the function cannot modify the original object. However, for mutable objects, changes made within the function can affect the original object outside the function, leading to unexpected behaviour if not handled correctly.&lt;/p&gt;

&lt;h5&gt;
  
  
  Passing Immutable Objects:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def modify_immutable(x):
    x += 1
    print("Inside the function:", x)

num = 10
modify_immutable(num)
print("Outside the function:", num)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Output
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;Inside the function: 11&lt;br&gt;
Outside the function: 10&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Passing mutable Objects:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def modify_mutable(lst):
    lst.append(4)
    print("Inside the function:", lst)

my_list = [1, 2, 3]
modify_mutable(my_list)
print("Outside the function:", my_list)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Output
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;Inside the function: [1, 2, 3, 4]&lt;br&gt;
Outside the function: [1, 2, 3, 4]&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>object</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
