<?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: GeekTech</title>
    <description>The latest articles on DEV Community by GeekTech (@geektechpub).</description>
    <link>https://dev.to/geektechpub</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%2F800187%2Fd4f0d72b-b9cd-4b0c-998f-b2f27279e1f4.png</url>
      <title>DEV Community: GeekTech</title>
      <link>https://dev.to/geektechpub</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/geektechpub"/>
    <language>en</language>
    <item>
      <title>5 packages to level up your React code</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Fri, 04 Mar 2022 14:54:01 +0000</pubDate>
      <link>https://dev.to/geektechpub/5-packages-to-level-up-your-react-code-519d</link>
      <guid>https://dev.to/geektechpub/5-packages-to-level-up-your-react-code-519d</guid>
      <description>&lt;h2&gt;
  
  
  Howdy Geeks! 👋
&lt;/h2&gt;

&lt;p&gt;As a React developer, your work is to build high-quality JavaScript code. Programming is a difficult task. Indeed, you are expected to produce high-quality code while also ensuring that it is bug-free. &lt;/p&gt;

&lt;p&gt;When it comes to developer productivity and enjoyment, packages are essential. Why waste time reinventing the wheel when you can save time by doing so? There's a good chance that someone has already used a package to solve the problem you're having.&lt;/p&gt;

&lt;p&gt;So, here are 5 packages you must install to level up your React code&lt;/p&gt;

&lt;h2&gt;
  
  
  1️⃣ &lt;a href="https://eslint.org/"&gt;ES Lint&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;ESLint generates a slew of JavaScript rules that your code must adhere to. When there are tabs instead of spaces in the source code, for example, you can tell ESLint to trigger an error.&lt;/p&gt;

&lt;p&gt;You can define all of the rules one by one, but this is highly time consuming. Thankfully, ESLint config Airbnb, one of the most well-known shared ESLint configs, allows you to use some pre-configured ESLint rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  2️⃣ &lt;a href="https://www.npmjs.com/package/prettier"&gt;Prettier&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can force a JS code style preference in ESLint, but the alternatives are restricted. Using Prettier on top of ESLint is the best method to ensure that your code has a consistent appearance.&lt;/p&gt;

&lt;p&gt;Prettier cleans up your JavaScript code by parsing it and reformatting it. It will not change the logic of your code, but it will make it easier to read. Your team and you now now code in the same way. Writing code becomes a far more pleasurable process as a result. New developers can also ramp up more quickly in your codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  3️⃣ &lt;a href="https://www.framer.com/motion/"&gt;Framer Motion&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Framer Motion is a production-ready motion library for React. The motions and animations are powered by the Framer library. The package includes spring animations, scroll animations, CSS variables and so much more!&lt;/p&gt;

&lt;p&gt;Framer Motion offers more advanced listeners and also extends the basic set of React event listeners. When animating between two separate components, Framer Motion will take care of everything in between. A production-ready motion library for React. Utilize the power behind Framer, the best prototyping tool for teams.&lt;/p&gt;

&lt;h2&gt;
  
  
  4️⃣ &lt;a href="https://formik.org"&gt;Formik&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Formik is the world's most popular open source form library for React and React Native.&lt;br&gt;
Formik takes care of the repetitive and annoying stuff — keeping track of values/errors/visited fields, orchestrating validation, and handling submission — so you don’t have to. This means you spend less time wiring up state and change handlers and more time focusing on your business logic.&lt;/p&gt;

&lt;p&gt;No fancy subscriptions or observables under the hood, just plain React state and props. By staying within the core React framework and away from magic, Formik makes debugging, testing, and reasoning about your forms a breeze. If you know React, and you know a bit about forms, you know Formik!&lt;/p&gt;

&lt;h2&gt;
  
  
  5️⃣ &lt;a href="https://docz.site"&gt;Docz&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;When it comes to software development, one of the most critical and time-consuming procedures is code documentation. Docz makes it simple to create and distribute beautiful interactive code documentation.&lt;/p&gt;

&lt;p&gt;Docz uses Gatsby and Gatsby theme shadowing to let you to easily construct live-reloading, SEO-friendly, production-ready documentation sites with MDX and adjust the look, feel, and behaviour as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks for reading!
&lt;/h2&gt;

&lt;p&gt;Thank you for reading!&lt;br&gt;
Follow us on &lt;a href="https://twitter.com/geektechpub"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;br&gt;
Abhiraj&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>The terminal formatting library you need in 2022</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Sun, 27 Feb 2022 12:47:42 +0000</pubDate>
      <link>https://dev.to/geektechpub/the-terminal-formatting-library-you-need-in-2022-3e55</link>
      <guid>https://dev.to/geektechpub/the-terminal-formatting-library-you-need-in-2022-3e55</guid>
      <description>&lt;p&gt;When designing CLI applications we always face challenges as python programmers&lt;br&gt;
when it comes to making the text/UI look good. But have you ever wondered if this tedious task&lt;br&gt;
could be abstracted behind a powerful terminal UI library, which is simple to&lt;br&gt;
use yet extremely powerful? Well, you're in luck as this blog will tell you all&lt;br&gt;
you need to know about such a library: Rich.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Textualize/rich" rel="noopener noreferrer"&gt;Rich&lt;/a&gt; is a Python library for rich text&lt;br&gt;
and gorgeous formatting in the console. Rich makes it easy to add color and&lt;br&gt;
style to the CLI of your program. It supports rendering&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/latest/tables.html" rel="noopener noreferrer"&gt;tables&lt;/a&gt;, &lt;a href="https://rich.readthedocs.io/en/latest/syntax.html" rel="noopener noreferrer"&gt;syntax&lt;br&gt;
highlighted&lt;/a&gt; source code,&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/latest/progress.html" rel="noopener noreferrer"&gt;progress bars&lt;/a&gt;,&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/latest/markdown.html" rel="noopener noreferrer"&gt;markdown&lt;/a&gt;,&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/latest/traceback.html" rel="noopener noreferrer"&gt;tracebacks&lt;/a&gt; and many&lt;br&gt;
more &lt;em&gt;out of the box&lt;/em&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Compatibility
&lt;/h2&gt;

&lt;p&gt;Rich is cross-platform and also works with the True Color / Emojis from the new&lt;br&gt;
Windows Terminal. The classic terminal in Windows is limited to 16 colours.&lt;br&gt;
Rich requires Python &lt;code&gt;3.6.1&lt;/code&gt; or higher. It also works with &lt;a href="https://jupyter.org/" rel="noopener noreferrer"&gt;Jupyter&lt;br&gt;
notebooks&lt;/a&gt; without any additional configuration.&lt;/p&gt;

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

&lt;p&gt;Rich can be installed through from &lt;a href="https://pypi.org/" rel="noopener noreferrer"&gt;PyPI&lt;/a&gt; very easily using&lt;br&gt;
&lt;a href="https://pypi.org/project/pip/" rel="noopener noreferrer"&gt;pip&lt;/a&gt; (or any other package manager).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install &lt;/span&gt;rich


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

&lt;/div&gt;

&lt;p&gt;Then you can test Rich using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich


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

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FTextualize%2Frich%2Fmaster%2Fimgs%2Ffeatures.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FTextualize%2Frich%2Fmaster%2Fimgs%2Ffeatures.png" alt="rich sample&amp;lt;br&amp;gt;
output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Rich has a plethora of features under its belt. Let's have a quick look at each&lt;br&gt;
of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rich Print
&lt;/h3&gt;

&lt;p&gt;Rich provides a&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/latest/reference/init.html?highlight=print#rich.print" rel="noopener noreferrer"&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
function to facilitate printing rich output to the console. Moreover, this&lt;br&gt;
function has an identical signature to the built-in &lt;code&gt;print()&lt;/code&gt;. Let's try it!&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;

