<?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: Brain Buffering</title>
    <description>The latest articles on DEV Community by Brain Buffering (_yourbrainbuffer_).</description>
    <link>https://dev.to/_yourbrainbuffer_</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%2Forganization%2Fprofile_image%2F16093%2Fa67d365c-588b-4ccd-9284-59ec4b52214b.png</url>
      <title>DEV Community: Brain Buffering</title>
      <link>https://dev.to/_yourbrainbuffer_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_yourbrainbuffer_"/>
    <language>en</language>
    <item>
      <title>The Learner’s Point #01: Pydantic — Bringing TypeScript-Like Validation to Python</title>
      <dc:creator>Prasoon  Jadon </dc:creator>
      <pubDate>Mon, 23 Nov 2026 05:29:59 +0000</pubDate>
      <link>https://dev.to/_yourbrainbuffer_/the-learners-point-01-pydantic-bringing-typescript-like-validation-to-python-458g</link>
      <guid>https://dev.to/_yourbrainbuffer_/the-learners-point-01-pydantic-bringing-typescript-like-validation-to-python-458g</guid>
      <description>&lt;p&gt;I am not a teacher or anything. Through this series, &lt;em&gt;The Learner's Point&lt;/em&gt;, I am not here to teach you. I am just here to share what I know and what I have been learning lately.&lt;/p&gt;

&lt;p&gt;And in the comments, you can share what you know. We are going to learn from each other.&lt;/p&gt;

&lt;p&gt;So, let's start exploring something new!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Pydantic?
&lt;/h2&gt;

&lt;p&gt;If you have ever worked with TypeScript, you probably know how useful type definitions can be when working with JavaScript applications.&lt;/p&gt;

&lt;p&gt;TypeScript provides a static type system that helps developers catch type-related errors during development. It works beautifully with ecosystems like React and Node.js.&lt;/p&gt;

&lt;p&gt;But what about Python developers?&lt;/p&gt;

&lt;p&gt;Well, Pydantic is one interesting answer.&lt;/p&gt;

&lt;p&gt;You can think of Pydantic as bringing a TypeScript-like data-validation experience to Python, but with runtime validation.&lt;/p&gt;

&lt;p&gt;And why do we need it?&lt;/p&gt;

&lt;p&gt;In small applications, you can validate data manually. You can write conditions to check whether a particular value is an integer, string, or something else.&lt;/p&gt;

&lt;p&gt;But what happens when you start working with larger applications, APIs, and complex data structures?&lt;/p&gt;

&lt;p&gt;Writing validation logic for everything manually becomes repetitive and difficult to maintain.&lt;/p&gt;

&lt;p&gt;Python dictionaries also don't provide built-in validation for their contents.&lt;/p&gt;

&lt;p&gt;That's where Pydantic comes into action!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Installing Pydantic is pretty simple. You can use either pip or uv.&lt;/p&gt;

&lt;p&gt;I personally sometimes use both. And honestly, pip doesn't take that much time either!&lt;/p&gt;

&lt;p&gt;For this tutorial, let's use pip.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install pydantic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am installing it too because I don't currently have it installed in this environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our First Pydantic Program
&lt;/h2&gt;

&lt;p&gt;Before moving further, let's create our first program.&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="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;

&lt;span class="n"&gt;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;title='Pydantic is TypeScript for Python' isPublished=True

Pydantic is TypeScript for Python

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

&lt;/div&gt;



&lt;p&gt;Now, let's understand what we just wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Model and BaseModel
&lt;/h2&gt;

&lt;p&gt;Before understanding the code, let's understand two important things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is a Model?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A model is a class that defines the structure of data. It specifies which fields should exist and what type of data each field is expected to contain.&lt;/p&gt;

&lt;p&gt;For example, our Tutorial model contains two fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;title: It expects a string.&lt;/li&gt;
&lt;li&gt;isPublished: It expects a boolean value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. What is BaseModel?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;BaseModel is a fundamental class provided by Pydantic.&lt;/p&gt;

&lt;p&gt;Developers inherit from this class to create their own Pydantic models.&lt;/p&gt;

