<?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: Bruno Teixeira Lopes</title>
    <description>The latest articles on DEV Community by Bruno Teixeira Lopes (@brunotlps).</description>
    <link>https://dev.to/brunotlps</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3608752%2F1fa577b3-7b7d-4a25-ad20-f06e2c9ac4d4.jpeg</url>
      <title>DEV Community: Bruno Teixeira Lopes</title>
      <link>https://dev.to/brunotlps</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brunotlps"/>
    <language>en</language>
    <item>
      <title>Python Data Model - Part 1</title>
      <dc:creator>Bruno Teixeira Lopes</dc:creator>
      <pubDate>Tue, 28 Jul 2026 22:54:43 +0000</pubDate>
      <link>https://dev.to/brunotlps/python-data-model-part-1-492k</link>
      <guid>https://dev.to/brunotlps/python-data-model-part-1-492k</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="https://dev.to/brunotlps/modelo-de-dados-python-parte-1-3ela"&gt;Leia a versão em português deste artigo aqui&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Ever wondered why modifying a list inside a function changes the original list, but modifying a number doesn't? You've just run into one of the most fundamental — and most misunderstood — concepts in Python: its &lt;strong&gt;data model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Understanding how Python represents, identifies, and compares objects isn't just theory: it's what saves you from subtle bugs related to aliasing, incorrect comparisons, and unexpected side effects in mutable containers.&lt;/p&gt;

&lt;p&gt;In this first article of the series, we'll build the foundation you need for that: what an object actually is in Python, the difference between identity and equality, what mutability really means, how an object is born and dies, and how all of this connects once objects live inside containers.&lt;/p&gt;

&lt;p&gt;This article assumes you're already comfortable with basic Python syntax (variables, lists, dictionaries, functions). If that's you, let's get straight to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Everything is an object
&lt;/h2&gt;

&lt;p&gt;The data model defines how values are represented and how they behave in Python. &lt;strong&gt;Every piece of data your program handles&lt;/strong&gt; is an &lt;strong&gt;object&lt;/strong&gt;: numbers, strings, lists, functions, classes, and even modules (PYTHON SOFTWARE FOUNDATION, 2026a).&lt;/p&gt;