&lt;span class="c1"&gt;# Colored text
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[yellow]Yellow text[/yellow]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Stylized text
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[bold]Bold text[/bold]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Emojis
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Text with :lemon:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# All three combined
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[bold yellow]Bold yellow text with :lemon:[/bold yellow]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Pretty formatting of objects
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;locals&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FDD0Q7vN%2Fprint.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FDD0Q7vN%2Fprint.png" alt="rich print output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rich supports [Console Markup&lt;br&gt;
(&lt;a href="https://rich.readthedocs.io/en/latest/markup.html#console-markup" rel="noopener noreferrer"&gt;https://rich.readthedocs.io/en/latest/markup.html#console-markup&lt;/a&gt;) (inspired by&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/BBCode" rel="noopener noreferrer"&gt;bbcode&lt;/a&gt;) to insert colour and stylize&lt;br&gt;
the output. You can then print strings or objects to the terminal in the usual&lt;br&gt;
way. Rich will do some basic syntax highlighting and format data structures to&lt;br&gt;
make them easier to read.&lt;/p&gt;

&lt;p&gt;If you don't want to replace the built-in &lt;code&gt;print()&lt;/code&gt; in your program with Rich's&lt;br&gt;
you can use an import alias.&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;rprint&lt;/span&gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Console Markup
&lt;/h3&gt;

&lt;p&gt;Rich supports a simple markup which you can use to insert colour and styles&lt;br&gt;
virtually everywhere Rich would accept a string (e.g. &lt;code&gt;print()&lt;/code&gt; and &lt;code&gt;log()&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Run the following command to see some examples:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.markup


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;Rich's console markup is inspired by&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/BBCode" rel="noopener noreferrer"&gt;bbcode&lt;/a&gt;. You can start the&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/stable/style.html#styles" rel="noopener noreferrer"&gt;style&lt;/a&gt; by writing it&lt;br&gt;
in &lt;code&gt;[]&lt;/code&gt;. The style will be applied till the closing &lt;code&gt;[/]&lt;/code&gt;. Let's see an&lt;br&gt;
example:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[bold red]alert![/bold red] Something happened&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FNtRg4gy%2Falert.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FNtRg4gy%2Falert.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Text
&lt;/h2&gt;

&lt;p&gt;Rich has a &lt;a href="https://rich.readthedocs.io/en/stable/text.html" rel="noopener noreferrer"&gt;&lt;code&gt;Text&lt;/code&gt;&lt;/a&gt; class you&lt;br&gt;
can use to mark up strings with &lt;em&gt;color&lt;/em&gt; and &lt;em&gt;style&lt;/em&gt; attributes. You can use a&lt;br&gt;
&lt;code&gt;Text&lt;/code&gt; instance anywhere a &lt;em&gt;string&lt;/em&gt; is accepted, which gives you a lot of&lt;br&gt;
control over presentation.&lt;/p&gt;

&lt;p&gt;One way to add a style to Text is the &lt;code&gt;stylize()&lt;/code&gt; method which applies a style&lt;br&gt;
to a start and end offset. Here's an example:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.text&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stylize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bold magenta&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This will print “Hello, World!” to the terminal, with the first word in bold&lt;br&gt;
magenta.&lt;/p&gt;

&lt;p&gt;Alternatively, you can construct styled text by calling &lt;code&gt;append()&lt;/code&gt; to add a&lt;br&gt;
string and style to the end of the &lt;code&gt;Text&lt;/code&gt;. Here’s an example:&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;text&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;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bold magenta&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;text&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; World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Text attributes
&lt;/h3&gt;

&lt;p&gt;You can set several parameters on the &lt;code&gt;Text&lt;/code&gt; class's constructor to control how&lt;br&gt;
the text is displayed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;justify&lt;/code&gt; should be “left”, “centre”, “right”, or “full”, and will override
default justify behaviour.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;overflow&lt;/code&gt; should be “fold”, “crop”, or “ellipsis”, and will override the default
overflow.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;no_wrap&lt;/code&gt; prevents wrapping if the text is longer than the available width.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tab_size&lt;/code&gt; Sets the number of characters in a tab.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;code&gt;Text&lt;/code&gt; instance may be used in place of a plain string virtually everywhere&lt;br&gt;
in the Rich API, which gives you a lot of control over how text renders within&lt;br&gt;
other Rich renderables. For instance, the following example right aligns text&lt;br&gt;
within a &lt;a href="https://rich.readthedocs.io/en/stable/panel.html" rel="noopener noreferrer"&gt;&lt;code&gt;Panel&lt;/code&gt;&lt;/a&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.text&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;

&lt;span class="n"&gt;panel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;right&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;panel&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FSvsp7k8%2Fpanel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FSvsp7k8%2Fpanel.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlighting
&lt;/h2&gt;

&lt;p&gt;Rich can apply styles to text patterns that you &lt;code&gt;print()&lt;/code&gt; or &lt;code&gt;log()&lt;/code&gt;. Rich will&lt;br&gt;
highlight &lt;em&gt;numbers&lt;/em&gt;, &lt;em&gt;strings&lt;/em&gt;, &lt;em&gt;collections&lt;/em&gt;, &lt;em&gt;booleans&lt;/em&gt;, &lt;em&gt;None&lt;/em&gt;, and a few&lt;br&gt;
more exotic patterns like file paths, &lt;em&gt;URLs&lt;/em&gt;, and &lt;em&gt;UUIDs&lt;/em&gt; with the default&lt;br&gt;
settings.&lt;/p&gt;

&lt;p&gt;Setting &lt;code&gt;highlight=False&lt;/code&gt; on &lt;code&gt;print()&lt;/code&gt; or &lt;code&gt;log()&lt;/code&gt; disables highlighting, as&lt;br&gt;
does setting &lt;code&gt;highlight=False&lt;/code&gt; on the&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/stable/console.html" rel="noopener noreferrer"&gt;Console&lt;/a&gt; constructor,&lt;br&gt;
which disables it everywhere. If you disable highlighting in the constructor,&lt;br&gt;
you may still use &lt;code&gt;highlight=True&lt;/code&gt; on print/log to selectively enable it. &lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Highlighters
&lt;/h3&gt;

&lt;p&gt;You can create a custom highlighter if the default highlighting does not meet&lt;br&gt;
your needs. Extending the &lt;code&gt;RegexHighlighter&lt;/code&gt; class, which applies a style to&lt;br&gt;
any text matching a list of regular expressions, is the simplest method to do&lt;br&gt;
this.&lt;/p&gt;

&lt;p&gt;Here is an example of text that appears to be an email address:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.highlighter&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RegexHighlighter&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.theme&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Theme&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmailHighlighter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RegexHighlighter&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Apply style to anything that looks like an email.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="n"&gt;base_style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;example.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;highlights&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;(?P&amp;lt;email&amp;gt;[\w-]+@([\w-]+\.)+[\w-]+)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;example.email&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;bold magenta&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;highlighter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;EmailHighlighter&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Send funds to money@example.org&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F2tmWqtL%2Fo8KZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F2tmWqtL%2Fo8KZ.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;RegexHighlighter&lt;/code&gt; is a powerful tool, you can modify its base class&lt;br&gt;
&lt;code&gt;Highlighter&lt;/code&gt; to create your highlighting scheme. It just has one method,&lt;br&gt;
&lt;code&gt;highlight&lt;/code&gt;, to which the &lt;code&gt;Text&lt;/code&gt; to highlight is supplied.&lt;/p&gt;

&lt;p&gt;Here's an example that uses a different colour for each character: &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;from&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;randint&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.highlighter&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Highlighter&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RainbowHighlighter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Highlighter&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
            &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stylize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;color(&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;rainbow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RainbowHighlighter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;rainbow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I must not fear. Fear is the mind-killer.&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Frv1dB52%2Fo8lG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Frv1dB52%2Fo8lG.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pretty Printing
&lt;/h2&gt;

&lt;p&gt;Rich will format (i.e. pretty print) containers like lists, dicts, and sets in&lt;br&gt;
addition to syntax highlighting.&lt;/p&gt;

&lt;p&gt;To view an example of nice printed output, use the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.pretty


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

&lt;/div&gt;

&lt;p&gt;Take note of how the output will adjust to fit the terminal width.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;pprint&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;pprint()&lt;/code&gt; method to adjust how items are nicely printed with a&lt;br&gt;
few more options. Here's how you'd go about doing it:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.pretty&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt;

&lt;span class="nf"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;locals&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FjZjYmYV%2Fo8l5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FjZjYmYV%2Fo8l5.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Pretty renderable
&lt;/h4&gt;

&lt;p&gt;You can use Rich's Pretty class to inject pretty printed data into another&lt;br&gt;
renderable.&lt;/p&gt;

&lt;p&gt;The following example shows how to display attractive printed data in a basic&lt;br&gt;
panel: &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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.pretty&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Pretty&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;

&lt;span class="n"&gt;pretty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pretty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;locals&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;panel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pretty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Fmb5Dw2s%2Fo8Us.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Fmb5Dw2s%2Fo8Us.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can checkout the &lt;a href="https://rich.readthedocs.io/en/stable/pretty.html#rich-repr-protocol" rel="noopener noreferrer"&gt;Rich Repr&lt;br&gt;
Protocol&lt;/a&gt;&lt;br&gt;
to customize Rich's formatting capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logging Handler
&lt;/h2&gt;

&lt;p&gt;Rich includes a &lt;a href="https://rich.readthedocs.io/en/stable/reference/logging.html#logging" rel="noopener noreferrer"&gt;logging&lt;br&gt;
handler&lt;/a&gt;&lt;br&gt;
that formats and colors text generated by the Python logging package.&lt;/p&gt;

&lt;p&gt;An example of how to set up a rich logger is as follows:&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;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.logging&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RichHandler&lt;/span&gt;

&lt;span class="n"&gt;FORMAT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%(message)s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basicConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NOTSET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;FORMAT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;datefmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[%X]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;RichHandler&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rich&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F7RsyyxN%2Fo8U.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F7RsyyxN%2Fo8U.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because most libraries are unaware of the need to escape literal square&lt;br&gt;
brackets, rich logs will not render &lt;a href="https://rich.readthedocs.io/en/stable/markup.html#console-markup" rel="noopener noreferrer"&gt;Console&lt;br&gt;
Markup&lt;/a&gt; in&lt;br&gt;
logging by default, but you can enable it by setting &lt;code&gt;markup=True&lt;/code&gt; on the&lt;br&gt;
handler. Alternatively, you can enable it per log message by adding the&lt;br&gt;
following &lt;code&gt;extra&lt;/code&gt; argument:&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;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[bold red blink]Server is shutting down![/]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;extra&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;markup&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&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;Similarly, the highlighter can be turned off or on for each log message:&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;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;123 will not be highlighted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;extra&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;highlighter&lt;/span&gt;&lt;span class="sh"&gt;"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Handle exceptions
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;RichHandler&lt;/code&gt; can be configured to format exceptions using Rich's &lt;code&gt;Traceback&lt;/code&gt;&lt;br&gt;
class, which provides more context than a built-in exception. Set rich&lt;br&gt;
&lt;code&gt;tracebacks=True&lt;/code&gt; on the handler constructor to obtain attractive exceptions in&lt;br&gt;
your logs:&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;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.logging&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RichHandler&lt;/span&gt;

&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basicConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NOTSET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%(message)s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;datefmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[%X]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;RichHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rich_tracebacks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rich&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unable print!&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F88WGpvC%2Fo8U8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F88WGpvC%2Fo8U8.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a few more options for configuring logging output; check the&lt;br&gt;
&lt;code&gt;RichHandler&lt;/code&gt; reference for more information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Traceback
&lt;/h2&gt;

&lt;p&gt;Rich can format and highlight Python tracebacks with syntax highlighting. Rich&lt;br&gt;
tracebacks are easier to read than ordinary Python tracebacks and show more&lt;br&gt;
code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.traceback


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Printing tracebacks
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;print_exception()&lt;/code&gt; method prints a traceback for the currently handled&lt;br&gt;
exception. Here's an illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print_exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;show_locals&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&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;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F7bS4fZ0%2Fo8UZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F7bS4fZ0%2Fo8UZ.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rich displays the value of local variables for each frame of the traceback when&lt;br&gt;
the &lt;code&gt;show_locals&lt;/code&gt; argument is set to &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For a more detailed example, see&lt;br&gt;
&lt;a href="https://github.com/Textualize/rich/blob/master/examples/exception.py" rel="noopener noreferrer"&gt;&lt;code&gt;exception.py&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Traceback Handler
&lt;/h3&gt;

&lt;p&gt;Rich can be set as the default traceback handler, which means that all uncaught&lt;br&gt;
exceptions will be highlighted.&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.traceback&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt;

&lt;span class="nf"&gt;install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;show_locals&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&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;For more details on this, see &lt;a href="https://rich.readthedocs.io/en/stable/traceback.html#traceback-handler" rel="noopener noreferrer"&gt;Traceback&lt;br&gt;
Handler&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prompt
&lt;/h3&gt;

&lt;p&gt;Rich offers several &lt;code&gt;Prompt&lt;/code&gt; classes that ask for input from the user and loop&lt;br&gt;
until it receives a valid response (they all use the &lt;a href="https://rich.readthedocs.io/en/stable/console.html#input" rel="noopener noreferrer"&gt;Console&lt;br&gt;
API&lt;/a&gt; internally).&lt;br&gt;
Here's a simple illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.prompt&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;

&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The prompt can be specified as a string (which can include &lt;a href="https://rich.readthedocs.io/en/stable/markup.html#console-markup" rel="noopener noreferrer"&gt;Console&lt;br&gt;
Markup&lt;/a&gt; and&lt;br&gt;
emoji code) or as a &lt;code&gt;Text&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;You can specify a default value to be returned if the user presses return&lt;br&gt;
without typing anything:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.prompt&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;

&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Paul Atreides&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;If you provide a list of options, the prompt will loop until the user selects&lt;br&gt;
one:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.prompt&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;

&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choices&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;Paul&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;Jessica&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;Duncan&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Paul&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;You can use &lt;code&gt;IntPrompt&lt;/code&gt;, which asks for an integer, and &lt;code&gt;FloatPrompt&lt;/code&gt;, which&lt;br&gt;
asks for floats, in addition to &lt;code&gt;Prompt&lt;/code&gt;, which delivers strings.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Confirm&lt;/code&gt; class is a specific prompt for asking a basic yes/no question to&lt;br&gt;
the user. Here's an example:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.prompt&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Confirm&lt;/span&gt;

&lt;span class="n"&gt;is_rich_great&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Confirm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Do you like rich?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;is_rich_great&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The Prompt class can be customized via inheritance. Examples can be found in&lt;br&gt;
&lt;a href="https://github.com/Textualize/rich/blob/master/rich/prompt.py" rel="noopener noreferrer"&gt;&lt;code&gt;prompt.py&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Run the following command from the command line to see some of the prompts in&lt;br&gt;
action:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.prompt


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Columns
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Columns&lt;/code&gt; class allows Rich to render text or other Rich renderable in&lt;br&gt;
clean columns. To use, create a &lt;code&gt;Columns&lt;/code&gt; instance and print it to the Console&lt;br&gt;
with an iterable of renderable.&lt;/p&gt;

&lt;p&gt;The following is a very rudimentary clone of the &lt;code&gt;ls&lt;/code&gt; command in OSX/Linux for&lt;br&gt;
listing directory contents:&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;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.columns&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Columns&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&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="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Usage: python columns.py DIRECTORY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;directory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listdir&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="n"&gt;argv&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="n"&gt;columns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;equal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;columns&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FmFzBjT2%2Fo8UM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FmFzBjT2%2Fo8UM.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See&lt;br&gt;
&lt;a href="https://github.com/Textualize/rich/blob/master/examples/columns.py" rel="noopener noreferrer"&gt;&lt;code&gt;columns.py&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
for an example of a script that generates columns with more than just text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Render Groups
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Group&lt;/code&gt; class enables you to group many renderables so that they can be&lt;br&gt;
rendered in a context where only one renderable is allowed. For example, you&lt;br&gt;
might want to use a &lt;code&gt;Panel&lt;/code&gt; to display multiple renderable.&lt;/p&gt;

&lt;p&gt;To render two panels within a third, create a Group and pass the &lt;em&gt;child&lt;/em&gt;&lt;br&gt;
renderables as positional parameters, then wrap the result in another Panel:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;

&lt;span class="n"&gt;panel_group&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on blue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;World&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on red&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;panel_group&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FQDLSzRK%2Fo8U.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FQDLSzRK%2Fo8U.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method is useful when you know ahead of time which renderables will be in&lt;br&gt;
a group, but it can become inconvenient if you have a higher number of&lt;br&gt;
renderable, particularly if they are dynamic. To cope with these circumstances,&lt;br&gt;
Rich provides the &lt;code&gt;group()&lt;/code&gt; decorator. An iterator of renderables is used by&lt;br&gt;
the decorator to create a group.&lt;/p&gt;

&lt;p&gt;The following is the decorator equivalent of the preceding example:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;


&lt;span class="nd"&gt;@group&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_panels&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on blue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;World&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on red&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;get_panels&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Markdown
&lt;/h2&gt;

&lt;p&gt;Rich can render Markdown to the console. Construct a &lt;code&gt;Markdown&lt;/code&gt; object and then&lt;br&gt;
print it to the console to render markdown. Markdown is a fantastic method to&lt;br&gt;
add rich content to your command line programmes.&lt;/p&gt;

&lt;p&gt;Here's an example of how to put it to use:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.markdown&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Markdown&lt;/span&gt;

&lt;span class="n"&gt;MARKDOWN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
# This is an h1

Rich can do a pretty *decent* job of rendering markdown.

1. This is a list item
2. This is another list item
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;md&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Markdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MARKDOWN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;md&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FwYXV2w3%2Fo8Uf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FwYXV2w3%2Fo8Uf.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's worth noting that code blocks include full syntax highlighting!&lt;/p&gt;

&lt;p&gt;The Markdown class can also be used from the command line. In the terminal, the&lt;br&gt;
following example displays a readme:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.markdown README.md


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

&lt;/div&gt;

&lt;p&gt;To display the whole set of arguments for the markdown command, type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.markdown &lt;span class="nt"&gt;-h&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Padding
&lt;/h2&gt;

&lt;p&gt;To put white space around text or other renderable, use the &lt;code&gt;Padding&lt;/code&gt; class.&lt;br&gt;
The following example will print the word "Hello" with 1 character of padding&lt;br&gt;
above and below it, as well as a space on the left and right edges:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.padding&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Padding&lt;/span&gt;

&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Instead of a single value, you can describe the padding on a more detailed&lt;br&gt;
level by using a tuple of values. The top/bottom and left/right padding are set&lt;br&gt;
by a tuple of two values, whereas the padding for the top, right, bottom, and&lt;br&gt;
left sides is set by a tuple of four values. If you're familiar with CSS,&lt;br&gt;
you'll know this scheme.&lt;/p&gt;

&lt;p&gt;The following, for example, has two blank lines above and below the text, as&lt;br&gt;
well as four spaces of padding on the left and right sides:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.padding&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Padding&lt;/span&gt;

&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The Padding class also has a &lt;code&gt;style&lt;/code&gt; argument that applies a style to the&lt;br&gt;
padding and contents, as well as an &lt;code&gt;expand&lt;/code&gt; switch that can be set to &lt;code&gt;False&lt;/code&gt;&lt;br&gt;
to prevent the padding from stretching to the terminal's full width.&lt;/p&gt;

&lt;p&gt;Here's an example that exemplifies both of these points:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.padding&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Padding&lt;/span&gt;

&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;on blue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Padding can be used in any context, just like all Rich renderable. For example,&lt;br&gt;
in a &lt;code&gt;Table&lt;/code&gt;, you could add a Padding object to a row with  padding of 1 and a&lt;br&gt;
style of "on the red" to emphasise an item.&lt;/p&gt;

&lt;h3&gt;
  
  
  Padding
&lt;/h3&gt;

&lt;p&gt;Construct a Panel using the renderable as the first positional argument to&lt;br&gt;
build a border around text or another renderable. Here's an illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, [red]World!&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FnzC9cTY%2Fo8Uk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FnzC9cTY%2Fo8Uk.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By passing the &lt;code&gt;box&lt;/code&gt; argument to the Panel constructor, you can change the&lt;br&gt;
panel's style. A list of possible box styles may be found at&lt;br&gt;
&lt;a href="https://rich.readthedocs.io/en/stable/appendix/box.html#appendix-box" rel="noopener noreferrer"&gt;Box&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The panels will span the whole width of the terminal. By specifying&lt;br&gt;
&lt;code&gt;expand=False&lt;/code&gt; on the constructor, or by building the Panel with &lt;code&gt;fit()&lt;/code&gt;, you&lt;br&gt;
may make the panel fit the content. Consider the following scenario:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, [red]World!&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F9VjNxfb%2Fo8U7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F9VjNxfb%2Fo8U7.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Panel constructor takes two arguments: a &lt;code&gt;title&lt;/code&gt; argument that draws a&lt;br&gt;
title at the top of the panel, and a &lt;code&gt;subtitle&lt;/code&gt; argument that draws a subtitle&lt;br&gt;
at the bottom:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.panel&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Panel&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, [red]World!&lt;/span&gt;&lt;span class="sh"&gt;"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Welcome&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subtitle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Thank you&lt;/span&gt;&lt;span class="sh"&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FHh0WPnC%2Fo8Uh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FHh0WPnC%2Fo8Uh.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See &lt;code&gt;Panel&lt;/code&gt; for details on how to customize Panels.&lt;/p&gt;

&lt;h2&gt;
  
  
  Progress Display
&lt;/h2&gt;

&lt;p&gt;Rich can show continuously updated information about the status of long-running&lt;br&gt;
tasks, file copies, and so forth. The information presented can be customised;&lt;br&gt;
by default, a description of the 'task,' a progress bar, percentage complete,&lt;br&gt;
and anticipated time left will be provided.&lt;/p&gt;

&lt;p&gt;Multiple tasks are supported with a rich progress display, each with a bar and&lt;br&gt;
progress statistics. This can be used to keep track of several jobs that are&lt;br&gt;
being worked on in threads or processes.&lt;/p&gt;

&lt;p&gt;Try this from the command line to see how the progress display looks:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.progress


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

&lt;/div&gt;

&lt;p&gt;Progress is compatible with Jupyter notebooks, however, auto-refresh is&lt;br&gt;
disabled. When calling update, you must explicitly call &lt;code&gt;refresh()&lt;/code&gt; or set&lt;br&gt;
&lt;code&gt;refresh=True&lt;/code&gt; when calling &lt;code&gt;update()&lt;/code&gt;. Alternatively, you can use the&lt;br&gt;
&lt;code&gt;track()&lt;/code&gt; function, which performs an automatic refresh after each loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic usage
&lt;/h3&gt;

&lt;p&gt;For basic functionality, use the &lt;code&gt;track()&lt;/code&gt; function, which takes a sequence&lt;br&gt;
(such as a list or range object) and an optional job description. On each&lt;br&gt;
iteration, the track method will return values from the sequence and update the&lt;br&gt;
progress information.&lt;/p&gt;

&lt;p&gt;Here's an illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.progress&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;track&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sleep&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Processing...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Fh12Vbbs%2Fo8kj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2Fh12Vbbs%2Fo8kj.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For advanced usage, &lt;a href="https://rich.readthedocs.io/en/stable/progress.html#advanced-usage" rel="noopener noreferrer"&gt;read the&lt;br&gt;
docs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;Rich can syntax highlight various programming languages with line numbers.&lt;/p&gt;

&lt;p&gt;Construct a Syntax object and print it to the console to highlight code. Here's&lt;br&gt;
an illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.syntax&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Syntax&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;syntax.py&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;rt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;code_file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Syntax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;syntax&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FrGGcYpn%2Fo8kW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2FrGGcYpn%2Fo8kW.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may also use the from_path() alternative constructor which will load the&lt;br&gt;
code from disk and auto-detect the file type.&lt;/p&gt;

&lt;p&gt;The example above could be re-written as follows:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.syntax&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Syntax&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Syntax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;syntax.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;syntax&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;For more details, and features: &lt;a href="https://rich.readthedocs.io/en/stable/syntax.html" rel="noopener noreferrer"&gt;read the&lt;br&gt;
docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tables
&lt;/h2&gt;

&lt;p&gt;Rich's &lt;code&gt;Table&lt;/code&gt; class provides several options for displaying tabular data on&lt;br&gt;
the terminal.&lt;/p&gt;

&lt;p&gt;To draw a table, create a &lt;code&gt;Table&lt;/code&gt; object, use &lt;code&gt;add_column()&lt;/code&gt; and &lt;code&gt;add_row()&lt;/code&gt; to&lt;br&gt;
add columns and rows, and then print it to the terminal.&lt;/p&gt;

&lt;p&gt;Here's an illustration:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.console&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Console&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.table&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Table&lt;/span&gt;

&lt;span class="n"&gt;table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Table&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Star Wars Movies&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Released&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;right&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cyan&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;no_wrap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Title&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;magenta&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Box Office&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;right&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;green&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Dec 20, 2019&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;Star Wars: The Rise of Skywalker&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;$952,110,690&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;May 25, 2018&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;Solo: A Star Wars Story&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;$393,151,347&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Dec 15, 2017&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;Star Wars Ep. V111: The Last Jedi&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;$1,332,539,889&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Dec 16, 2016&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;Rogue One: A Star Wars Story&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;$1,332,439,889&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&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;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F2N9PZKT%2Fo8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.ibb.co%2F2N9PZKT%2Fo8d.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rich will compute the best column sizes for your material, and text will be&lt;br&gt;
wrapped to fit if the terminal isn't big enough. &lt;/p&gt;

&lt;p&gt;The add row method allows you to do more than just add text. You are free to&lt;br&gt;
include everything Rich is capable of rendering (including another table).&lt;/p&gt;

&lt;p&gt;For more details, &lt;a href="https://rich.readthedocs.io/en/stable/tables.html" rel="noopener noreferrer"&gt;read the&lt;br&gt;
docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tree
&lt;/h2&gt;

&lt;p&gt;Rich offers a &lt;code&gt;Tree&lt;/code&gt; class that can build a terminal tree view. A tree view is&lt;br&gt;
an excellent technique to display the contents of a file system or other&lt;br&gt;
hierarchical data. A label for each branch of the tree can be text or any other&lt;br&gt;
Rich renderable.&lt;/p&gt;

&lt;p&gt;To see an example of a Rich tree, run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.tree


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

&lt;/div&gt;

&lt;p&gt;The following code creates and prints a tree with a simple text label:&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;from&lt;/span&gt; &lt;span class="n"&gt;rich.tree&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Tree&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;

&lt;span class="n"&gt;tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rich Tree&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This will only output the word "Rich Tree" if there is just one &lt;code&gt;Tree&lt;/code&gt;&lt;br&gt;
instance. When we call add() to add new branches to the Tree, things get much&lt;br&gt;
more fascinating. The code that follows adds two more branches:&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;tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;foo&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bar&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Two branches will now be attached to the original tree via guide lines.&lt;/p&gt;

&lt;p&gt;A new Tree instance is returned when you call &lt;code&gt;add()&lt;/code&gt;. You can use this&lt;br&gt;
instance to create a more complex tree by adding more branches. Let's expand&lt;br&gt;
the tree with a couple more levels:&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;baz_tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;baz&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;baz_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[red]Red&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[green]Green&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[blue]Blue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Tree styles
&lt;/h3&gt;

&lt;p&gt;You can supply a style parameter for the entire branch, as well as a&lt;br&gt;
&lt;code&gt;guide_style&lt;/code&gt; argument for the guidelines, in the Tree constructor and &lt;code&gt;add()&lt;/code&gt;&lt;br&gt;
method. These styles are passed down through the branches and will apply to any&lt;br&gt;
sub-trees.&lt;/p&gt;

&lt;p&gt;Rich will select the thicker forms of Unicode line characters if you set &lt;code&gt;guide&lt;br&gt;
style&lt;/code&gt; to bold. Similarly, if you choose the "underline2" style, you'll get&lt;br&gt;
Unicode characters with two lines.&lt;/p&gt;
&lt;h3&gt;
  
  
  Examples
&lt;/h3&gt;

&lt;p&gt;See&lt;br&gt;
&lt;a href="https://github.com/Textualize/rich/blob/master/examples/tree.py" rel="noopener noreferrer"&gt;&lt;code&gt;tree.py&lt;/code&gt;&lt;/a&gt;,&lt;br&gt;
which can produce a tree view of a directory on your hard drive, for a more&lt;br&gt;
practical demonstration. &lt;/p&gt;
&lt;h2&gt;
  
  
  Live Display
&lt;/h2&gt;

&lt;p&gt;To animate portions of the terminal, progress bars and status indicators employ&lt;br&gt;
a live display. The &lt;code&gt;Live&lt;/code&gt; class allows you to create bespoke live displays.&lt;/p&gt;

&lt;p&gt;Run the following command to see a live display demonstration:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

python &lt;span class="nt"&gt;-m&lt;/span&gt; rich.live


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

&lt;/div&gt;

&lt;p&gt;Note: If you see ellipsis "...", it means your terminal isn't tall enough to&lt;br&gt;
display the entire table.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic usage
&lt;/h3&gt;

&lt;p&gt;Construct a &lt;code&gt;Live&lt;/code&gt; object with a renderable and use it as a context manager to&lt;br&gt;
make a live display. The live display will be visible throughout the context.&lt;br&gt;
To update the display, you can update the renderable:&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;time&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.live&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Live&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rich.table&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Table&lt;/span&gt;

&lt;span class="n"&gt;table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Row ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Description&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Level&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;Live&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;refresh_per_second&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;  &lt;span class="c1"&gt;# update 4 times a second to feel fluid
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# arbitrary delay
&lt;/span&gt;        &lt;span class="c1"&gt;# update the renderable internally
&lt;/span&gt;        &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;description &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="si"&gt;}&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;[red]ERROR&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;For more details, &lt;a href="https://rich.readthedocs.io/en/stable/live.html" rel="noopener noreferrer"&gt;read thedocs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rich supports more features like &lt;a href="https://rich.readthedocs.io/en/stable/layout.html" rel="noopener noreferrer"&gt;Layouts&lt;/a&gt;, and interacting with the &lt;a href="https://rich.readthedocs.io/en/stable/protocol.html" rel="noopener noreferrer"&gt;console protocol&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thank you for reading! Follow us on &lt;a href="https://twitter.com/geektechpub" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
for more tech blogs. To learn more about Rich you can take a look at their&lt;br&gt;
wonderful &lt;a href="https://rich.readthedocs.io/en/stable/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;, on which&lt;br&gt;
this blog was based upon.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;br&gt;
Sourajyoti&lt;/p&gt;

</description>
      <category>python</category>
      <category>terminal</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Flask Blog Tutorial #2: User Registration and Interacting with MySQL</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Mon, 21 Feb 2022 14:40:49 +0000</pubDate>
      <link>https://dev.to/geektechpub/flask-blog-tutorial-2-user-registration-and-interacting-with-mysql-2gj0</link>
      <guid>https://dev.to/geektechpub/flask-blog-tutorial-2-user-registration-and-interacting-with-mysql-2gj0</guid>
      <description>&lt;p&gt;Howdy Geeks! 👋&lt;/p&gt;

&lt;p&gt;I am back again. &lt;/p&gt;

&lt;p&gt;In this article, we will create a database to save user information for registration and create forms for registration. We will use MySQL so you can use either &lt;strong&gt;APACHE&lt;/strong&gt; or if you use Windows, you could download &lt;strong&gt;MySQL&lt;/strong&gt; and use it.&lt;/p&gt;

&lt;p&gt;Tutorial to download APACHE: &lt;a href="https://youtu.be/oJnCEqeAsUk" rel="noopener noreferrer"&gt;https://youtu.be/oJnCEqeAsUk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tutorial to download MySQL: &lt;a href="https://www.youtube.com/watch?v=H0ZpCVhS6hw" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=H0ZpCVhS6hw&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interacting with MySQL database
&lt;/h2&gt;

&lt;p&gt;After installing MySQL, open cmd and run this code to access MySQL and create databases and tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u root -p 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-u is for username,&lt;/p&gt;

&lt;p&gt;-p is for the password, and&lt;/p&gt;

&lt;p&gt;root is the main admin so we are accessing MySQL DB as a root user.&lt;/p&gt;

&lt;p&gt;To create a database: &lt;/p&gt;

&lt;p&gt;After successfully signing in, enter this command to show the created databases under your user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; SHOW DATABASES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684701839%2FCcNkRxfUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684701839%2FCcNkRxfUw.png" alt="showdb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, create your database for your flask blog app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE name_of_db; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a DB, you can verify it by doing,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHOW DATABASES; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create tables in your db:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USE name_of_db; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we create tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users(id INT(11) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100),email VARCHAR(100), username VARCHAR(30), password VARCHAR(100), registered_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates an &lt;strong&gt;&lt;em&gt;ID&lt;/em&gt;&lt;/strong&gt; table that has a primary key, &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; table of 100 characters,*** email*** table of 100 characters, &lt;strong&gt;&lt;em&gt;username&lt;/em&gt;&lt;/strong&gt; table of 30 characters, &lt;strong&gt;&lt;em&gt;password&lt;/em&gt;&lt;/strong&gt; table ( which will be hashed) of 100 characters and table for a date the user registers that automatically use the current date as the value. &lt;/p&gt;

&lt;p&gt;You should see a&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QUERY OK, 0 rows affected, 1 warning (2.34 sec)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684744072%2F2J-bCw5id.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684744072%2F2J-bCw5id.png" alt="usedb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To confirm, write this command to show created tables&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHOW TABLES; then DESCRIBE users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684546641%2Ff2KokgSSr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684546641%2Ff2KokgSSr.png" alt="describedb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flask-MySQL DB
&lt;/h3&gt;

&lt;p&gt;Next, we install flask-mysql to interact with our created tables on MySQL. &lt;/p&gt;

&lt;p&gt;To install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask-mysqldb 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, we need to validate our login and register form so let’s install** wtform**. &lt;/p&gt;

&lt;p&gt;To install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install Flask-WTF. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are saving users’ passwords we need to hash them. We can do so by using** passlib**. &lt;/p&gt;

&lt;p&gt;To install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install passlib. 

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Register form
&lt;/h2&gt;

&lt;p&gt;Let’s work on the registration form, but before that, import: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flash&lt;/strong&gt;: For flash messages on the form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redirect&lt;/strong&gt;: For redirecting users after completing the form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;url_for&lt;/strong&gt;: For creating a URL that redirects users and prevents the overhead of having to change URLs in the application (especially in templates).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;session&lt;/strong&gt;: For supporting Server-side application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;logging&lt;/strong&gt;: For functions and classes which implement a flexible event logging system for applications and libraries. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not forget to import our DB,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From flask mysqldb import MySQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next up, import wtform and the fields we will be using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From wtform import Form, StringField, TextAreaField, PasswordField, Validators
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s import passlib to hash our saved password&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From passlib.hash import sha256 crypt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating a Registration form
&lt;/h2&gt;

&lt;p&gt;We want to create our form with wtforms. To do this, we need to create class for each form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class RegisterForm(Form):
    name = StringField('Name', [validators.Length(min=5, max=40)])
    username = StringField('Username', [validators.Length(min=7, max=30)])
    email = StringField('Email', [validators.Length(min=7, max=35)])
    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Password does not match')
    ])
    confirm = PasswordField('Confirm Password')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s create a route for registration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/register', ['GET', 'POST'])
def register():
    form = RegisterForm(request.form)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, all route has a &lt;strong&gt;GET&lt;/strong&gt; method but we need to define a POST method. &lt;em&gt;Do not forget to import requests.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s create a register template and call it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form)
    return render_template('register.html', form=form)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add random text on your HTML file and go to &lt;a href="http://127.0.0.1:5000/register" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/register&lt;/a&gt;&lt;br&gt;