&lt;p&gt;It provides several built-in capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data validation:&lt;/strong&gt; Checks whether provided data follows the defined structure and types.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type conversion:&lt;/strong&gt; Converts compatible input values into their expected types when permitted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error handling:&lt;/strong&gt; Raises validation errors when data doesn't meet the requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serialization:&lt;/strong&gt; Converts model instances into dictionaries and JSON.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Field management:&lt;/strong&gt; Organizes data according to the fields defined in the model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In simple words, BaseModel provides the functionality, while our custom model defines the structure of the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Our First Program
&lt;/h2&gt;

&lt;p&gt;Now let's break down our code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Importing BaseModel&lt;/strong&gt;&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="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all, we import BaseModel from the Pydantic library.&lt;/p&gt;

&lt;p&gt;We need this because our custom model will inherit its functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating Our Model&lt;/strong&gt;&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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we create a class named Tutorial that inherits from BaseModel.&lt;/p&gt;

&lt;p&gt;Notice something?&lt;/p&gt;

&lt;p&gt;We haven't used a normal Python class alone. We have extended BaseModel to get Pydantic's functionality.&lt;/p&gt;

&lt;p&gt;Inside the class, we define two fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;title: str&lt;/code&gt; means title is expected to contain a string.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isPublished: bool&lt;/code&gt; means isPublished is expected to contain a boolean.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are called type annotations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Creating a Model Instance&lt;/strong&gt;&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;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we create an instance of our Tutorial model.&lt;/p&gt;

&lt;p&gt;We provide values for both fields.&lt;/p&gt;

&lt;p&gt;Pydantic checks the supplied data against the model's definitions when this instance is created.&lt;/p&gt;

&lt;p&gt;If the data is valid, the instance is created successfully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Printing the Model&lt;/strong&gt;&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints the model instance along with its field names and values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Accessing Individual Fields&lt;/strong&gt;&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also access individual fields using dot notation, just like ordinary Python objects.&lt;/p&gt;

&lt;p&gt;That's why we get the title and publication status separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens If We Provide Invalid Data?
&lt;/h2&gt;

&lt;p&gt;Let's experiment a little.&lt;/p&gt;

&lt;p&gt;What if we change our program to this?&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;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are providing a string instead of a boolean.&lt;/p&gt;

&lt;p&gt;Pydantic will raise a ValidationError because it cannot interpret &lt;code&gt;"hello"&lt;/code&gt; as a valid boolean value.&lt;/p&gt;

&lt;p&gt;This is one of the major advantages of using Pydantic.&lt;/p&gt;

&lt;p&gt;It doesn't just help us define the structure of our data; it also checks the data when we create model instances.&lt;/p&gt;

&lt;h2&gt;
  
  
  That's All for Today!
&lt;/h2&gt;

&lt;p&gt;And that's how we created our first Pydantic model using BaseModel.&lt;/p&gt;

&lt;p&gt;We have explored what Pydantic is, why developers use it, how to install it, and how to create and use our first model.&lt;/p&gt;

&lt;p&gt;There is still a lot more to explore, but let's not rush!&lt;/p&gt;

&lt;p&gt;In the next part, we will explore how Pydantic handles different data types and how type conversion works.&lt;/p&gt;

&lt;p&gt;And as always, if you know something interesting about Pydantic or have a better way to approach something discussed here, share it in the comments.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Learner's Point #01: Getting Started with Pydantic and BaseModel
&lt;/h1&gt;

&lt;p&gt;I am not a teacher or anything. Through this series, &lt;em&gt;The Learner's Point&lt;/em&gt;, I am not here to teach you. I am just here to share what I know and what I have been learning lately.&lt;/p&gt;

&lt;p&gt;And in the comments, you can share what you know. We are going to learn from each other.&lt;/p&gt;

&lt;p&gt;So, let's start exploring something new!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Pydantic?
&lt;/h2&gt;

&lt;p&gt;If you have ever worked with TypeScript, you probably know how useful type definitions can be when working with JavaScript applications.&lt;/p&gt;

&lt;p&gt;TypeScript provides a static type system that helps developers catch type-related errors during development. It works beautifully with ecosystems like React and Node.js.&lt;/p&gt;

&lt;p&gt;But what about Python developers?&lt;/p&gt;

&lt;p&gt;Well, Pydantic is one interesting answer.&lt;/p&gt;