&lt;p&gt;Every Python object has three essential characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identity&lt;/strong&gt;: the object's address in memory. Checked with &lt;code&gt;id(object_name)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type&lt;/strong&gt;: defines which values and operations the object supports. Checked with &lt;code&gt;type(object_name)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value&lt;/strong&gt;: the content the object represents, which may or may not change depending on the object's &lt;strong&gt;mutability&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type affects nearly every aspect of an object's behavior. That's even true for identity: some types have a single instance shared across the entire program, which is why the correct way to compare them is by identity (&lt;code&gt;is&lt;/code&gt;), not equality (&lt;code&gt;==&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;None&lt;/code&gt; represents the absence of a value;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NotImplemented&lt;/code&gt; signals that a special operation doesn't support the operands it received;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;...&lt;/code&gt;, also called &lt;code&gt;Ellipsis&lt;/code&gt;, can be used as a sentinel and in extended slicing operations.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# &amp;lt;class 'NoneType'&amp;gt;
&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;NotImplemented&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# &amp;lt;class 'NotImplementedType'&amp;gt;
&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;             &lt;span class="c1"&gt;# &amp;lt;class 'ellipsis'&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For single-instance types, &lt;code&gt;is&lt;/code&gt; is always the recommended way to check for absence of value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt;  &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="c1"&gt;# WRONG
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="c1"&gt;# CORRECT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Identity vs Equality
&lt;/h2&gt;

&lt;p&gt;As we just saw, an object's identity refers to its memory address: &lt;code&gt;id(x)&lt;/code&gt; returns an &lt;code&gt;int&lt;/code&gt; representing the memory location where &lt;code&gt;x&lt;/code&gt; is stored. Equality, on the other hand, checks whether the values of two objects are the same, using the &lt;strong&gt;magic method&lt;/strong&gt; &lt;code&gt;__eq__&lt;/code&gt; — we'll dig deeper into that method in upcoming chapters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;is&lt;/code&gt;: compares identity.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt;: compares content or value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This distinction between identity and equality is the foundation for understanding &lt;strong&gt;mutability&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Mutable vs Immutable
&lt;/h2&gt;

&lt;p&gt;An object's mutability is determined by its type. A &lt;strong&gt;mutable&lt;/strong&gt; object can have its value changed after creation. An &lt;strong&gt;immutable&lt;/strong&gt; object cannot be modified; any operation on it produces a new object (PYTHON SOFTWARE FOUNDATION, 2026b).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Immutable&lt;/th&gt;
&lt;th&gt;Mutable&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NoneType&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;list&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;dict&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;complex&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;set&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;str&lt;/code&gt;, &lt;code&gt;tuple&lt;/code&gt;, &lt;code&gt;range&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;bytearray&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;frozenset&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Mutation&lt;/strong&gt; changes the object itself; &lt;strong&gt;reassignment&lt;/strong&gt; makes the name point to a new object.&lt;/p&gt;

&lt;p&gt;Example with a mutable object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# list is mutable
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;
&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;items&lt;/span&gt;  &lt;span class="c1"&gt;# ['a', 'b', 'c']
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt;  &lt;span class="c1"&gt;# ['a', 'b', 'c']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example with an immutable object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="c1"&gt;# int is immutable
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;  &lt;span class="c1"&gt;# a new object with value 15 is created; total now points to it
&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;  &lt;span class="c1"&gt;# 15
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt;  &lt;span class="c1"&gt;# 10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Immutable objects can hold &lt;strong&gt;references&lt;/strong&gt; to mutable objects, because immutability in Python affects only the object's reference structure, not the content it points to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alyne&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SQL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;record&lt;/span&gt;  &lt;span class="c1"&gt;# ("Alyne", ["Python", "SQL"])
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tuple &lt;code&gt;record&lt;/code&gt; still points to the same references — only the inner list was changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Object life cycle
&lt;/h2&gt;

&lt;p&gt;An object's life cycle in Python has four main phases: creation and memory allocation, attribute initialization, active use throughout the program via references, and destruction with memory release controlled by reference counting and the garbage collector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getrefcount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# number of active references to the object (includes getrefcount's own temporary reference)
&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;  &lt;span class="c1"&gt;# new reference to the same object
&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getrefcount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the count goes up, since 'a' and 'b' now point to the same object
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When an object becomes unreachable — that is, when its reference count reaches zero — it can be garbage collected by CPython through a reference-counting scheme with delayed detection of cyclically linked garbage. This cyclic collection is optional and doesn't guarantee that all garbage containing circular references will actually be collected.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Containers
&lt;/h2&gt;

&lt;p&gt;Container objects are data structures capable of holding other objects — in other words, objects that contain references to others.&lt;/p&gt;

&lt;p&gt;They can hold values of different types at the same time, support iteration through loops, and it's common to use the &lt;code&gt;in&lt;/code&gt; operator to efficiently check whether an item is present in a container — a check that, internally, relies on equality (&lt;code&gt;==&lt;/code&gt;), not identity.&lt;/p&gt;

&lt;p&gt;Main container types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lists (&lt;code&gt;list&lt;/code&gt;)&lt;/strong&gt;: ordered, mutable sequences, defined with square brackets &lt;code&gt;[]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tuples (&lt;code&gt;tuple&lt;/code&gt;)&lt;/strong&gt;: ordered, immutable sequences, defined with parentheses &lt;code&gt;()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dictionaries (&lt;code&gt;dict&lt;/code&gt;)&lt;/strong&gt;: collections of key-value pairs, defined with curly braces &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sets (&lt;code&gt;set&lt;/code&gt;)&lt;/strong&gt;: collections of unique, unordered elements, also defined with curly braces &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Watch out for a common gotcha: an empty &lt;code&gt;{}&lt;/code&gt; creates a &lt;code&gt;dict&lt;/code&gt;, not a &lt;code&gt;set&lt;/code&gt;. To create an empty set, you need to use &lt;code&gt;set()&lt;/code&gt; explicitly.&lt;/p&gt;

&lt;p&gt;Since containers hold &lt;strong&gt;references&lt;/strong&gt;, not copies, everything we've covered about identity, equality, and mutability applies directly here: modifying a mutable object inside a container affects every variable that references that same object — even if the container itself is immutable, as we saw with the tuple example in section 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;Identity, equality, mutability, life cycle, and containers aren't isolated topics — they're facets of the same core concept: in Python, variables are references to objects, not boxes holding values. Understanding that is what lets you predict, with confidence, when a change will propagate and when it will produce a brand-new object.&lt;/p&gt;