You should see it display. &lt;/p&gt;

&lt;p&gt;Let’s create our form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'layout.html' %}

{% block body %}
    &amp;lt;h1&amp;gt;Register&amp;lt;/h1&amp;gt;
    {% from "includes/_formhelpers.html" import render_field%}
    &amp;lt;form method="post" action=""&amp;gt;
        &amp;lt;div class="form-group"&amp;gt;
            {{render_field(form.name, class_="form-control")}}
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="form-group"&amp;gt;
            {{render_field(form.email, class_='form-control')}}
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="form-group"&amp;gt;
            {{render_field(form.username, class_='form-control')}}
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="form-group"&amp;gt;
            {{render_field(form.password, class_='form-control')}}
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="form-group"&amp;gt;
            {{render_field(form.confirm, class_='form-control')}}
        &amp;lt;/div&amp;gt;
       &amp;lt;p&amp;gt;&amp;lt;input type="submit" class="btn btn-primary" value="Submit"&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;/form&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that is done, we need to write form helpers to beautify and authenticate our created form.&lt;/p&gt;

&lt;p&gt;Create a new file under includes folder. Name the file, &lt;strong&gt;_formhelpers.html&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;{% macro render_field(field) %}
    {{ field.label }}
    {{ field(**kwargs)|safe }}
    {% if field.errors %}
        {% for error in field.errors %}
            &amp;lt;span class="help-inline"&amp;gt;{{ error }}&amp;lt;/span&amp;gt;
        {% endfor %}
    {% endif %}    
{% endmacro %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684635280%2FJPrdK-0ZS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643684635280%2FJPrdK-0ZS.png" alt="register_form.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we are done we that, we want to handle our submission. Let’s set up MySQL first. &lt;/p&gt;

&lt;p&gt;First, import flask mysql.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from data import Articles
from flask_mysqldb import MySQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then connect it to the app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Config MySQL DB
app.config ['MYSQL_HOST'] = 'localhost'
app.config ["MYSQL_USER"] = 'root'
app.config ["MYSQL_PASSWORD"] = '1234567'
app.config ["MYSQL_DB"] = 'MyFlaskBlogDB'
app.config ["MYSQL_CURSORCLASS"] = 'DictCursor'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;MYSQL_HOST&lt;/strong&gt; defines the host of the database, which is our localhost&lt;br&gt;
&lt;strong&gt;MYSQL_USER&lt;/strong&gt; is the user that authenticates the database &lt;br&gt;
&lt;strong&gt;MYSQL_PASSWORD&lt;/strong&gt; is the password for the database&lt;br&gt;
&lt;strong&gt;MYSQL_DB&lt;/strong&gt; is the database in use. &lt;br&gt;
&lt;strong&gt;MYSQL_CURSORCLASS&lt;/strong&gt;: In this case, we will set it to return information in a dictionary by default. &lt;/p&gt;

&lt;p&gt;Next, we initialize our database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql = MySQL(app)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s save information if it’s a POST request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        name = form.name.data 
        email = form.email.data
        username = form.username.data 
        password = sha256_crypt.hash(str(form.password.data))     
    return render_template('register.html', form=form)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;sha256_crypt.hash&lt;/strong&gt;: ensures that the password sent to the database is encrypted. The above code stores the information in a variable and saves it. &lt;/p&gt;

&lt;p&gt;Let’s create a cursor that can create queries or commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    password = sha256_crypt.encrypt(str(form.password.data))  

        # Creates cursor
        cur = mysql.connection.cursor() 

        cur.execute("INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)", (name, email, username, password)
) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code creates a connection to MySQL and saves the information to the tables in the database, but it won’t do anything unless we commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
# commit to db 
Mysql.connection.commit()

#close connection
cur.close
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, we want to send a flash message after the user registers. With flash messaging, we give a message and also categorize it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flash('You are now registered and may login. Welcome to BlogIt!', 'success')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;success&lt;/strong&gt; is the category of this flash message.&lt;/p&gt;

&lt;p&gt;Next, we want to redirect after a successful logging in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;redirect(url_for('index'))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we redirect, we use the url_for to define where we wish users to see next.&lt;/p&gt;

&lt;p&gt;For the flash messaging, we need where we can include it in our template so create a file under includes and call it** _messages.html**. &lt;/p&gt;

&lt;p&gt;Add this code to newly created file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% with messages = get_flashed_messages(with_categories=true) %}
  {% if messages %}
    {% for category, message in messages %}
      &amp;lt;div class="alert alert-{{ category }}"&amp;gt;{{ message }}&amp;lt;/div&amp;gt;
    {% endfor %}
  {% endif %}
{% endwith %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, include it in layout.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {% include 'includes/_navbar.html' %}
    &amp;lt;div class="container"&amp;gt;
    { include 'includes/_messages.html' %}
        {% block body%}{% endblock%}
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add a register button on our navbar. Go to* _navbar.html* add this code below the ul in the navbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        &amp;lt;ul class="nav navbar-nav navbar-right"&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href="/register"&amp;gt;Register&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the server and you would see a register button on the right side of the navbar. &lt;br&gt;
Before we test the form, let’s set a secret key. Add it to the bottom of your app.py file.&lt;br&gt;
app.secret_key = 'Secret145'. &lt;/p&gt;

&lt;p&gt;Register a user and you would see it in your database. To check in the DB,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Redirecting
&lt;/h2&gt;

&lt;p&gt;After registering, we want users to be redirected to the login page. We will discuss more in this on the next article series. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for reading!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow us on &lt;a href="https://twitter.com/geektechpub" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;br&gt;
Sophia Iroegbu.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>python</category>
      <category>mysql</category>
      <category>apach</category>
    </item>
    <item>
      <title>Everything you need to know about Go-Lang - #2</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Sun, 13 Feb 2022 16:05:55 +0000</pubDate>
      <link>https://dev.to/geektechpub/everything-you-need-to-know-about-go-lang-2-1p91</link>
      <guid>https://dev.to/geektechpub/everything-you-need-to-know-about-go-lang-2-1p91</guid>
      <description>&lt;p&gt;You probably have heard about Google's cool language called Golang. Golang is a statically typed, compiled programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is similar to C/C++, but with memory safety, garbage collection, structural typing, and CSP-style concurrency.&lt;/p&gt;

&lt;p&gt;This is the continuation of &lt;a href="https://dev.to/geektechpub/everything-you-need-to-know-about-go-lang-1-2j6o"&gt;Everything you need to know about Go-Lang - #1&lt;/a&gt;, so if you have not read that then check that out first.&lt;/p&gt;

&lt;p&gt;In the last part we have learned about Printing and Variables. We'll start off from where we left.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constants
&lt;/h2&gt;

&lt;p&gt;We have learned about variables. They are like a container which stores values of a type and can be reassigned with other values of the same type. In short that means we can change the values of variables. Now this might seen a good thing, but often time we use variables whose value we don't change at all. It's a good practice to define those as constants instead of variables. To define a value as constant we use the &lt;code&gt;const&lt;/code&gt; keyword. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3.14&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2.71828&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;const&lt;/code&gt; keyword works pretty much the same as &lt;code&gt;var&lt;/code&gt; except you cannot change it's value. Using Constants when needed is a good practice and is beneficial to compiler sometimes. We can also declare the type of constant the same way as we do to variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;aWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"This is a constant whose content cannot be changed"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are coming from other languages you maybe thinking that go follows a convention of writing constant in UPPERCASE. However, in go constant name is generally written in camelCase instead of UPPERCASE. The main reason is that variable or constant names which start with capital letter are those to be exported, if your variable or constant will not be exported to then it's useless to start it with UPPERCASE.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Turn
&lt;/h2&gt;

&lt;p&gt;Try using &lt;em&gt;constants&lt;/em&gt; in your previous programs of Golang instead of &lt;em&gt;var&lt;/em&gt; for those whose values that aren't changing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;In Go, there are various kinds of operator that used for certain functions. These operators can be differentiated into:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arithmetic Operator.&lt;/li&gt;
&lt;li&gt;Relational Operator.&lt;/li&gt;
&lt;li&gt;Logical Operator.&lt;/li&gt;
&lt;li&gt;Bitwise Operator.&lt;/li&gt;
&lt;li&gt;Assignment Operator.&lt;/li&gt;
&lt;li&gt;Misc. Operator.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Arithmetic Operator
&lt;/h2&gt;

&lt;p&gt;We have used Arithmetic Operator earlier. Let's learn about them again. Arithmetic Operators are used to perform, mathematical operations like addition, subtraction, division, multiplication, and modulus (remainder).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Addition: The &lt;code&gt;+&lt;/code&gt; operator is to add two operand. &lt;/li&gt;
&lt;li&gt;Subtraction: The &lt;code&gt;-&lt;/code&gt; operator is to subtract two operand.&lt;/li&gt;
&lt;li&gt;Multiplication: The &lt;code&gt;*&lt;/code&gt; operator is to multiply two operand.&lt;/li&gt;
&lt;li&gt;Division: The &lt;code&gt;\&lt;/code&gt; operator is to divide two operand. Dividing two integer returns an integer.&lt;/li&gt;
&lt;li&gt;Modulus: The &lt;code&gt;%&lt;/code&gt; operator return the remainders of two operand.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sum = "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Difference = "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Product = "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Quotient = "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Remainder = "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&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;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;Sum = 22
Difference = 18
Product = 40
Quotient = 10
Remainder = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Relational Operators
&lt;/h2&gt;

&lt;p&gt;Relational operators are used for comparison of two expressions. Relational operators return &lt;code&gt;true&lt;/code&gt; if the condition satisfies or else it returns &lt;code&gt;false&lt;/code&gt;. Here are the Relational operators:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt;: Is &lt;em&gt;equality&lt;/em&gt; operator, it is used to check whether the left and right-hand side operands are equal. It returns &lt;code&gt;true&lt;/code&gt; if both are equal or else returns &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;2.0&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;true
false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;!=&lt;/code&gt;: Is the &lt;em&gt;not equal to&lt;/em&gt;. It is used to check whether the two operands are different. It returns &lt;code&gt;true&lt;/code&gt; if they are not equal and returns &lt;code&gt;false&lt;/code&gt; if they were. &lt;code&gt;!&lt;/code&gt; is the &lt;em&gt;not&lt;/em&gt; operator.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3.14&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;22&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;7&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;true
false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt;: Known as &lt;em&gt;greater than&lt;/em&gt; operator. It is used to check whether the left-hand is greater than the right-hand side. It returns &lt;code&gt;true&lt;/code&gt; if the left-hand side operand is greater than the right otherwise it returns &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&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;false
false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt;: Known as &lt;em&gt;greater than equal to&lt;/em&gt; operator. It is used to check whether the left-hand side operand is greater than or equal to the right-hand side. It returns &lt;code&gt;true&lt;/code&gt; if the left operand is greater than or equal to the right-hand side or else returns &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&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;false
true
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt;: Known as &lt;em&gt;lesser than&lt;/em&gt; operator. It returns &lt;code&gt;true&lt;/code&gt; if left-hand side is lesser than the right-hand side, or else returns &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&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;true
false
false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt;: Known as the &lt;em&gt;lesser than equal to&lt;/em&gt; operator. It returns &lt;code&gt;true&lt;/code&gt; if the left-hand side is lesser than or equal to the right-hand side, or else returns &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;5&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;true
true
false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Logical Operator
&lt;/h2&gt;

&lt;p&gt;They are used to combine two or more conditions or to change the checking of the original statement. The logical operators are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;: The &lt;em&gt;logical and&lt;/em&gt; operator returns &lt;code&gt;true&lt;/code&gt; if all the conditions that are being joined by it are &lt;code&gt;true&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;9&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;false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;||&lt;/code&gt;: The &lt;em&gt;logical or&lt;/em&gt; operator returns &lt;code&gt;true&lt;/code&gt; if any of the conditions that it joins are &lt;code&gt;true&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;9&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;true
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;!&lt;/code&gt;: The &lt;em&gt;logical not&lt;/em&gt;, also mentioned as &lt;em&gt;not&lt;/em&gt; operator earlier, negates the result of the expression.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&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;false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bitwise Operators
&lt;/h2&gt;

&lt;p&gt;In Go language, there are 6 bitwise operators which work at bit level or used to perform bit by bit operations. Bitwise operators works with binary. Following are the bitwise operators: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; (bitwise &lt;em&gt;AND&lt;/em&gt;): Takes two numbers as operands and does &lt;em&gt;AND&lt;/em&gt; on every bit. The result of &lt;em&gt;AND&lt;/em&gt; is 1 only if both bits are 1.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;|&lt;/code&gt; (bitwise &lt;em&gt;OR&lt;/em&gt;): Takes two numbers as operands and does &lt;em&gt;OR&lt;/em&gt; on every bit of two numbers. The result of &lt;em&gt;OR&lt;/em&gt; is 1 any of the two bits is 1.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;^&lt;/code&gt;(bitwise XOR): Takes two numbers as operands and does &lt;em&gt;XOR&lt;/em&gt; on every bit of two numbers. The result of &lt;em&gt;XOR&lt;/em&gt; is 1 if the two bits are different.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; (left shift): Takes two numbers, left shifts the bits of the first operand, the second operand specifies the number of places to shift.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; (right shift): Takes two numbers, right shifts the bits of the first operand, the second operand specifies the number of places to shift.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;^&lt;/code&gt; (AND NOT): This is the bit clear operator.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Assignment Operators
&lt;/h2&gt;

&lt;p&gt;Assignment operator is used to assign values to a variable. The left-hand side is the variable and the right-hand side is the value. Different types of Assignment Operators are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;=&lt;/code&gt;: Known as equals to. It assigns the values at the right to the left-hand side.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a +=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a + ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a -=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a - ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a *=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a * ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a /=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a / ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a %=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a % ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a &amp;amp;=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a &amp;amp; ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a ^=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a ^ ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a |=&lt;/code&gt;: Other form of writing &lt;code&gt;a = a | ...&lt;/code&gt;, where a is a variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conditional Statements
&lt;/h2&gt;

&lt;p&gt;Suppose you ask your friend to buy you a lego space shuttle for yourself, but if it isn't available then buy a lego star wars. Over here you can see that we have a condition for us that if a lego space space shuttle then buy it or else buy a lego star wars. In the world of computers, programmer often face the same situation, where they need to so check if a certain condition is &lt;code&gt;true&lt;/code&gt; then execute one set of commands, or else execute another set of commands.&lt;/p&gt;

&lt;p&gt;In Go there are two types of Conditional statements&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If / Else&lt;/li&gt;
&lt;li&gt;Switch-Case&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  If / Else
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt; keyword is used to check whether one condition is &lt;code&gt;true&lt;/code&gt;. If the condition is &lt;code&gt;true&lt;/code&gt; then it executes the code block. Or else it doesn't execute that block. The syntax of &lt;code&gt;if&lt;/code&gt; is every simple :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;// &amp;lt;= `true` &lt;/span&gt;
    &lt;span class="n"&gt;statements&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;//&amp;lt;= true&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The statement here is true"&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;Before I give any further examples, we need to talk about operators.&lt;/p&gt;

&lt;p&gt;The equality operator &lt;code&gt;==&lt;/code&gt; is use to check where that the left-hand side and right-hand side of the operation are equal. This is not to be confused with the &lt;code&gt;=&lt;/code&gt; equal to , which is used to assign values from right to the left.&lt;/p&gt;

&lt;p&gt;Let's now see some more examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;//&amp;lt;= true&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Condition "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&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;Condition true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;10 / 2 == 5&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt;. Let's now see another example where our condition isn't &lt;code&gt;true&lt;/code&gt; and see the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;// &amp;lt;= false&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="m"&gt;3&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;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we see we receive no output as our condition didn't satisfy and hence didn't enter the block.&lt;/p&gt;

&lt;p&gt;In the last example we saw how if our condition doesn't satisfied then it doesn't print anything. If we want do execute some other statements when the condition doesn't satisfy we can use &lt;code&gt;else&lt;/code&gt; keyword, right next to the closing braces of the &lt;code&gt;if&lt;/code&gt;. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Condition true"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Condition true"&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;Condition true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use &lt;code&gt;else if&lt;/code&gt; statement if we want to add another condition.&lt;br&gt;
Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&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="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scanf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%v %v"&lt;/span&gt;&lt;span class="p"&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="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// takes user input and splits it by space&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"More than 5"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Equal to 5"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Less than 5"&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;You might want to check about different operators, as it will be helpful in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  Switch case:
&lt;/h2&gt;

&lt;p&gt;When you have too many conditions to check from, using &lt;code&gt;if else if else&lt;/code&gt; might be time consuming, so a better and more efficient way would be using &lt;code&gt;switch case&lt;/code&gt;. Here's the syntax of &lt;code&gt;switch case&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch can compare values and executes the piece of code of that case. This is especially helpful during menus where user input depends on what to do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// takes user-input&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Prinln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Other value"&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;This block of code compares the value of &lt;code&gt;v&lt;/code&gt; with the values written after case and before &lt;code&gt;:&lt;/code&gt;. Now if you are coming from other languages then you must be thinking the above code is technically wrong as if any of the cases gets executed those below it will get executed too, known as fall-through error. Fall-through error is an error that causes the fall of control of the program. It is common in other languages like C/C++, Java, etc. However in Go, fall-through isn't the default. We can create fall through explicitly by using the &lt;code&gt;fallthrough&lt;/code&gt; keyword however. Like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fallthrough&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Gophers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fallthrough&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hi"&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;Hello
Gophers
Hi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fall-through was actually useful when multiple statements had the same block of statements to execute. However in Golang to counter the problem of not having fall-through, they introduced checking of multiple values in one case. Like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"odd"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"even"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Prinln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"None"&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;Now depending on the value of &lt;code&gt;v&lt;/code&gt;, the program will print &lt;code&gt;odd&lt;/code&gt;, &lt;code&gt;even&lt;/code&gt; or &lt;code&gt;none&lt;/code&gt;. This is a faster way than the use of &lt;code&gt;fallthrough&lt;/code&gt; and also easier to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nested
&lt;/h2&gt;

&lt;p&gt;You have multiple conditional statements inside another conditional statement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Turn
&lt;/h2&gt;

&lt;p&gt;Take two variable, assign values to them in such a way that the first one is greater than the second one. Divide them (both must be integer). Now If your result is less than 5, find out whether the first number is greater than 10, and less than 20, else check if the difference between the number is divisible by 2 or not (If a number is divisible by another number, then the remainder between them is 0). &lt;/p&gt;

&lt;p&gt;Take four variables and assign them with random letters and check how many vowels are there. If there are none, print an appropriate message&lt;/p&gt;

&lt;h2&gt;
  
  
  Loop
&lt;/h2&gt;

&lt;p&gt;Sometimes as a programmer you want your statement to run over and over again until the condition gets satisfied. So today we shall learn about loops.&lt;/p&gt;

&lt;p&gt;Now if you are coming from other languages you may think there are two or three (for older languages) types of loops. In Golang, there's only one. That is everyone's favorite for loop. For loop has different syntax, you can use the right one depending on what you need. The most basic one is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;decrement&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;change&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;statements&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we first have to initialize it with some value. Then we have to check whether a condition is &lt;code&gt;true&lt;/code&gt; so that the loop runs, and then change the value. The statements in a loop with runs continuously until the condition is &lt;code&gt;false&lt;/code&gt;, when for the next iteration the condition becomes &lt;code&gt;false&lt;/code&gt; the loop will not run.&lt;br&gt;
Suppose we want to print numbers from 0 to 10, we can easily do that using loops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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;1
2
3
4
5
6
7
8
9
10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can omit the initializing or the increment/decrement, but we have to initialize the value for the variable we use in loop, or else we will get an error. Also if we don't change the value of that variable the loop might run forever and never end generation some behavior we don't want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&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;The first loop will print the values from 0 to 9 and the second loop from 0 to 5. Golang offer some syntactical sugar for us, if we don't initialize and increment/decrement as the same line as for loop declaration we can omit the semi colons. Please don't if we omit both, then only we can use this. This makes for loop very similar to while loop. We shall use this syntax of for loop when we don't know the number of iterations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&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;Another import function is the &lt;code&gt;range&lt;/code&gt;d for. It is used to get the index number and the uses with it. We shall understand better when we deal with string and arrays/slices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&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;0 "H"
1 "E"
2 "L"
3 "L"
4 "O"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We shall use more of this function in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nested
&lt;/h2&gt;

&lt;p&gt;You can write a for loop inside another for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Your Turn
&lt;/h2&gt;

&lt;p&gt;Try to print this patter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*
**
***
****
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Hint: You have to use &lt;code&gt;Print&lt;/code&gt; and &lt;code&gt;Println&lt;/code&gt; functions. Remember to use nested loops)&lt;/p&gt;