&lt;p&gt;You can think of Pydantic as bringing a TypeScript-like data-validation experience to Python, but with runtime validation.&lt;/p&gt;

&lt;p&gt;And why do we need it?&lt;/p&gt;

&lt;p&gt;In small applications, you can validate data manually. You can write conditions to check whether a particular value is an integer, string, or something else.&lt;/p&gt;

&lt;p&gt;But what happens when you start working with larger applications, APIs, and complex data structures?&lt;/p&gt;

&lt;p&gt;Writing validation logic for everything manually becomes repetitive and difficult to maintain.&lt;/p&gt;

&lt;p&gt;Python dictionaries also don't provide built-in validation for their contents.&lt;/p&gt;

&lt;p&gt;That's where Pydantic comes into action!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Installing Pydantic is pretty simple. You can use either pip or uv.&lt;/p&gt;

&lt;p&gt;I personally sometimes use both. And honestly, pip doesn't take that much time either!&lt;/p&gt;

&lt;p&gt;For this tutorial, let's use pip.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install pydantic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am installing it too because I don't currently have it installed in this environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our First Pydantic Program
&lt;/h2&gt;

&lt;p&gt;Before moving further, let's create our first program.&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="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;

&lt;span class="n"&gt;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;title='Pydantic is TypeScript for Python' isPublished=True

Pydantic is TypeScript for Python

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

&lt;/div&gt;



&lt;p&gt;Now, let's understand what we just wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Model and BaseModel
&lt;/h2&gt;

&lt;p&gt;Before understanding the code, let's understand two important things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is a Model?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A model is a class that defines the structure of data. It specifies which fields should exist and what type of data each field is expected to contain.&lt;/p&gt;

&lt;p&gt;For example, our Tutorial model contains two fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;title: It expects a string.&lt;/li&gt;
&lt;li&gt;isPublished: It expects a boolean value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. What is BaseModel?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;BaseModel is a fundamental class provided by Pydantic.&lt;/p&gt;

&lt;p&gt;Developers inherit from this class to create their own Pydantic models.&lt;/p&gt;

&lt;p&gt;It provides several built-in capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data validation:&lt;/strong&gt; Checks whether provided data follows the defined structure and types.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type conversion:&lt;/strong&gt; Converts compatible input values into their expected types when permitted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error handling:&lt;/strong&gt; Raises validation errors when data doesn't meet the requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serialization:&lt;/strong&gt; Converts model instances into dictionaries and JSON.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Field management:&lt;/strong&gt; Organizes data according to the fields defined in the model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In simple words, BaseModel provides the functionality, while our custom model defines the structure of the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Our First Program
&lt;/h2&gt;

&lt;p&gt;Now let's break down our code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Importing BaseModel&lt;/strong&gt;&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="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all, we import BaseModel from the Pydantic library.&lt;/p&gt;

&lt;p&gt;We need this because our custom model will inherit its functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating Our Model&lt;/strong&gt;&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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we create a class named Tutorial that inherits from BaseModel.&lt;/p&gt;

&lt;p&gt;Notice something?&lt;/p&gt;

&lt;p&gt;We haven't used a normal Python class alone. We have extended BaseModel to get Pydantic's functionality.&lt;/p&gt;

&lt;p&gt;Inside the class, we define two fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;title: str&lt;/code&gt; means title is expected to contain a string.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isPublished: bool&lt;/code&gt; means isPublished is expected to contain a boolean.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are called type annotations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Creating a Model Instance&lt;/strong&gt;&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;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we create an instance of our Tutorial model.&lt;/p&gt;

&lt;p&gt;We provide values for both fields.&lt;/p&gt;

&lt;p&gt;Pydantic checks the supplied data against the model's definitions when this instance is created.&lt;/p&gt;

&lt;p&gt;If the data is valid, the instance is created successfully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Printing the Model&lt;/strong&gt;&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints the model instance along with its field names and values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Accessing Individual Fields&lt;/strong&gt;&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tutorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also access individual fields using dot notation, just like ordinary Python objects.&lt;/p&gt;

&lt;p&gt;That's why we get the title and publication status separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens If We Provide Invalid Data?
&lt;/h2&gt;

&lt;p&gt;Let's experiment a little.&lt;/p&gt;

