<?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: Arvind Suthar</title>
    <description>The latest articles on DEV Community by Arvind Suthar (@arvind-suthar).</description>
    <link>https://dev.to/arvind-suthar</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%2F544067%2F68c1ad2a-d792-443a-992b-7e0cbee7b741.jpg</url>
      <title>DEV Community: Arvind Suthar</title>
      <link>https://dev.to/arvind-suthar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arvind-suthar"/>
    <language>en</language>
    <item>
      <title>Python Type Hints: Code readability perspective</title>
      <dc:creator>Arvind Suthar</dc:creator>
      <pubDate>Tue, 11 Jul 2023 18:02:58 +0000</pubDate>
      <link>https://dev.to/arvind-suthar/python-type-hints-code-readability-perspective-2a6i</link>
      <guid>https://dev.to/arvind-suthar/python-type-hints-code-readability-perspective-2a6i</guid>
      <description>&lt;p&gt;This article is a quick introduction to type hints for beginners who’ve started programming in Python. If you’re an experienced programmer, then I suggest checking out more advanced articles or documentation.&lt;/p&gt;

&lt;p&gt;Python is a dynamic language, where data/variable types aren’t generally defined. This makes Python flexible and convenient for developers because you don’t have to rigorously define and track variable types.&lt;/p&gt;

&lt;p&gt;When we’re reading code base of bigger projects, especially libraries, “Type Hints” help us to know which object types are associated with which variables. If you’re coming from a statically typed languages(C/C++, Java, TypeScript, etc), then you’ll already be familiar with type declarations and you know its importance while debugging or understanding code base.&lt;/p&gt;

&lt;p&gt;With Python 3.5, type hints officially became part of the language.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Type hinting is a formal solution to statically indicate the type of a value.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax of Python Type Hints
&lt;/h3&gt;

&lt;p&gt;Type hints involve a color and a type declaration after the first invocation/declaration of a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: str
age: int

name = input("Enter your name: ")
age = int(input("Enter your age: "))

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Type hinting Python functions
&lt;/h3&gt;

&lt;p&gt;Type hints can be implemented in Python functions to document the values they accept and return.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;greeting = "Hello, {}, you're {} years old"

def greet(user:str, age:int) -&amp;gt; str:
    return greeting.format(user, age)

name = input("Enter your name: ")
age = int(input("Enter your age: "))

print(greet(name, age))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, you can apply type hints to container objects, classes, etc. Check out following sources to take a deep dive into type hints in Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/typing.html"&gt;Python Docs
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html"&gt;Type Hints Cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>codereview</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