&lt;h2&gt;
  
  
  Struct
&lt;/h2&gt;

&lt;p&gt;A structure or &lt;code&gt;struct&lt;/code&gt; in Golang is a user-defined type that allows to group/combine items of possibly different types into a single type. Any real-world entity which has some set of properties/fields can be represented as a &lt;code&gt;struct&lt;/code&gt;. This concept is generally compared with the classes in object-oriented programming. It can be termed as a lightweight class that does not support inheritance but supports composition. &lt;/p&gt;

&lt;p&gt;Suppose you define a &lt;code&gt;struct&lt;/code&gt; which contains your address, these shall be the variables inside it: &lt;em&gt;House Name&lt;/em&gt; (string), &lt;em&gt;Street Name&lt;/em&gt; (String), &lt;em&gt;City&lt;/em&gt; (String), &lt;em&gt;Pincode&lt;/em&gt; (int).&lt;/p&gt;

&lt;p&gt;Let's define our &lt;code&gt;struct&lt;/code&gt;. Till now we were declaring function inside our &lt;code&gt;main&lt;/code&gt; function, but &lt;code&gt;struct&lt;/code&gt; definitions are generally done outside &lt;code&gt;main&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;houseName&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;streetName&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;pincode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&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;Now let's allocate values into it and print it. To allocate values we must always pass them in order, or else we can assign it as &lt;code&gt;name&lt;/code&gt;:&lt;code&gt;value&lt;/code&gt;.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;houseName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;streetName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;pincode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;houseName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"City Mall"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;streetName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"MG Road"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Delhi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;pincode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;110007&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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;{City Mall MG Road Delhi 110007}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way is without using the name of the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;houseName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;streetName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;pincode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"City Mall"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"MG Road"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"Delhi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="m"&gt;110007&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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;{City Mall MG Road Delhi 110007}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what if you want to access any fields from the &lt;code&gt;struct&lt;/code&gt;, how would you do so? &lt;/p&gt;