&lt;p&gt;What if we change our program to this?&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;tutorial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pydantic is TypeScript for Python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;isPublished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are providing a string instead of a boolean.&lt;/p&gt;

&lt;p&gt;Pydantic will raise a ValidationError because it cannot interpret &lt;code&gt;"hello"&lt;/code&gt; as a valid boolean value.&lt;/p&gt;

&lt;p&gt;This is one of the major advantages of using Pydantic.&lt;/p&gt;

&lt;p&gt;It doesn't just help us define the structure of our data; it also checks the data when we create model instances.&lt;/p&gt;

&lt;h2&gt;
  
  
  That's All for Today!
&lt;/h2&gt;

&lt;p&gt;And that's how we created our first Pydantic model using BaseModel.&lt;/p&gt;

&lt;p&gt;We have explored what Pydantic is, why developers use it, how to install it, and how to create and use our first model.&lt;/p&gt;

&lt;p&gt;There is still a lot more to explore, but let's not rush!&lt;/p&gt;

&lt;p&gt;In the next part, we will explore how Pydantic handles different data types and how type conversion works.&lt;/p&gt;

&lt;p&gt;And as always, if you know something interesting about Pydantic or have a better way to approach something discussed here, share it in the comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't Know Python Yet? I've Got Something for You!
&lt;/h2&gt;

&lt;p&gt;And if you don't know Python yet, don't worry! I've got something for you.&lt;/p&gt;

&lt;p&gt;Before exploring Pydantic, you might want to get familiar with Python fundamentals. And for that, I have found some really interesting beginner-friendly tutorials.&lt;/p&gt;

&lt;p&gt;These tutorials are written by &lt;strong&gt;Star (&lt;a class="mentioned-user" href="https://dev.to/star123"&gt;@star123&lt;/a&gt;)&lt;/strong&gt; in a very friendly and creative way, using the world of Necoz and its cats to make programming concepts easier to understand.&lt;/p&gt;

&lt;p&gt;Here are some of them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/necoz/necoz-the-ufo-kingdom-python-loops-hd1"&gt;Python Loops – Necoz: The UFO Kingdom&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/necoz/the-great-cat-party-on-necoz-python-variable-1cgf"&gt;Python Variables – The Great Cat Party on Necoz Planet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/necoz/the-biggest-earthquake-on-necoz-python-operator-3ddo"&gt;Python Operators – The Biggest Earthquake on Necoz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/necoz/the-function-factory-of-necoz-learning-python-functions-2ikd"&gt;Python Functions – The Function Factory of Necoz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/necoz/necoz-school-picnic-when-30-cats-went-crazy-python-data-types-3b71"&gt;Python Data Types – Necoz School Picnic&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can also explore more tutorials on &lt;a href="https://dev.to/star123"&gt;Star's Dev.to profile&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Go through these tutorials, get familiar with the basics of Python, and then come back here to explore Pydantic – our little TypeScript-like companion in the Python ecosystem!&lt;/p&gt;

&lt;p&gt;Happy learning!&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>discuss</category>
    </item>
    <item>
      <title>C++ STL: WHERE HAVE YOU BEEN ALL MY LIFE? 😭</title>
      <dc:creator>Shruti Shahi</dc:creator>
      <pubDate>Sun, 22 Nov 2026 09:49:08 +0000</pubDate>
      <link>https://dev.to/_yourbrainbuffer_/c-stl-where-have-you-been-all-my-life-3gbl</link>
      <guid>https://dev.to/_yourbrainbuffer_/c-stl-where-have-you-been-all-my-life-3gbl</guid>
      <description>&lt;p&gt;A little college flashback.&lt;/p&gt;

&lt;p&gt;I used to be VERY much on Python's side.&lt;/p&gt;

&lt;p&gt;I mean, look at that language. You ask it to do something, and it just does it. No unnecessary drama, no demanding the world from you. Just the bare minimum.&lt;/p&gt;

&lt;p&gt;Meanwhile, C and C++ were out here demanding &lt;strong&gt;KING TREATMENT&lt;/strong&gt; for every little thing.&lt;/p&gt;

&lt;p&gt;I was genuinely pissed.&lt;/p&gt;

&lt;p&gt;Python was my favourite child, and I wasn't even trying to hide it.&lt;/p&gt;