&lt;p&gt;That foundation is what the next step of the series builds on: &lt;strong&gt;magic methods&lt;/strong&gt; (dunder methods), the protocol Python uses behind seemingly simple operations like &lt;code&gt;len(obj)&lt;/code&gt;, &lt;code&gt;obj[key]&lt;/code&gt;, or &lt;code&gt;for item in obj&lt;/code&gt;. In Part 2, we'll see how these methods let objects you create behave just like the language's built-in types.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;PYTHON SOFTWARE FOUNDATION. &lt;strong&gt;3. Data model&lt;/strong&gt;. In: &lt;strong&gt;Python 3.14.6 Documentation&lt;/strong&gt;. [S. l.]: Python Software Foundation, 2026a. Available at: &lt;a href="https://docs.python.org/3/reference/datamodel.html" rel="noopener noreferrer"&gt;https://docs.python.org/3/reference/datamodel.html&lt;/a&gt;. Accessed on: Jul. 28, 2026.&lt;/p&gt;

&lt;p&gt;PYTHON SOFTWARE FOUNDATION. &lt;strong&gt;Built-in Types&lt;/strong&gt;. In: &lt;strong&gt;Python 3.14.6 Documentation&lt;/strong&gt;. [S. l.]: Python Software Foundation, 2026b. Available at: &lt;a href="https://docs.python.org/3/library/stdtypes.html" rel="noopener noreferrer"&gt;https://docs.python.org/3/library/stdtypes.html&lt;/a&gt;. Accessed on: Jul. 28, 2026.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Modelo de Dados Python - Parte 1</title>
      <dc:creator>Bruno Teixeira Lopes</dc:creator>
      <pubDate>Tue, 28 Jul 2026 22:51:54 +0000</pubDate>
      <link>https://dev.to/brunotlps/modelo-de-dados-python-parte-1-3ela</link>
      <guid>https://dev.to/brunotlps/modelo-de-dados-python-parte-1-3ela</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="https://dev.to/brunotlps/python-data-model-part-1-492k"&gt;Read this article in English here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introdução
&lt;/h2&gt;

&lt;p&gt;Se você já se perguntou por que alterar uma lista dentro de uma função muda a lista original, mas alterar um número não, você esbarrou em um dos conceitos mais fundamentais (e mais mal compreendidos) de Python: o &lt;strong&gt;modelo de dados&lt;/strong&gt; da linguagem.&lt;/p&gt;

&lt;p&gt;Entender como Python representa, identifica e compara objetos não é só teoria: é o que evita bugs sutis relacionados a aliasing, comparações incorretas e efeitos colaterais inesperados em containers mutáveis.&lt;/p&gt;

&lt;p&gt;Neste primeiro artigo da série, vamos construir a base necessária para isso: o que é um objeto em Python, a diferença entre identidade e igualdade, o que realmente significa mutabilidade, como um objeto nasce e morre, e como tudo isso se conecta quando objetos são armazenados em containers.&lt;/p&gt;

&lt;p&gt;Este artigo assume que você já tem familiaridade com a sintaxe básica de Python (variáveis, listas, dicionários, funções). Se esse é o seu caso, vamos direto ao ponto.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Tudo é objeto
&lt;/h2&gt;

&lt;p&gt;O modelo de dados define como os valores são representados e como se comportam em Python. &lt;strong&gt;Todo dado manipulado pelo programa&lt;/strong&gt; é um &lt;strong&gt;objeto&lt;/strong&gt;: números, strings, listas, funções, classes e até módulos (PYTHON SOFTWARE FOUNDATION, 2026a).&lt;/p&gt;