&lt;p&gt;We can do so by using dot notation &lt;code&gt;.&lt;/code&gt; followed by the name of the fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;houseName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;streetName&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;pincode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;houseName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"City Mall"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;streetName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"MG Road"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Delhi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;pincode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;110007&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;city&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;Delhi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Your Turn
&lt;/h2&gt;

&lt;p&gt;Make a &lt;code&gt;struct&lt;/code&gt; called Birds, in it create 4 fields &lt;em&gt;Name&lt;/em&gt; (string), &lt;em&gt;CanFly&lt;/em&gt; (bool), &lt;em&gt;isRare&lt;/em&gt; (bool), &lt;em&gt;Age&lt;/em&gt; (int). In &lt;code&gt;main&lt;/code&gt; function pass the name of a bird, pass &lt;code&gt;true&lt;/code&gt; and false if it can fly or is it rare, and pass the age of it, and print the &lt;code&gt;struct&lt;/code&gt;. If &lt;code&gt;canFly&lt;/code&gt; or &lt;code&gt;isRare&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt; then print an appropriate message. (Hint: Use &lt;code&gt;if&lt;/code&gt; / &lt;code&gt;else&lt;/code&gt; to check ).&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this post, we have learned how to declare constants, how to check conditions and perform operations, we have learned how to loop a set of statements depending on our need, and then we closed it all up with structures. We have also learned about different operators. In the next part, we shall learn more about &lt;em&gt;structs&lt;/em&gt;, &lt;em&gt;functions&lt;/em&gt;, &lt;em&gt;data type&lt;/em&gt; and &lt;em&gt;pointers&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for Reading
&lt;/h3&gt;