&lt;p&gt;And then there was indentation. Python, I love you, but WHY are you having mood swings when I'm already struggling? One misplaced indentation and suddenly we're having problems.&lt;/p&gt;

&lt;p&gt;Anyway, fast-forward to college, when I was learning C++ and stumbled upon something called &lt;strong&gt;STL&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;EXCUSE ME???&lt;/p&gt;

&lt;p&gt;YOU MEAN TO TELL ME THIS EXISTS???&lt;/p&gt;

&lt;p&gt;All this time I was manually doing things, questioning my life choices, and C++ had THIS hidden somewhere?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foj3jnho2rfiqlppy218y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foj3jnho2rfiqlppy218y.png" alt=" " width="500" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suddenly my ADHD makes me sing Rihanna's &lt;em&gt;Where Have You Been&lt;/em&gt;. Coz WHY NOT?&lt;/p&gt;

&lt;p&gt;I wasn't cheating on Python. I was simply discovering that C++ had some pretty impressive qualities too. 😭&lt;/p&gt;

&lt;h2&gt;
  
  
  So, what's STL?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STL = Standard Template Library.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Basically, a collection of ready-made tools in C++ that saves us from implementing everything ourselves.&lt;/p&gt;

&lt;p&gt;Three main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Containers:&lt;/strong&gt; Store data (&lt;code&gt;vector&lt;/code&gt;, &lt;code&gt;list&lt;/code&gt;, &lt;code&gt;stack&lt;/code&gt;, &lt;code&gt;queue&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithms:&lt;/strong&gt; Perform operations (&lt;code&gt;sort()&lt;/code&gt;, &lt;code&gt;find()&lt;/code&gt;, &lt;code&gt;reverse()&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iterators:&lt;/strong&gt; Help us navigate containers (&lt;code&gt;begin()&lt;/code&gt;, &lt;code&gt;end()&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A little example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;bits/stdc++.h&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;5&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;8&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;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 2 3 5 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LOOK AT THAT.&lt;/p&gt;

&lt;p&gt;One function. Sorted numbers. No manually implementing a sorting algorithm.&lt;/p&gt;

&lt;p&gt;And suddenly, C++ wasn't looking so noob anymore.&lt;/p&gt;

&lt;p&gt;Maybe I judged you too soon, C++.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your turn:&lt;/strong&gt; What's that one programming feature you discovered and immediately thought:&lt;/p&gt;

&lt;p&gt;"WHERE HAVE YOU BEEN ALL MY LIFE?"&lt;/p&gt;

&lt;p&gt;I need to know. 😭&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Brain Buffering 🧠 — Come curious, leave slightly less confused.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cozy Bytes 🍺 | Rust::Who Owns the Cat? 🐈🦀</title>
      <dc:creator>nyaomaru</dc:creator>
      <pubDate>Fri, 20 Nov 2026 16:21:37 +0000</pubDate>
      <link>https://dev.to/_yourbrainbuffer_/cozy-bytes-rustwho-owns-the-cat-13ch</link>
      <guid>https://dev.to/_yourbrainbuffer_/cozy-bytes-rustwho-owns-the-cat-13ch</guid>
      <description>&lt;p&gt;Hoi hoi! 😸&lt;/p&gt;

&lt;p&gt;Happy Friday! Let's learn a tiny bit of Rust! 😸🍻&lt;/p&gt;

&lt;p&gt;No complicated architecture. No giant diagrams. Just a cat, a crab, and a little bit of ownership.&lt;/p&gt;

&lt;p&gt;Grab a beer! 🍺&lt;/p&gt;




&lt;h2&gt;
  
  
  🐈 Ownership::This Is My Cat!
&lt;/h2&gt;

&lt;p&gt;Rust has three simple ownership rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every value has an owner.&lt;/li&gt;
&lt;li&gt;There can only be one owner at a time.&lt;/li&gt;
&lt;li&gt;When the owner goes out of scope, the value is dropped.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's adopt a cat!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&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="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{b}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  📦 Move::Wait... Where's My Cat?!
&lt;/h2&gt;

&lt;p&gt;What happens if we try to use &lt;code&gt;a&lt;/code&gt; again?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{a}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ❌ Compile error!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WHAT?! WHERE IS MY CAT?! 🙀&lt;/p&gt;

&lt;p&gt;Ownership moved from &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Sorry, &lt;code&gt;a&lt;/code&gt;. That's not your cat anymore. 😿&lt;/p&gt;

&lt;p&gt;Rust remembers. Rust never forgets. 🦀&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Small note: This behavior applies to non-&lt;code&gt;Copy&lt;/code&gt; types like String. Simple types such as &lt;code&gt;i32&lt;/code&gt; implement Copy, so &lt;code&gt;let b = a;&lt;/code&gt; copies the value and a can still be used. 😸&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🤝 Borrowing::Can I Pet Your Cat?
&lt;/h2&gt;

&lt;p&gt;What if we just want to borrow a value without taking ownership?&lt;/p&gt;

&lt;p&gt;We can use a reference (&lt;code&gt;&amp;amp;&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{b}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{a}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WOW! Both work! 😸&lt;/p&gt;

&lt;p&gt;&lt;code&gt;a&lt;/code&gt; still owns the value. &lt;code&gt;b&lt;/code&gt; is just borrowing it.&lt;/p&gt;

&lt;p&gt;You can pet my cat, but you can't take it home. 😼&lt;/p&gt;




&lt;h2&gt;
  
  
  ✏️ MutableBorrowing::The Cats Are Multiplying!
&lt;/h2&gt;

&lt;p&gt;A shared reference (&lt;code&gt;&amp;amp;&lt;/code&gt;) doesn't let us modify the borrowed &lt;code&gt;String&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But a mutable reference (&lt;code&gt;&amp;amp;mut&lt;/code&gt;) does!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" and another cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{a}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat and another cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oh no.&lt;/p&gt;

&lt;p&gt;The cats are multiplying. 🐈🐈&lt;/p&gt;




&lt;h2&gt;
  
  
  🦀 BorrowChecker::One Human at a Time!
&lt;/h2&gt;

&lt;p&gt;Multiple humans can pet the same cat.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{a} {b}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ✅&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everyone is happy. The cat gets extra attention. 😸&lt;/p&gt;

&lt;p&gt;But what if two humans try to brush the same cat at once?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cat"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ❌ Compile error!&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" is fluffy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" is SUPER fluffy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust::ABSOLUTELY NOT. 🦀💢&lt;/p&gt;

&lt;p&gt;So here's the rule:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; — Many humans can borrow the cat for reading.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;mut&lt;/code&gt; — Only one human can borrow the cat for modification, with no other active borrows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Want to brush the cat? Wait until everyone else is done borrowing it!&lt;/p&gt;

&lt;p&gt;The crab is just trying to keep our cats safe. 🐈💚&lt;/p&gt;




&lt;h2&gt;
  
  
  🍪 Summary::One Little Byte at a Time
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Ownership&lt;/code&gt; -&amp;gt; This is my cat.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Move&lt;/code&gt; -&amp;gt; It's your cat now.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; -&amp;gt; You can pet my cat.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;mut&lt;/code&gt; -&amp;gt; You can brush my cat, but one human at a time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BorrowChecker&lt;/code&gt; -&amp;gt; The angry crab protecting our cats. 🦀&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it for today's Cozy Bytes!&lt;/p&gt;

&lt;p&gt;Rust looks scary sometimes, but we don't have to learn everything at once.&lt;/p&gt;

&lt;p&gt;One little byte at a time. 😸💚&lt;/p&gt;

&lt;p&gt;Happy Friday! 🍻&lt;/p&gt;

</description>
      <category>rust</category>
      <category>learning</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Members, listen up!</title>
      <dc:creator>Shruti Shahi</dc:creator>
      <pubDate>Tue, 17 Nov 2026 17:09:07 +0000</pubDate>
      <link>https://dev.to/_yourbrainbuffer_/members-listen-up-2i7h</link>
      <guid>https://dev.to/_yourbrainbuffer_/members-listen-up-2i7h</guid>
      <description>&lt;p&gt;If you wanna connect with me on Discord, go to &lt;a href="https://discord.com/users/1070406001011986482" rel="noopener noreferrer"&gt;mestonecold&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's get to know the everyday chaos there! 😺🥂&lt;/p&gt;

&lt;p&gt;Good night from here! Oyasumi!🌙&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