&lt;p&gt;Um objeto Python conta com três características essenciais:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identidade&lt;/strong&gt;: representa o endereço do objeto em memória. Consultada com &lt;code&gt;id(nome_objeto)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tipo&lt;/strong&gt;: define quais valores e operações o objeto aceita. Consultado com &lt;code&gt;type(nome_objeto)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Valor&lt;/strong&gt;: conteúdo representado pelo objeto, podendo ou não ser alterado a depender da &lt;strong&gt;mutabilidade do objeto&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Os tipos afetam quase todos os aspectos do comportamento do objeto. Isso vale até para a identidade: alguns tipos possuem uma única instância em todo o programa, e por isso a forma correta de compará-los é por identidade (&lt;code&gt;is&lt;/code&gt;), não por igualdade (&lt;code&gt;==&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;None&lt;/code&gt; representa ausência de valor;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NotImplemented&lt;/code&gt; informa que uma operação especial não oferece suporte aos operandos recebidos;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;...&lt;/code&gt;, também chamado de &lt;code&gt;Ellipsis&lt;/code&gt;, pode ser usado como uma sentinela e em operações especiais de fatiamento.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# &amp;lt;class 'NoneType'&amp;gt;
&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;NotImplemented&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# &amp;lt;class 'NotImplementedType'&amp;gt;
&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;             &lt;span class="c1"&gt;# &amp;lt;class 'ellipsis'&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Para instâncias únicas, o operador &lt;code&gt;is&lt;/code&gt; é sempre a forma recomendada de checar ausência de valor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt;  &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="c1"&gt;# ERRADO
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="c1"&gt;# CORRETO
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Identidade vs Igualdade
&lt;/h2&gt;

&lt;p&gt;Como visto anteriormente, a identidade de um objeto refere-se ao seu endereço de memória: &lt;code&gt;id(x)&lt;/code&gt; retorna um &lt;code&gt;int&lt;/code&gt; representando o espaço de memória em que &lt;code&gt;x&lt;/code&gt; está armazenado. Já a igualdade verifica se os valores de dois objetos são iguais, utilizando o &lt;strong&gt;método mágico&lt;/strong&gt; &lt;code&gt;__eq__&lt;/code&gt; — voltaremos a estudar mais sobre este método nos próximos capítulos.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;is&lt;/code&gt;: compara identidades.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt;: compara conteúdo ou valores.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Essa distinção entre identidade e igualdade é a base para entender &lt;strong&gt;mutabilidade&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Mutável vs Imutável
&lt;/h2&gt;

&lt;p&gt;A mutabilidade de um objeto é determinada pelo seu tipo. Um objeto &lt;strong&gt;mutável&lt;/strong&gt; pode ter seu valor alterado depois de criado. Um objeto &lt;strong&gt;imutável&lt;/strong&gt; não pode ser modificado; uma operação sobre ele produz outro objeto (PYTHON SOFTWARE FOUNDATION, 2026b).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Imutáveis&lt;/th&gt;
&lt;th&gt;Mutáveis&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NoneType&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;list&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;dict&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;complex&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;set&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;str&lt;/code&gt;, &lt;code&gt;tuple&lt;/code&gt;, &lt;code&gt;range&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;bytearray&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;frozenset&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A &lt;strong&gt;mutação&lt;/strong&gt; altera o próprio objeto; a &lt;strong&gt;reatribuição&lt;/strong&gt; faz o nome apontar para um novo objeto.&lt;/p&gt;

&lt;p&gt;Exemplo com objeto mutável:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# list é mutável
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;
&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;items&lt;/span&gt;  &lt;span class="c1"&gt;# ['a', 'b', 'c']
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt;  &lt;span class="c1"&gt;# ['a', 'b', 'c']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exemplo com objeto imutável:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="c1"&gt;# int é imutável
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;  &lt;span class="c1"&gt;# um novo objeto com valor 15 é criado; total passa a apontar para ele
&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;  &lt;span class="c1"&gt;# 15
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt;  &lt;span class="c1"&gt;# 10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objetos imutáveis podem conter &lt;strong&gt;referências&lt;/strong&gt; a objetos mutáveis, pois a imutabilidade em Python afeta apenas a estrutura de referências do objeto, não o conteúdo interno ao qual ele aponta.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alyne&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SQL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;record&lt;/span&gt;  &lt;span class="c1"&gt;# ("Alyne", ["Python", "SQL"])
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tupla &lt;code&gt;record&lt;/code&gt; continua apontando para as mesmas referências — apenas a lista interna foi alterada.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Ciclo de vida dos objetos
&lt;/h2&gt;

&lt;p&gt;O ciclo de vida de um objeto em Python compreende quatro fases principais: criação e alocação de memória, inicialização de atributos, uso ativo no programa por meio de referências, e destruição com liberação de memória controlada por contagem de referências e coletor de lixo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getrefcount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# número de referências ativas ao objeto (inclui a referência temporária do próprio getrefcount)
&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;  &lt;span class="c1"&gt;# nova referência para o mesmo objeto
&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getrefcount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# o valor aumenta, pois agora 'a' e 'b' apontam para o mesmo objeto
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quando um objeto se torna inacessível — ou seja, quando sua contagem de referências chega a zero — ele pode ser coletado como lixo pelo CPython através de um esquema de contagem de referências, com detecção atrasada para referências circulares. Essa coleta cíclica é opcional e não garante que todo o lixo com referências circulares será efetivamente coletado.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Containers
&lt;/h2&gt;

&lt;p&gt;Objetos containers são estruturas de dados capazes de armazenar outros objetos, ou seja, são objetos que contêm referências a outros.&lt;/p&gt;

&lt;p&gt;Eles podem guardar dados de tipos diferentes ao mesmo tempo, permitem percorrer seus elementos usando laços de repetição, e é muito comum utilizar o operador &lt;code&gt;in&lt;/code&gt; para verificar se um item está presente em um container de maneira eficiente — verificação essa que, internamente, usa igualdade (&lt;code&gt;==&lt;/code&gt;), não identidade.&lt;/p&gt;

&lt;p&gt;Tipos principais de containers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Listas (&lt;code&gt;list&lt;/code&gt;)&lt;/strong&gt;: sequências ordenadas e mutáveis, definidas por colchetes &lt;code&gt;[]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tuplas (&lt;code&gt;tuple&lt;/code&gt;)&lt;/strong&gt;: sequências ordenadas e imutáveis, definidas por parênteses &lt;code&gt;()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dicionários (&lt;code&gt;dict&lt;/code&gt;)&lt;/strong&gt;: coleções de pares chave-valor, definidos por chaves &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conjuntos (&lt;code&gt;set&lt;/code&gt;)&lt;/strong&gt;: coleções de elementos únicos e não ordenados, também definidos por chaves &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Atenção a uma pegadinha comum: &lt;code&gt;{}&lt;/code&gt; vazio cria um &lt;code&gt;dict&lt;/code&gt;, não um &lt;code&gt;set&lt;/code&gt;. Para criar um conjunto vazio, é preciso usar &lt;code&gt;set()&lt;/code&gt; explicitamente.&lt;/p&gt;

&lt;p&gt;Como containers guardam &lt;strong&gt;referências&lt;/strong&gt; e não cópias, tudo o que vimos sobre identidade, igualdade e mutabilidade se aplica de forma direta aqui: alterar um objeto mutável dentro de um container afeta todas as variáveis que referenciam esse mesmo objeto — mesmo que o container em si seja imutável, como vimos no exemplo da tupla na seção 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Conclusão
&lt;/h2&gt;

&lt;p&gt;Identidade, igualdade, mutabilidade, ciclo de vida e containers são faces do mesmo conceito central: em Python, variáveis são referências a objetos, não caixas que guardam valores. Entender isso é o que permite prever, com segurança, quando uma alteração vai se propagar e quando vai gerar um objeto novo.&lt;/p&gt;

&lt;p&gt;Essa base é o que sustenta o próximo passo da série: os &lt;strong&gt;métodos mágicos&lt;/strong&gt; (dunder methods), o protocolo que Python usa por trás de operações aparentemente simples como &lt;code&gt;len(obj)&lt;/code&gt;, &lt;code&gt;obj[chave]&lt;/code&gt; ou &lt;code&gt;for item in obj&lt;/code&gt;. Na Parte 2, vamos ver como esses métodos permitem que objetos criados por você se comportem como os tipos nativos da linguagem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;p&gt;PYTHON SOFTWARE FOUNDATION. &lt;strong&gt;3. Modelo de dados&lt;/strong&gt;. In: &lt;strong&gt;Documentação Python 3.14.6&lt;/strong&gt;. [S. l.]: Python Software Foundation, 2026a. Disponível em: &lt;a href="https://docs.python.org/pt-br/3/reference/datamodel.html" rel="noopener noreferrer"&gt;https://docs.python.org/pt-br/3/reference/datamodel.html&lt;/a&gt;. Acesso em: 28 jul. 2026.&lt;/p&gt;

&lt;p&gt;PYTHON SOFTWARE FOUNDATION. &lt;strong&gt;Tipos embutidos&lt;/strong&gt;. In: &lt;strong&gt;Documentação Python 3.14.6&lt;/strong&gt;. [S. l.]: Python Software Foundation, 2026b. Disponível em: &lt;a href="https://docs.python.org/pt-br/3/library/stdtypes.html" rel="noopener noreferrer"&gt;https://docs.python.org/pt-br/3/library/stdtypes.html&lt;/a&gt;. Acesso em: 28 jul. 2026.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