&lt;p&gt;Follow us on &lt;a href="https://twitter.com/GeektechPub"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Until we meet again,&lt;/p&gt;

&lt;p&gt;Arindol Sarkar.&lt;/p&gt;

</description>
      <category>go</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>30 games you can play to learn to code</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Tue, 08 Feb 2022 12:32:44 +0000</pubDate>
      <link>https://dev.to/geektechpub/30-games-you-can-play-to-learn-to-code-4lc0</link>
      <guid>https://dev.to/geektechpub/30-games-you-can-play-to-learn-to-code-4lc0</guid>
      <description>&lt;h2&gt;
  
  
  Howdy Geeks! 👋
&lt;/h2&gt;

&lt;p&gt;It is the 21st Century and games are an integral part of our lives. But did you know you can learn coding by playing games? If not, you’re in luck today. &lt;/p&gt;

&lt;p&gt;Presenting the 30 games you can play to learn a variety of programming languages&lt;/p&gt;

&lt;h2&gt;
  
  
  1.  &lt;a href="https://lab.reaal.me/jsrobot/"&gt;JS Robot&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn the basics of javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://play.elevatorsaga.com/"&gt;Elevator Saga&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Make the elevators efficiently move people through floors and avoid backlogs.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.  &lt;a href="https://warriorjs.com/"&gt;WarriorJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Code your way through dungeons, prove your skills, and get hired.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.  &lt;a href="https://alexnisnevich.github.io/untrusted/"&gt;Untrusted&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A text-based dungeon crawler where you progress with the aid of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.  &lt;a href="http://www.crunchzilla.com/code-monster"&gt;Code Monster&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn the basics of JavaScript on the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  6.  &lt;a href="https://jsfight.club/"&gt;JavaScript Fight Club&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Playing Javascript games to master fundamentals.&lt;/p&gt;

&lt;h2&gt;
  
  
  7.  &lt;a href="https://yare.io/"&gt;Yare&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Real-Time Strategy game where you control your units by writing JavaScript code.&lt;/p&gt;

&lt;h2&gt;
  
  
  8.  &lt;a href="https://www.codewars.com/"&gt;Codewars&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Improve your skills by training with others on real code challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  9.  &lt;a href="https://www.codingame.com/"&gt;CodinGame&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Games and Programming Challenges to Code Better.&lt;/p&gt;

&lt;h2&gt;
  
  
  10.  &lt;a href="http://cyber-dojo.org/"&gt;Cyber Dojo&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hone your programming skills in a huge range of languages, writing code to pass tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  11.  &lt;a href="https://grasshopper.codes/"&gt;Grasshopper&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Fun, quick lessons on your phone that teach you to write real JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  12.  &lt;a href="https://alf.nu/ReturnTrue"&gt;ReturnTrue&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A game where you learn about booleans, return true to win.&lt;/p&gt;

&lt;h2&gt;
  
  
  13. &lt;a href="https://codingfantasy.com/"&gt;Coding Fantasy&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn to code in a revolutionary new, fun, and effective way.&lt;/p&gt;

&lt;h2&gt;
  
  
  14. &lt;a href="https://codecombat.com/play"&gt;CodeCombat&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn how to code by playing a game.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. &lt;a href="https://mmckegg.github.io/web-audio-school/"&gt;Web Audio School&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Interactive WebAudio tutorials.&lt;/p&gt;

&lt;h2&gt;
  
  
  16. &lt;a href="https://www.codingame.com/start"&gt;CodinGame&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A challenge-based training platform where you can play with the hottest programming topics.&lt;/p&gt;

&lt;h2&gt;
  
  
  17. &lt;a href="https://david-peter.de/cube-composer/"&gt;Cube Composer&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A puzzle game inspired by functional programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  18. &lt;a href="https://www.codecademy.com"&gt;Codecademy&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn to code interactively, for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  19. &lt;a href="https://www.codeavengers.com/"&gt;Code Avengers&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn to build websites, apps, and games in a fun and effective way.&lt;/p&gt;

&lt;h2&gt;
  
  
  20. &lt;a href="https://cssbattle.dev/"&gt;CSS Battle&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Test your CSS skills by solving coding challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  21. &lt;a href="https://flukeout.github.io/"&gt;CSS Dinner&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Solve challenges by arranging dishes and food and learn about CSS selectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  22. &lt;a href="https://cssgridgarden.com/"&gt;Grid Garden&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Write CSS code to grow your carrot garden while learning about the CSS grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  23. &lt;a href="http://www.flexboxdefense.com/"&gt;Flexbox defense&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Stop the incoming enemies from getting past your defenses using CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  24. &lt;a href="http://flexboxfroggy.com/"&gt;Flexbox froggy&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Master CSS Flexbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  25. &lt;a href="http://www.hexinvaders.com/"&gt;Hex Invaders&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Learn about HEX colors by shooting off aliens having the same colors!&lt;/p&gt;

&lt;h2&gt;
  
  
  26. &lt;a href="https://github.com/turkishviking/Python-Robocode"&gt;Robocode&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Code robots, win matches, rank up.&lt;/p&gt;

&lt;h2&gt;
  
  
  27. &lt;a href="https://py.checkio.org/"&gt;Checkio&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Practice Python Online&lt;/p&gt;

&lt;h2&gt;
  
  
  28. &lt;a href="https://github.com/ryanb/ruby-warrior"&gt;Ruby Warrior&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A game written in Ruby for learning Ruby and artificial intelligence.&lt;/p&gt;

&lt;h2&gt;
  
  
  29. &lt;a href="https://mystery.knightlab.com/"&gt;SQL Mystery&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;There's been a Murder in SQL City! The SQL Murder Mystery is designed to be both a self-directed lesson to learn SQL concepts and commands and a fun game for experienced SQL users to solve an intriguing crime.&lt;/p&gt;

&lt;h2&gt;
  
  
  30. &lt;a href="https://ohmygit.org/"&gt;Oh my git!&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;An open-source game about learning Git!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thank you for reading!
&lt;/h3&gt;

&lt;p&gt;Follow us on &lt;a href="https://twitter.com/geektechpub"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;/p&gt;

&lt;p&gt;Abhiraj.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Everything you need to know about Go-Lang - #1</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Fri, 04 Feb 2022 07:50:02 +0000</pubDate>
      <link>https://dev.to/geektechpub/everything-you-need-to-know-about-go-lang-1-2j6o</link>
      <guid>https://dev.to/geektechpub/everything-you-need-to-know-about-go-lang-1-2j6o</guid>
      <description>&lt;p&gt;You probably have heard about Google's cool language called Golang. Golang is a  statically typed, compiled programming language designed at Google by &lt;em&gt;Robert Griesemer, Rob Pike, and Ken Thompson&lt;/em&gt;. It is similar to C/C++,  but with &lt;em&gt;memory safety, garbage collection, structural typing, and CSP-style concurrency&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  History of Golang
&lt;/h2&gt;

&lt;p&gt;Go was developed by Google in 2007 to improve programming productivity. The developers wanted to amending the limitations of languages in that era while keeping the useful features like,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;static typing and run-time efficiency&lt;/li&gt;
&lt;li&gt;readability and usability&lt;/li&gt;
&lt;li&gt;high-performance networking and multiprocessing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The developers of Golang had shared dislikes for the language C++, which is also said to be the primary motivation behind this project. Announced in 2009, the version 1.0 was not released until 2012. Go is widely used in google and by open source developers. Go 1 guarantees compatibility for the language specification and major parts of the standard library. All versions up to the current Go 1.17 release have maintained this promise.&lt;br&gt;
Each major Go release is supported until there are two newer major releases.&lt;/p&gt;
&lt;h2&gt;
  
  
  Design
&lt;/h2&gt;

&lt;p&gt;Go is based on C, with an emphasis on greater simplicity and safety. The language has a syntax and environment adopting patterns more common in dynamic languages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Optional concise variable declaration and initialization through type inference.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fast compilation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remote package management with online package documentation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Golang takes an distinctive approach towards a particular problem :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Built-in concurrency primitives: light-weight processes, channels, and the select statement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An interface system in place of virtual inheritance, and type embedding instead of non-virtual inheritance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A toolchain that, by default, produces statically linked native binaries without external dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The languages was tried  to be kept as simple as possible, which in the process had to eliminate some common features found in other programming languages, but Golang makes up for those, by alternating features or other approaches.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started with Go
&lt;/h2&gt;

&lt;p&gt;So before we dive into the programming part first we need to install Golang in your pc. You can get Go from their &lt;a href="https://go.dev/dl/"&gt;official  download website&lt;/a&gt;. Download the latest version for your os. &lt;/p&gt;

&lt;p&gt;Now that we have Golang, we need to find a proper text editor. Now for the basics part or for the learning part you can use the Go Official &lt;a href="https://go.dev/play/"&gt;PlayGround&lt;/a&gt;, or else you might wanna use any among these : &lt;a href="http://liteide.org/en/"&gt;LiteIDE&lt;/a&gt;, &lt;a href="https://atom.io/packages/go-plus"&gt;Atom with Go-Plus&lt;/a&gt;, &lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt;, or &lt;a href="https://www.jetbrains.com/go/"&gt;GoLand&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have both Go and a text editor with us, we might begin our journey through go.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hello  World
&lt;/h2&gt;

&lt;p&gt;So let's now write our first hello world program. Now every go program starts with a package. A package is collection of source codes which are complied together. Among all the package there must be atleast one package named main. Since, we are getting started with Golang, we shall have only one package as of now. After defining our own package now we need to import another package. Now this might sound confusing but trust me when you will do the practical work it will all be a piece of cake. So where was I ?  Oh yes, we would now have to import another package. This package is the &lt;a href="https://pkg.go.dev/fmt"&gt;fmt&lt;/a&gt; package which stands for format. This package contains vital functions for printing, scanning in certain formats. So we have different ways of importing package. Since we are importing one package we shall use this syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When there are multiple packages to import we shall use this syntax:&lt;br&gt;
(suppose we are importing &lt;a href="https://pkg.go.dev/math"&gt;math&lt;/a&gt; along with fmt)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="s"&gt;"math"&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now that we have learned how to import now let's write the main function. So let's ask the basics first. What is the main function ? In simple terms it is the block from which the complier starts executing your program, one project must have atleast one main function. So how do we define functions now ?&lt;br&gt;
Well after import we define functions like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="s"&gt;"math"&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&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;Please note it is a syntax error if we change the way braces are put. The opening brace must be on the same line as the defination of the function and the closing brace on the next line where the function is suppose to end. We shall learn more about other functions later into the series.&lt;/p&gt;

&lt;p&gt;Now that we have define our main functions now let's write some command to make it work. Since printing &lt;em&gt;hello world&lt;/em&gt;, is believed to be the basics of a solid foundation, we shall print &lt;em&gt;hello world&lt;/em&gt; as our first program. So to print we shall use the &lt;em&gt;Println&lt;/em&gt; function from the &lt;em&gt;fmt&lt;/em&gt; package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To print a word or sentence we shall write it inside the parenthesis with single or double quotes on it. To do any mathematical operations, we shall not provide any quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World!"&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;Now that we wrote our first program let's analyse what we've written. So as said first we declared our &lt;strong&gt;main&lt;/strong&gt; package, then we've imported the &lt;strong&gt;fmt&lt;/strong&gt; package, we have removed the math package as we are not using it now. Keeping unused package, variables or functions generated error. Then we have declared our &lt;strong&gt;main&lt;/strong&gt; function which is the entry point of every program. Inside our main function we have used the &lt;strong&gt;Println&lt;/strong&gt; function from the &lt;strong&gt;fmt&lt;/strong&gt; package to print hello world. Now the &lt;strong&gt;Println&lt;/strong&gt; function prints and sends the cursor to the next line. If you have other print statement and you don't want it to go to the next line us &lt;strong&gt;Print&lt;/strong&gt; instead of &lt;strong&gt;Println&lt;/strong&gt;. Now according to our analysis our program must print &lt;strong&gt;Hello World&lt;/strong&gt;.  If u are using a text editor, make sure to save your file, open up terminal, navigate to the folder in which your source code is saved and type in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;sourcecodefilename&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before running this command make sure to save your file as a &lt;strong&gt;.go&lt;/strong&gt; file&lt;/p&gt;

&lt;h2&gt;
  
  
  Output :
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;Hello&lt;/span&gt; &lt;span class="n"&gt;World&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Try it Yourself
&lt;/h2&gt;

&lt;p&gt;Now that you have printed hello world try printing these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your name and your profession in same line using two different statements. (Hint : Use two print statement)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your name and your profession in different line.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The value of : 6 .0/ 2.0 (2.0*3.0) &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Now that you know how to print statements let's try storing data. Now variables are like a container that stores data which might change in the future. Variables can store numbers, sentences, characters, arrays, objects, etc.&lt;/p&gt;

&lt;p&gt;Let's learn how to declare a variable. Variable declaration is simple. We need to use the &lt;strong&gt;var&lt;/strong&gt; keyword, followed by a name. This name can be anything from an alphabet to a word. We cannot use numbers, or special symbols as variable names, to store data. Given below is an example of how to declare a variable and store values to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;decimal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;45.6&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;Word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we know how to declare a variable and initialize it let's learn how to declare a variable and assign it's value later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must be wondering why have I written the keyword &lt;strong&gt;int&lt;/strong&gt; after the variable name. Well in our previous example where we declared the name of our variable and assigned it a value immediately, our compiler was seeing the value and understanding what type can the variable hold. By what type a variable can hold, I mean one variable can hold data s of only one type that is either integers (numbers without decimal), floating-point numbers (numbers with decimals), string (anything within double quotes), etc. We shall learn more about these later.  So as of now we need to know that when we are declaring a variable we must also mention it's type. We use &lt;strong&gt;int&lt;/strong&gt; for integer, &lt;strong&gt;float&lt;/strong&gt; for floating point, &lt;strong&gt;string&lt;/strong&gt; for string type. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;float&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, what if we assign values of other type to these variable. When we are assigning values of int to float, the compiler will implicitly change the integer to float, but while doing the vice versa, we shall get the error, as integer variables are only capable of storing numbers without decimal.&lt;br&gt;
You can however explicitly type case it and store it, but then it would store till the decimal and not after the decimal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;float&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="c"&gt;// No error&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;4.2&lt;/span&gt; &lt;span class="c"&gt;// Error &lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;float&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2.3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//No error as explicit typecasting &lt;/span&gt;
&lt;span class="c"&gt;//c stores 2 as int not capable of storing  after decimal&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However if you have the values ready and want to assign to the variable right away without using &lt;strong&gt;var&lt;/strong&gt; or declaring the type, well we have some syntactical sugar for that! Just write the variable name followed by := and the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;45&lt;/span&gt;
&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;4.6&lt;/span&gt;
&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;
&lt;span class="c"&gt;// We don't have to declare the type or use var keyword&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Previously we had seen how to add values to these variables now let's learn how to perform arithmetic operations with those:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; 
&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="c"&gt;// add&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&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="c"&gt;// subtract&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="c"&gt;//multiply&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&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="c"&gt;//divide&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
 &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="c"&gt;//mixed operation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to print variable we don't need quotes, we just write the variable name in the parenthesis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&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="c"&gt;// a is a declared variable with some value in it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great ! We now know how to score values in variable, declare variable, initialize variable, add values of other types into it, and print it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it Yourself:
&lt;/h2&gt;

&lt;p&gt;Now that you know how to work with variables try these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Declare two variables with values 3 and 5 respectively, and interchange their value using a third variable, and Print the result (Hint : If a was 3 and b was 5, the final result should be a = 5 and b = 3)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare two variables with value 4 and 6 and interchange their values without using a third variable, and Print the result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare two variables of int type and assign float values to it by typecasting, and Print the result. (Hint : a = int (3.4))&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary :
&lt;/h2&gt;

&lt;p&gt;In this part we've learned about how to write a go program. We have written our first go program, by printing hello world. Then we've learned about variables and different functions. In the next part we shall go over : Constants, user input, conditional structs, loops, functions, structs. &lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;p&gt;Thank you for reading!&lt;br&gt;
Follow us on &lt;a href="https://twitter.com/geektechpub"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;br&gt;
Arindol&lt;/p&gt;

</description>
      <category>go</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Flask Blog Tutorial #1: Getting Started</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Wed, 02 Feb 2022 14:53:07 +0000</pubDate>
      <link>https://dev.to/geektechpub/flask-blog-tutorial-1-getting-started-10cd</link>
      <guid>https://dev.to/geektechpub/flask-blog-tutorial-1-getting-started-10cd</guid>
      <description>&lt;p&gt;Howdy Geeks! 👋&lt;/p&gt;

&lt;p&gt;I will build a web app alongside this article and this will act as a guide as I would share my struggles and we will debug as well. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's git this shii!&lt;/strong&gt; 🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Flask?
&lt;/h3&gt;

&lt;p&gt;Flask is a python framework that is used to create microservice web applications. It aims to keep projects simple but extensible and it won't decide for you, i.e. It allows you to create functionalities and has fewer packages or tell you what type of database to be used in a project. &lt;/p&gt;

&lt;h3&gt;
  
  
  Virtual Environment
&lt;/h3&gt;

&lt;p&gt;In python, before doing anything. It is advisable to create a virtual environment and use it to install frameworks so your project folder looks neat. &lt;/p&gt;

&lt;p&gt;To do so,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python3 -m venv name_of_virtual_enviroment 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;name_of_virtual_enviroment should be replaced by the name you choose for your virtual environment (env or myenv or venv). In this article, I will call mine &lt;strong&gt;venv&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To activate the created virtual environment: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For windows OS&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;venv\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Mac OS&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; venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This activates the virtual environment, and you can now install packages for your projects. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;NB: Do this in your project folder. *&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flask Installation
&lt;/h3&gt;

&lt;p&gt;To do this:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Flask is now installed! You are a flask developer!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643197122186%2Fzr6JAMqqT.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643197122186%2Fzr6JAMqqT.gif" alt="happy_gif.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, onto your code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a python file and name, &lt;strong&gt;app.py&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This file will be like an entry file which will lead to other codebases in the projects. &lt;/p&gt;

&lt;p&gt;Write this in your app.py file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask

app = Flask(__name__)

if __name__ == '__main__':
    app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run it by doing on your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643198520346%2FH5pEnrdGK8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643198520346%2FH5pEnrdGK8.png" alt="snip1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the URL on your terminal and you should see this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643198924362%2FizF1CNzIS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643198924362%2FizF1CNzIS.png" alt="NotFound.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see this because we have created no routes for home or index, so let's do that right away.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Routes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/')
def index():
        return "Hello World!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a route and will return ** Hello World ** when we run the URL again. &lt;/p&gt;

&lt;p&gt;Kill your terminal and run &lt;strong&gt;python app.py&lt;/strong&gt; again, then you will see it. &lt;/p&gt;

&lt;p&gt;It's a pain in the ass to always restart the terminal to see your recent changes on your localhost right? An easy way to do this is by adding a debug mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;OR&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;app = Flask(__name__)
app.debug =True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anyone would suffice. Restart your terminal and whatever change you make will automatically update on the web.&lt;/p&gt;

&lt;h3&gt;
  
  
  Templating your index file
&lt;/h3&gt;

&lt;p&gt;Normally we do not return strings, we return templates. Flask uses **&lt;br&gt;
Jinja templating**.&lt;/p&gt;
&lt;h4&gt;
  
  
  Jinja Templating
&lt;/h4&gt;

&lt;p&gt;In your application, you will use templates to render HTML, which will display in the browser. In Flask, we configured Jinja to auto escape any data that is rendered in HTML templates. This means that it’s safe to render user input; any characters entered that could mess with the HTML, such as &amp;lt; and &amp;gt; will be escaped with safe values that look the same in the browser but don’t cause unwanted effects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have imported render_template, which is a flask package. &lt;/p&gt;

&lt;p&gt;Now, let's return it so it shows on our localhost.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/')
def index():
        return render_template('home.html')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What did we just do? &lt;/p&gt;

&lt;p&gt;We just rendered an HTML template in your python file. Cool, right? &lt;/p&gt;

&lt;h4&gt;
  
  
  Creating template folder
&lt;/h4&gt;

&lt;p&gt;Create a template folder and an HTML file will name it &lt;strong&gt;home.html&lt;/strong&gt; as stated in the previous code and create another file named layout.html&lt;/p&gt;

&lt;p&gt;Write the following code in your layout file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;My Flask Blog&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    {% block body%}{% endblock%}
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add this code to your home.html:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'layout.html' %}

{% block body %}
    Home
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will be your result: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643203859906%2FPJpws97mE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643203859906%2FPJpws97mE.png" alt="home.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bootstrap installation
&lt;/h3&gt;

&lt;p&gt;We would use the bootstrap CDN instead of flask-bootstrap because flask-bootstrap limits us and it is complex to use. Use this link to understand bootstrap in flask better: &lt;a href="https://youtu.be/IRNMEML3RoA" rel="noopener noreferrer"&gt;https://youtu.be/IRNMEML3RoA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy this code and paste it after the title tag in your layout.html like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;title&amp;gt;My Flask Blog&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, copy the JavaScript code and paste it above the ending body tag like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap should be enabled. Reload and you will notice changes such as a change in fonts and no padding. &lt;/p&gt;

&lt;h3&gt;
  
  
  NavBar
&lt;/h3&gt;

&lt;p&gt;The NavBar should show on every route page so it will be added to the HTML layout file. Create a folder under templates folder named &lt;strong&gt;includes&lt;/strong&gt; then create a file named _navbar.html and it should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643206455653%2FS8-c2Y1K5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643206455653%2FS8-c2Y1K5.png" alt="Screenshot 2022-01-26 151340.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add this code to _navbar file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;nav class="navbar navbar-default"&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;div class="navbar-header"&amp;gt;
        &amp;lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"&amp;gt;
          &amp;lt;span class="sr-only"&amp;gt;Toggle navigation&amp;lt;/span&amp;gt;
          &amp;lt;span class="icon-bar"&amp;gt;&amp;lt;/span&amp;gt;
          &amp;lt;span class="icon-bar"&amp;gt;&amp;lt;/span&amp;gt;
          &amp;lt;span class="icon-bar"&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;/button&amp;gt;
        &amp;lt;a class="navbar-brand" href="#"&amp;gt;My Flask BlogApp&amp;lt;/a&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div id="navbar" class="collapse navbar-collapse"&amp;gt;
        &amp;lt;ul class="nav navbar-nav"&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href="/"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href="/about"&amp;gt;About&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href="/articles"&amp;gt;Articles&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/nav&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then include the navbar file in your layout file and wrap the body in a container class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% include 'includes/_navbar.html' %}
    &amp;lt;div class="container"&amp;gt;
        {% block body%}{% endblock%}
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refresh and you notice that the content now has padding.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;about&lt;/strong&gt; and &lt;strong&gt;articles&lt;/strong&gt; links won't work because we have not created the routes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Home routes
&lt;/h3&gt;

&lt;p&gt;Let's finish our home route&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'layout.html' %}

{% block body %}
    &amp;lt;div class="jumbtron text-center"&amp;gt;
        &amp;lt;h1&amp;gt;Welcome To BlogIt!&amp;lt;/h1&amp;gt;
        &amp;lt;p class="lead"&amp;gt; This is a blog application built on the Python Flask Framework and users can upload articles.&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
{% endblock %
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should be your result so far: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643210739785%2FC8vkF2KR2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643210739785%2FC8vkF2KR2.png" alt="Screenshot 2022-01-26 162511.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, I decided to give it a name. &lt;/p&gt;

&lt;h3&gt;
  
  
  About routes
&lt;/h3&gt;

&lt;p&gt;Let's create a route for our about page&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/about')
def about():
    return render_template('about.html')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And create our HTML file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'layout.html' %}

{% block body %}
    &amp;lt;h1&amp;gt;About Us&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Est aperiam aspernatur facilis distinctio commodi maxime repellendus recusandae, beatae nihil molestias voluptatum, itaque possimus porro, eum praesentium saepe maiores repudiandae ea.&amp;lt;/p&amp;gt;
{% endblock %}

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

&lt;/div&gt;



&lt;p&gt;Refresh and check about page. &lt;/p&gt;

&lt;h3&gt;
  
  
  Article routes
&lt;/h3&gt;

&lt;p&gt;We would be using dummy data to display our articles page. First, let's create our routes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/articles')
def articles():
    return render_template('articles.html')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create our dummy article data. Create a file called &lt;strong&gt;article_data.py&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Add some dummy data in it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Articles():
    articles = [       
        {
            'id': 1, 
            'title': 'First article',
            'body': 'lorem ipsum adhdyj gdh gsshh hu gdh gsh asgasd sdivvvvFVUvjusd cgibsdjhbcu',
            'author': 'Sophia Iroegbu',
            'date_created': '26-01-2022'
        },
        {
            'id': 2, 
            'title': 'Second article',
            'body': 'lorem ipsum adhdyj gdh gsshh hu gdh gsh asgasd sdivvvvFVUvjusd cgibsdjhbcu',
            'author': 'John Doe',
            'date_created': '25-01-2022'
        },
        {
            'id': 3, 
            'title': 'Third article',
            'body': 'lorem ipsum adhdyj gdh gsshh hu gdh gsh asgasd sdivvvvFVUvjusd cgibsdjhbcu',
            'author': 'Mary James',
            'date_created': '26-01-2022'
        },
    ]


    return articles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterward, import it and add it to your article route in your entry file, app.py. It should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template
from article_data import Articles

app = Flask(__name__)

Articles = Articles()

@app.route('/')
def index():
    return render_template('home.html')

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/articles')
def articles():
    return render_template('articles.html', articles = Articles)

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will create a function that will loop through our data in article_data and display the article titles on the articles page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'layout.html' %}

{% block body %}
  &amp;lt;h1&amp;gt;Articles&amp;lt;/h1&amp;gt;
  &amp;lt;ul class="list-group"&amp;gt;
    {% for article in articles %}
      {{article.title}}
    {% endfor %}
  &amp;lt;/ul&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then wrap the articles in an unordered list of items and each title in an ordered list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;h1&amp;gt;Articles&amp;lt;/h1&amp;gt;
  &amp;lt;ul class="list-group"&amp;gt;
    {% for article in articles %}
      &amp;lt;li class="list-group-item"&amp;gt;{{articles.title}}&amp;lt;/li&amp;gt;
    {% endfor %}
  &amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should have something like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643231563933%2FLfYMOkoop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643231563933%2FLfYMOkoop.png" alt="Screenshot 2022-01-26 221212.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next wrap each article title to a link&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% for article in articles %}
      &amp;lt;li class="list-group-item"&amp;gt;&amp;lt;a href="article/{{article.id}}"&amp;gt;{{article.title}}&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    {% endfor %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refresh and you'd notice the change in title color and if you click any one, you'd see an error that is because we haven't created routes to display an article by id. &lt;/p&gt;

&lt;h3&gt;
  
  
  Display article route
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/articles/&amp;lt;string:id&amp;gt;/')
def display_article(id):
    return render_template('article.html', articles = Articles)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What we did was to specify the type of data we want to receive then use received data to query to the database and fetch the article by id. Since we are not using any database yet. Let's pass the id in the display articles routes like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/article/&amp;lt;string:id&amp;gt;/')
def display_article(id):
    return render_template('article.html', id=id)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refresh and click an article link, you should see an Id on the page. &lt;/p&gt;

&lt;p&gt;When we implement a MySQL database, we will display the full article. &lt;/p&gt;

&lt;p&gt;Congratulations, you just took a huge step in creating your first flask blog web app! You are officially a developer 🚀 &lt;/p&gt;

&lt;p&gt;Onto the next feature!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643233964213%2F3BDjs14qB.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643233964213%2F3BDjs14qB.gif" alt="dev-gif.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;Like I said earlier, I am coding alongside this article so the source code is available on my GitHub: &lt;a href="https://github.com/Sophyia7/flask-blog-app" rel="noopener noreferrer"&gt;https://github.com/Sophyia7/flask-blog-app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can fork and make some changes if you wish, it's 100% open source. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for reading!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow us on &lt;a href="https://twitter.com/geektechpub" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;/p&gt;

&lt;p&gt;Sophia Iroegbu.&lt;/p&gt;

</description>
      <category>flask</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>30 Javascript animation libraries for 2022</title>
      <dc:creator>GeekTech</dc:creator>
      <pubDate>Fri, 28 Jan 2022 15:50:15 +0000</pubDate>
      <link>https://dev.to/geektechpub/30-javascript-animation-libraries-for-2022-3lna</link>
      <guid>https://dev.to/geektechpub/30-javascript-animation-libraries-for-2022-3lna</guid>
      <description>&lt;h2&gt;
  
  
  Howdy Geeks! 👋
&lt;/h2&gt;

&lt;p&gt;Animation makes us be able to tell stories and communicate emotions and ideas in a unique way. Here are 30 JavaScript animation libraries to use in your projects today.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;a href="https://greensock.com/"&gt;Greensock&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A JavaScript library for building high-performance animations that work in every major browser&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="http://velocityjs.org/"&gt;VelocityJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Velocity is a lightweight animation engine with the same API as jQuery's $.animate()&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://github.com/alexfoxy/laxxx"&gt;Lax.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Simple &amp;amp; lightweight vanilla javascript plugin to create smooth &amp;amp; beautiful animations when you scroll!&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://github.com/dixonandmoe/rellax"&gt;Rellax.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A buttery smooth, super lightweight, vanilla javascript parallax library&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;a href="https://github.com/mrdoob/three.js/"&gt;three.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;An easy to use, lightweight, 3D library with a default WebGL renderer.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;a href="https://wowjs.uk/"&gt;wow.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Reveal Animations When You Scroll.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;a href="http://chocolat.insipi.de/"&gt;Chocolat.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Free lightbox plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. &lt;a href="https://michalsnik.github.io/aos/"&gt;Animate on Scroll&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Animate on scroll library to reveal animations when You scroll.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. &lt;a href="http://gijsroge.github.io/tilt.js/"&gt;TiltJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A tiny requestAnimationFrame powered 60+fps lightweight parallax hover tilt effect for jQuery.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. &lt;a href="https://roughnotation.com/"&gt;Rough Notation&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Rough Notation is a small JavaScript library to create and animate annotations on a web page&lt;/p&gt;

&lt;h2&gt;
  
  
  11. &lt;a href="https://particles.matteobruni.it/"&gt;tsParticles&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A lightweight library for creating particles, an improved version of the abandoned and obsolete particles.js&lt;/p&gt;

&lt;h2&gt;
  
  
  12. &lt;a href="https://vincentgarreau.com/particles.js/"&gt;Particles.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A lightweight JavaScript library for creating particles&lt;/p&gt;

&lt;h2&gt;
  
  
  13. &lt;a href="https://mojs.github.io/"&gt;mo.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The motion graphics toolbelt for the web&lt;/p&gt;

&lt;h2&gt;
  
  
  14. &lt;a href="https://lokeshdhakar.com/projects/lightbox2/"&gt;Lightbox2&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A small JS library to overlay images on top of the current page.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. &lt;a href="https://kenwheeler.github.io/slick/"&gt;Slick&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Fully responsive carousel&lt;/p&gt;

&lt;h2&gt;
  
  
  16. &lt;a href="https://barba.js.org/"&gt;Barba.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Create fluid and smooth transitions between your website’s pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  17. &lt;a href="https://locomotivemtl.github.io/locomotive-scroll/"&gt;Locomotive Scroll&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A simple scroll library that provides detection of elements in viewport &amp;amp; smooth scrolling with parallax.&lt;/p&gt;

&lt;h2&gt;
  
  
  18. &lt;a href="https://owlcarousel2.github.io/OwlCarousel2/"&gt;Owl Carousel&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Free responsive jQuery carousel&lt;/p&gt;

&lt;h2&gt;
  
  
  19. &lt;a href="https://swiperjs.com/"&gt;SwiperJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Free, Open Source, Modern Slider without jQuery. Available for Vanilla JS and all modern frameworks like React, Vue, Angular etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  20. &lt;a href="https://splidejs.com/"&gt;Splide&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Free, pure JS library for carousels and sliders&lt;/p&gt;

&lt;h2&gt;
  
  
  21. &lt;a href="https://simpleparallax.com/"&gt;Simple Parallax&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The easiest way to get a parallax effect with javascript&lt;/p&gt;

&lt;h2&gt;
  
  
  22. &lt;a href="https://thednp.github.io/kute.js/"&gt;Kute.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;KUTE.js is a JavaScript animation engine for modern browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  23. &lt;a href="https://sarcadass.github.io/granim.js/index.html"&gt;Granim.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Create fluid and interactive gradient animations with this small javascript library.&lt;/p&gt;

&lt;h2&gt;
  
  
  24. &lt;a href="https://popmotion.io/"&gt;Popmotion&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Simple animation libraries for delightful user interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  25. &lt;a href="https://maxwellito.github.io/vivus/"&gt;Vivus&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Vivus is a lightweight JavaScript class (with no dependencies) that allows you to animate SVGs, giving them the appearence of being drawn.&lt;/p&gt;

&lt;h2&gt;
  
  
  26. &lt;a href="https://mattboldt.com/demos/typed-js/"&gt;Typed.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A JavaScript Typing Animation Library.&lt;/p&gt;

&lt;h2&gt;
  
  
  27. &lt;a href="https://kimmobrunfeldt.github.io/progressbar.js/"&gt;Progress Bar JS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Responsive and slick progress bars with animated SVG paths.&lt;/p&gt;

&lt;h2&gt;
  
  
  28. &lt;a href="https://animejs.com"&gt;AnimeJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Lightweight JavaScript animation library with a simple, yet powerful API.&lt;/p&gt;

&lt;h2&gt;
  
  
  29. &lt;a href="https://anijs.github.io"&gt;AniJS&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A Library to Raise your Web Design without Coding&lt;/p&gt;

&lt;h2&gt;
  
  
  30. &lt;a href="https://www.remotion.dev/"&gt;Remotion&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This is not an animation library per se but you can use this to make videos by writing Javascript code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for reading!
&lt;/h2&gt;

&lt;p&gt;Follow us on &lt;a href="https://twitter.com/geektechpub"&gt;Twitter&lt;/a&gt; for more tech blogs.&lt;/p&gt;

&lt;p&gt;Until next time,&lt;br&gt;
Abhiraj&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
