<?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: KENNEDY NDUNGU WANJIRU</title>
    <description>The latest articles on DEV Community by KENNEDY NDUNGU WANJIRU (@ken_ndungu).</description>
    <link>https://dev.to/ken_ndungu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3952223%2Ff271cd60-4ef0-46cd-ace1-89042d6a28fe.png</url>
      <title>DEV Community: KENNEDY NDUNGU WANJIRU</title>
      <link>https://dev.to/ken_ndungu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ken_ndungu"/>
    <language>en</language>
    <item>
      <title>A Pythonic Guide to Functions</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Fri, 02 Oct 2026 17:11:45 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/a-pythonic-guide-to-functions-4gg1</link>
      <guid>https://dev.to/ken_ndungu/a-pythonic-guide-to-functions-4gg1</guid>
      <description>&lt;p&gt;You’ve seen &lt;code&gt;def&lt;/code&gt; a hundred times. You know how to write a function, call it, and return a value. But do you know what really happens when Python executes a function definition? Do you know why &lt;code&gt;args&lt;/code&gt; and &lt;code&gt;kwargs&lt;/code&gt; exist, or how a function can remember the environment where it was created? In Python, functions are more than just reusable blocks of code — they’re objects with attributes, they can be nested, passed as arguments, and wrapped by decorators. In this article, we’ll move from the basics of def and return to the powerful patterns that make Python feel like Python. Whether you’re a beginner or brushing up, there’s something here for you.&lt;br&gt;
A function is a block of organised,reusable code that is used to perform an action. &lt;br&gt;
There are two basic types of functions we can work with: &lt;strong&gt;built-in functions&lt;/strong&gt; and &lt;strong&gt;user-defined functions&lt;/strong&gt;.&lt;br&gt;
We can break down the creation of a function into five components.&lt;br&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FExplore-AI%2FPictures%2Fmaster%2Ffunction_components.png" width="800" height="338"&gt;

&lt;h3&gt;
  
  
  Function definition
&lt;/h3&gt;

&lt;p&gt;In Python, we use the keyword "def" to define a function, followed by round brackets and a colon. The colon is used to indicate the start of a new block of code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function name
&lt;/h3&gt;

&lt;p&gt;We need to give our function a name which we will use to call it later.&lt;br&gt;
There are some guidelines on how to name a function, such as the name must begin with a &lt;strong&gt;letter or an underscore&lt;/strong&gt;, it must be in &lt;strong&gt;lowercase&lt;/strong&gt;, it can have &lt;strong&gt;numbers&lt;/strong&gt; and be &lt;strong&gt;any length&lt;/strong&gt; (it's best to keep it short), it cannot be the same as any &lt;strong&gt;Python keyword&lt;/strong&gt;, and must describe the function's purpose.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function inputs
&lt;/h3&gt;

&lt;p&gt;Inputs, also known as parameters, &lt;strong&gt;define the variables required for the function to perform its tasks&lt;/strong&gt;. It's worth noting that we don't have to submit an input every time. If the function tasks do not require any inputs, we can leave this field empty.&lt;br&gt;
It is essential to differentiate between function &lt;code&gt;parameters&lt;/code&gt; and &lt;code&gt;arguments&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;Parameters&lt;/code&gt; are variables listed in the function declaration, serving as placeholders for the values that the function will receive during its execution. They act as local variables within the function, defining its input structure. On the other hand, &lt;code&gt;arguments&lt;/code&gt; are the actual values passed to a function when it is called. These values are assigned to the corresponding parameters defined in the function, allowing for dynamic and flexible behaviour.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function instructions/tasks
&lt;/h3&gt;

&lt;p&gt;This is the block of code within the function that serves as the &lt;strong&gt;set of instructions&lt;/strong&gt; that the function must follow. To indicate that the code that follows belongs to the function, we type it &lt;strong&gt;one tab away&lt;/strong&gt; from the declaration line.&lt;/p&gt;

&lt;h3&gt;
  
  
  Return statement
&lt;/h3&gt;

&lt;p&gt;The return statement defines what the result of the function or the output should be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;A return statement is not required for the function to be created successfully. However, because every function in Python must return something, functions that do not have a return statement return None by default.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the function
&lt;/h3&gt;

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

&lt;p&gt;We start by typing &lt;code&gt;def&lt;/code&gt; to define the function, followed by the &lt;strong&gt;function name&lt;/strong&gt;, which we called &lt;code&gt;calc_forest_area&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Our function has two &lt;strong&gt;arguments&lt;/strong&gt;, the forest &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;width&lt;/code&gt;.&lt;br&gt;
We add these arguments in the brackets and end the declaration with a &lt;strong&gt;colon&lt;/strong&gt; after the brackets.&lt;/p&gt;

&lt;p&gt;Pressing enter in most coding environments will take us to the next line at the correct &lt;strong&gt;level of indentation&lt;/strong&gt;. However, if it doesn't, we hit the tab button, which is equivalent to four or eight whitespaces, depending on the Python editor.&lt;/p&gt;

&lt;p&gt;Inside the function, we define a new &lt;strong&gt;variable&lt;/strong&gt; called &lt;code&gt;area&lt;/code&gt; and set it equal to our input length multiplied by our input width. This is the &lt;strong&gt;instruction&lt;/strong&gt; that will calculate our area.&lt;/p&gt;

&lt;p&gt;Next, we define what we want our function to return using the &lt;strong&gt;return statement&lt;/strong&gt;. In our case, we want our function to return the area of the forest calculated by the function.&lt;br&gt;
Therefore, we add “return” and the area variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Call the function
&lt;/h3&gt;

&lt;p&gt;Assume we wanted to use our newly created&amp;nbsp;function to determine the area of the &lt;code&gt;Zambesi forest&lt;/code&gt; which has a length of 300 kilometres and a width of 5000 kilometres.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffa1ig46k7u1xurf07j0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffa1ig46k7u1xurf07j0h.png" alt="Ima" width="800" height="60"&gt;&lt;/a&gt;&lt;br&gt;
We could also store our output in a variable in order to use it later.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa9ynxz4jqm0brnagby93.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa9ynxz4jqm0brnagby93.png" alt="Ima" width="796" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember when we made use of built-in functions and could read the documentation using the help() function? We can employ &lt;strong&gt;documentation strings&lt;/strong&gt; to perform something similar for user-defined functions.&lt;/p&gt;

&lt;p&gt;Documentation strings, abbreviated &lt;code&gt;docstrings&lt;/code&gt;, are used to &lt;strong&gt;describe the functionality&lt;/strong&gt; of a function, including the arguments and expected return, if they exist. Docstrings can also be used in other code constructs, such as classes and methods, to provide additional information to the user.&lt;/p&gt;

&lt;p&gt;The purpose of any docstring is to explain the function's purpose and&amp;nbsp;functionality so that anyone new viewing or using it understands what the function does.&lt;/p&gt;

&lt;h3&gt;
  
  
  Doc Strings
&lt;/h3&gt;

&lt;p&gt;A docstring is most commonly defined under the function definition with triple double quotation marks and is divided into three distinct sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functionality of the function.&lt;/li&gt;
&lt;li&gt;Breakdown of the input(s), if applicable.&lt;/li&gt;
&lt;li&gt;Breakdown of the output, if applicable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's add some docstrings to our &lt;code&gt;calc_forest_area&lt;/code&gt; function.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh4ofdbhpx7r7q3thhs67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh4ofdbhpx7r7q3thhs67.png" alt="Ima" width="799" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Docstrings are not required for our functions to execute successfully, however, there are some advantages to using them.&lt;br&gt;
Docstrings &lt;strong&gt;improve code readability&lt;/strong&gt; by allowing anyone viewing it to grasp its intent without having to decipher it, making &lt;strong&gt;collaboration&lt;/strong&gt; easier. In our code base, we tend to construct several functions that perform a variety of tasks. Having documentation that explains what the function does and how to use it makes it easier to &lt;strong&gt;keep track of all our functions&lt;/strong&gt;. We are also able to access the documentation for all our functions using the &lt;strong&gt;doc&lt;/strong&gt; attribute, as well as the built-in help() function.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;Now that we understand how to create a function, we need to understand scope, which refers to the parts of our code where an object or variable is available for use.&lt;br&gt;
We can distinguish between a &lt;strong&gt;local variable&lt;/strong&gt; and a &lt;strong&gt;global variable&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local variable
&lt;/h3&gt;

&lt;p&gt;When we created our function, within it we created a variable called &lt;code&gt;area&lt;/code&gt;.&lt;br&gt;
This variable is known as a &lt;strong&gt;local variable&lt;/strong&gt;.&lt;br&gt;
A local variable is defined in or by a function and is only available for use inside that function.&lt;br&gt;
For instance, if we attempted to access our &lt;code&gt;area&lt;/code&gt; variable from outside the function, we would receive an error stating that the variable name has not been defined.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Global variable
&lt;/h3&gt;

&lt;p&gt;In contrast, a global variable is one that is defined outside of any function's construct and can be accessed anywhere in our code. &lt;br&gt;
The &lt;code&gt;zambesi_forest&lt;/code&gt; variable we created earlier, for example, is a global variable that can be used globally in our code, even inside a function.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Function inputs
&lt;/h2&gt;

&lt;p&gt;Functions in Python are like tools that perform specific tasks. To make these tools versatile, we need a way to provide them with information. Inputs in functions serve this purpose, allowing us to customise the function's behaviour based on different situations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of inputs
&lt;/h3&gt;

&lt;h4&gt;
  
  
  No input
&lt;/h4&gt;

&lt;p&gt;Sometimes, a function doesn't require any input to perform its task. For example, suppose we wanted to write a function that would print a general deforestation message throughout our program at various phases.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4cswpga9zhovgtq6u1zs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4cswpga9zhovgtq6u1zs.png" alt="Ima" width="799" height="151"&gt;&lt;/a&gt;&lt;br&gt;
This function does&amp;nbsp;not require any input from the user in order to produce the desired outcome.&lt;/p&gt;

&lt;h4&gt;
  
  
  Default inputs
&lt;/h4&gt;

&lt;p&gt;Default inputs provide a way to set default values for named arguments in a function. If a value is not provided when calling the function, the default value is used.&lt;br&gt;
Suppose we wanted to give the user the option of entering their own personalised message if they so desired. In this case, we could use default arguments.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ivnvourohlrx4d54nc2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ivnvourohlrx4d54nc2.png" alt="Ima" width="800" height="177"&gt;&lt;/a&gt;&lt;br&gt;
A user who does not need a personalised message could use the function without providing a value for the &lt;code&gt;message&lt;/code&gt; argument.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcquplkgf464ei6j2e6wm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcquplkgf464ei6j2e6wm.png" alt="Ima" width="800" height="60"&gt;&lt;/a&gt;&lt;br&gt;
Alternatively, a user that needs a unique message can use the &lt;code&gt;message&lt;/code&gt; parameter to specify it.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzzbknrch2vcw5t8yhdpj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzzbknrch2vcw5t8yhdpj.png" alt="Ima" width="798" height="60"&gt;&lt;/a&gt;&lt;br&gt;
In the above examples, the message parameter has a default value, making it optional when calling the function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Variable inputs
&lt;/h4&gt;

&lt;p&gt;Sometimes, we might want a function to accept an arbitrary number of arguments without specifying their names.&lt;/p&gt;

&lt;p&gt;Python provides us with two variadic inputs – &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For us to understand &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;, it's important for us to understand the difference between keyword arguments and non-keyword arguments.&lt;/p&gt;

&lt;h5&gt;
  
  
  Keyword arguments
&lt;/h5&gt;

&lt;p&gt;Keyword arguments are used when we call a function and explicitly assign an argument to a parameter. The sequence in which we pass the arguments does not matter when using keyword arguments, because we explicitly assign the parameters to the variable. &lt;/p&gt;

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

&lt;p&gt;In the function call above, we used keyword parameters to call the &lt;code&gt;create_deforestation_message&lt;/code&gt; function. We entered the &lt;code&gt;message&lt;/code&gt; and then the&amp;nbsp;&lt;code&gt;location&lt;/code&gt; to explicitly assign each argument&amp;nbsp;to its parameter, regardless of order.&lt;/p&gt;

&lt;h5&gt;
  
  
  Positional arguments/Non-keyword arguments
&lt;/h5&gt;

&lt;p&gt;When we call a function in Python and supply arguments based on the position of the parameters, the arguments are referred to as positional arguments. Positional arguments are thus matched with parameters based on their position. Positional arguments are often known as "non-keyword arguments".&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb37kjms3cohdn9msekp4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb37kjms3cohdn9msekp4.png" alt="Ima" width="798" height="207"&gt;&lt;/a&gt;&lt;br&gt;
We utilised positional parameters in the function call above to call the &lt;code&gt;create_deforestation_message&lt;/code&gt; function. The arguments were entered in the correct sequence depending on their placement in the function parameters.&lt;br&gt;
Unlike keyword arguments, if we changed the order of these parameters, the function wouldn't perform as expected.&lt;/p&gt;

&lt;h4&gt;
  
  
  *args: Variable non-keyword arguments
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;*args&lt;/code&gt; enable a function to accept any number of positional arguments, that is, non-keyword arguments in a variable-length argument list.&lt;/p&gt;

&lt;p&gt;An &lt;code&gt;*args&lt;/code&gt; parameter is created in the same way as any other parameter, with the exception that an asterisk is added before the parameter name.&lt;br&gt;
Suppose we also wanted to create a function that allows the user to track the impact of deforestation on their forest. We could write a function that takes each consequence as an argument, but users may want to list a varying number of consequences or arguments.  This would be possible with &lt;code&gt;*args&lt;/code&gt;.&lt;/p&gt;

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

&lt;h4&gt;
  
  
  **kwargs: Keyword arguments
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;**kwargs&lt;/code&gt; indicate that our function can accept any number of &lt;strong&gt;keyword arguments&lt;/strong&gt; by placing &lt;code&gt;**&lt;/code&gt; before the parameter name. The arguments will be wrapped in a dictionary with the key being the parameter name and the value being the parameter value.&lt;/p&gt;

&lt;p&gt;Suppose we want to create a function that collects detailed and varying characteristics of a forest. The user must be able to decide what information they would like to share using this function. &lt;/p&gt;

&lt;p&gt;We can create a function named &lt;code&gt;list_forest_details&lt;/code&gt; that accepts any number of keyword arguments and uses a combination of the parameter name and value to output labelled information about the forest.&lt;/p&gt;

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

&lt;p&gt;In this function, &lt;code&gt;**details&lt;/code&gt; allows the function to accept any number of keyword arguments. It iterates through the dictionary and prints each key-value pair.&lt;/p&gt;

&lt;p&gt;Note: If our function were to make use of both &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;, it is important to remember that we always place &lt;code&gt;*args&lt;/code&gt; before &lt;code&gt;**kwargs&lt;/code&gt; in the argument list. &lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple return values
&lt;/h2&gt;

&lt;p&gt;Python functions are very versatile and can be configured to meet the needs of the user. We just proved this through our exploration of the number of ways users can enter inputs into our functions. This remains true for function return values. &lt;/p&gt;

&lt;p&gt;Python functions can return function results in several ways. We can return a string, a number, a dictionary, a tuple, or even a table as a value.&lt;/p&gt;

&lt;p&gt;Python can also return multiple values.&lt;/p&gt;

&lt;p&gt;In some cases, a function needs to provide more than one piece of information back to the user. This can be accomplished by separating the values with a comma. The values returned can then be allocated to numerous variables. This can come in handy in a variety of scenarios.&lt;/p&gt;

&lt;p&gt;Let's create a function that calculates the impact of deforestation caused by carbon emissions. &lt;/p&gt;

&lt;p&gt;We want our function to compute the &lt;strong&gt;percentage of tree cover loss&lt;/strong&gt; by subtracting the &lt;strong&gt;initial forest area&lt;/strong&gt; from the &lt;strong&gt;remaining forest area&lt;/strong&gt;. &lt;br&gt;
We also want it to estimate the &lt;strong&gt;increase in CO2 emissions&lt;/strong&gt; by multiplying the &lt;strong&gt;tree cover percentage&lt;/strong&gt;, the &lt;strong&gt;remaining forest area&lt;/strong&gt;, and the &lt;strong&gt;carbon emission factor&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;The function returns a tuple containing the percentage of tree cover loss, the remaining forest area, and the estimated increase in CO2 emissions. To use these values, we unpack the tuple into separate variables (loss_percentage, remaining_area, and co2_increase) when calling the function.&lt;br&gt;
We can then use or view each variable separately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg366lu9bs7yb93v3e7hy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg366lu9bs7yb93v3e7hy.png" alt="Ima" width="800" height="99"&gt;&lt;/a&gt;&lt;br&gt;
By exploring the above concepts, we have gained practical insights into how to create versatile and useful functions in Python.&lt;/p&gt;

</description>
      <category>python</category>
      <category>functions</category>
    </item>
    <item>
      <title>Mastering OOP in Python Without any Headache</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Fri, 02 Oct 2026 15:29:27 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/mastering-oop-in-python-without-the-headache-3ame</link>
      <guid>https://dev.to/ken_ndungu/mastering-oop-in-python-without-the-headache-3ame</guid>
      <description>&lt;p&gt;You know lists, dictionaries, loops, functions and control flows. You stared at &lt;code&gt;class Dog:&lt;/code&gt; and &lt;code&gt;def __init__(self, name):&lt;/code&gt; and wondered whether you have by mistake opened a Java tutorial.&lt;br&gt;
Once you understand a few concepts, you will find that you have been using OOP in Python all the time. You will see that it is straightforward and intuitive - a natural extension to your Python knowledge.Object oriented programming has 4 pillars and they are&lt;br&gt;
&lt;code&gt;1. Encapsulation&lt;/code&gt;&lt;br&gt;
&lt;code&gt;2. Inheritance&lt;/code&gt;&lt;br&gt;
&lt;code&gt;3. Polymorphism&lt;/code&gt; &lt;br&gt;
&lt;code&gt;4. Abstraction&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Classes in OOP are like &lt;em&gt;blueprints&lt;/em&gt; or &lt;em&gt;templates&lt;/em&gt; for creating objects. An object is a &lt;em&gt;specific instance of a class&lt;/em&gt;, containing attributes and behaviors defined in the class. For instance, if a class represents the concept of a 'tree', then each 'tree' planted is an object of that class, with its own unique characteristics.&lt;/p&gt;

&lt;p&gt;Imagine a forest with various tree species. Each species has unique characteristics like height, age, and species type. We can model this diversity using a class for trees, where each tree object represents a specific tree in the forest.&lt;br&gt;
In this article, we explore the basic concepts of OOP using Python code examples. We will learn about classes, instances, inheritance and dunder methods.&lt;/p&gt;

&lt;p&gt;An object oriented programming start with a class,a class is created using the keyword &lt;code&gt;class&lt;/code&gt; and the name of the class folllowed by a fullcolon &lt;code&gt;:&lt;/code&gt;.Follow it by a constructor method to initialise class attributes the method should end in fullcolon.&lt;code&gt;Attributes&lt;/code&gt; are variables stored on the object like &lt;code&gt;self.name&lt;/code&gt;.&lt;code&gt;self&lt;/code&gt; refers to the specific instance being created or used. It must be the first parameter of instance methods.&lt;br&gt;
A &lt;strong&gt;method&lt;/strong&gt; is simply a function defined inside a class. It describes what objects of that class can do.We can create as many methods as we want in a class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt; is a fundamental OOP principle that involves bundling data (attributes) and methods (functions) that operate on the data into a single unit or class. It also restricts direct access to some of the object's components, which is a means of preventing accidental interference and misuse of the data.&lt;/p&gt;


&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FExplore-AI%2FPictures%2Fmaster%2FEncapsulation.jpg" width="800" height="406"&gt;&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fojy9zkx2kd33ell94hq2.png" alt="Im" width="800" height="280"&gt;

&lt;p&gt;The &lt;code&gt;Tree&lt;/code&gt; class in the code defines a blueprint for creating tree objects with specific attributes: &lt;code&gt;species&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, and &lt;code&gt;age&lt;/code&gt;. The &lt;code&gt;__init__&lt;/code&gt; method, known as the constructor, initialises these attributes when a new tree object is created. The &lt;code&gt;describe&lt;/code&gt; method provides a simple way to output a description of the tree, demonstrating how methods can operate on the data encapsulated within the same object, allowing for clear and maintainable code structures.&lt;br&gt;
In our Tree class, encapsulation is demonstrated by how the attributes (species, height, age) and the method (describe) are enclosed within the class. This design allows us to create tree objects with their properties and behaviors neatly packaged together.&lt;br&gt;
Once we have a class ready we need to create an instance,an instance is a concrete object built from that blueprint.&lt;strong&gt;&lt;em&gt;To get an object call the class like a function&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8eemoarpc5n897or15w5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8eemoarpc5n897or15w5.png" alt="Ima" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This example shows how encapsulation makes our code more manageable and secure. By keeping the data (attributes like species, height and age) and methods (describe) within the class, we maintain a structured and organised approach to coding, which is particularly helpful in complex programming scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; in OOP allows us to define a class that inherits all the methods and properties from another class. The parent (or base) class is the class being inherited from, and the child (or derived) class is the class that inherits from the parent class.&lt;/p&gt;


&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FExplore-AI%2FPictures%2Fmaster%2FInheritance.jpg" width="800" height="483"&gt;

&lt;p&gt;Imagine a tree ecosystem where we have a &lt;code&gt;Tree&lt;/code&gt; class as our base class with attributes like &lt;code&gt;species&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, and &lt;code&gt;height&lt;/code&gt;, and methods &lt;code&gt;grow()&lt;/code&gt; and &lt;code&gt;reseed()&lt;/code&gt;. From this base class, we derive two subclasses: &lt;code&gt;Oak&lt;/code&gt; and &lt;code&gt;Pine&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Oak&lt;/code&gt; class inherits the properties and methods from &lt;code&gt;Tree&lt;/code&gt; and adds its own method &lt;code&gt;budding()&lt;/code&gt;. Similarly, the &lt;code&gt;Pine&lt;/code&gt; class inherits from &lt;code&gt;Tree&lt;/code&gt; and adds a &lt;code&gt;cone_count()&lt;/code&gt; method.&lt;/p&gt;

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

&lt;p&gt;The &lt;code&gt;Oak&lt;/code&gt; and &lt;code&gt;Pine&lt;/code&gt; classes illustrate inheritance by reusing the code from the &lt;code&gt;Tree&lt;/code&gt; class. They also demonstrate how we can extend the functionality of a base class by adding new methods that are specific to the subclass. This not only saves time by not having to rewrite shared code but also helps maintain a natural and understandable hierarchy within the codebase, mirroring real-world relationships.&lt;/p&gt;

&lt;p&gt;**Polymorphism **in OOP allows objects of different classes to respond to the same message—or method call—in ways appropriate to their types. This means that the same method can behave differently in different classes.&lt;/p&gt;


&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FExplore-AI%2FPictures%2Fmaster%2FPolymorphism.jpg" width="800" height="469"&gt;

&lt;p&gt;Let's say we have two subclasses, &lt;code&gt;Oak&lt;/code&gt; and &lt;code&gt;Pine&lt;/code&gt;, that stem from the same parent class &lt;code&gt;Tree&lt;/code&gt;. Each subclass can respond to common messages like &lt;code&gt;grow()&lt;/code&gt; and &lt;code&gt;reseed()&lt;/code&gt;. However, due to polymorphism, when the &lt;code&gt;grow()&lt;/code&gt; signal is sent, both &lt;code&gt;Oak&lt;/code&gt; and &lt;code&gt;Pine&lt;/code&gt; trees will grow, but the way they grow and how much they grow can vary. When the &lt;code&gt;reseed()&lt;/code&gt; signal is sent, both types of trees will disperse seeds, but the types of seeds and the method of dispersal might be different. Furthermore, each type of tree may have additional processes that are unique to its kind, such as &lt;code&gt;budding()&lt;/code&gt; in Oaks or &lt;code&gt;cone_count()&lt;/code&gt; in Pines.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F13xi6lu1192v6v4qndfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F13xi6lu1192v6v4qndfc.png" alt="Im" width="800" height="382"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgim3klfqsjt7lqukjxzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgim3klfqsjt7lqukjxzf.png" alt="Ima" width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; in OOP is the concept of &lt;em&gt;hiding the complex reality&lt;/em&gt; while exposing only the necessary parts. It's like using a simple user interface (UI) that hides the complex code behind it. For example, we often log in to websites via simple UIs, which abstracts us from the complex code.&lt;/p&gt;


&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FExplore-AI%2FPictures%2Fmaster%2FAbstraction.jpg" width="800" height="389"&gt;&lt;br&gt;
Let's say we want to provide a simple interface for the growth of various types of trees without needing to understand the intricate details of how each tree grows. The &lt;code&gt;Tree&lt;/code&gt; class will represent the abstract concept of a tree with the method &lt;code&gt;grow()&lt;/code&gt;, which is an abstract method because it's not implemented. Specific types of trees, such as &lt;code&gt;EvergreenTree&lt;/code&gt;, will provide concrete implementations of the &lt;code&gt;grow()&lt;/code&gt; method.&lt;br&gt;
For abstraction to work we have to &lt;code&gt;import abstractmethod&lt;/code&gt; into our code.

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

&lt;p&gt;The &lt;code&gt;Tree&lt;/code&gt; class serves as an abstract base class, similar to the user-friendly login interface. It defines the structure and expectations (like the login fields) without detailing the specifics. The &lt;code&gt;EvergreenTree&lt;/code&gt; class extends &lt;code&gt;Tree&lt;/code&gt; and provides the specifics of how an evergreen tree grows. This hides the complexity from the user, who simply needs to know that they can make a tree grow by calling the &lt;code&gt;grow()&lt;/code&gt; method, much like a user only needs to enter a username and password and click 'login' to start a session. This abstraction makes the code easier to use and maintain, as well as to extend with new types of trees.&lt;br&gt;
I hope this article helps you understand object oriented programming.&lt;/p&gt;

</description>
      <category>python</category>
      <category>oop</category>
    </item>
    <item>
      <title>The Art of Looping in Python</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Mon, 28 Sep 2026 14:36:02 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/the-art-of-looping-in-python-403i</link>
      <guid>https://dev.to/ken_ndungu/the-art-of-looping-in-python-403i</guid>
      <description>&lt;p&gt;Now consider writing that code 100 times. That would be quite painful wouldn't it? Now consider writing that code 10,000 times. It isn't just bad, it is a nightmare. Luckily for us, Python has a way of solving this problem for code and that way is through loops. In this article, I will cover what loops are, when you should use loops and why you will soon have loops in your toolbox.&lt;br&gt;
Two official python loop statements are &lt;em&gt;for&lt;/em&gt; and &lt;em&gt;while&lt;/em&gt; loops.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;for&lt;/code&gt; loops:&lt;/strong&gt; They are ideal for going through a sequence (like a list, tuple, or string), one by one. We use &lt;code&gt;for&lt;/code&gt; loops when we know how many things there are in a list. &lt;/p&gt;

&lt;p&gt;For example, for each element &lt;code&gt;i&lt;/code&gt; in &lt;code&gt;list_of_numbers&lt;/code&gt;, print out the value of &lt;code&gt;i&lt;/code&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Syntax and structure
&lt;/h3&gt;

&lt;p&gt;The syntax of a for loop in Python is straightforward. It includes the &lt;code&gt;for&lt;/code&gt; keyword, an &lt;code&gt;item&lt;/code&gt; variable, the &lt;code&gt;in&lt;/code&gt; operator, and a &lt;code&gt;collection&lt;/code&gt; object, where &lt;code&gt;collection&lt;/code&gt; refers to an object we &lt;strong&gt;can&lt;/strong&gt; iterate through, like a list, dictionary, or tuple. The instructions we want to run in each loop are in the loop body.&lt;/p&gt;

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

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Here the loop accesses each value in the list, one by one. We can iterate through our list of animals too, one by one:&lt;/p&gt;

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

&lt;p&gt;We can add as many instructions as we like in the body of the loop. Once a loop is complete, it executes the next line of code after the loop. &lt;/p&gt;

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

&lt;p&gt;We can loop through any iterable data structure like tuples, sets, dictionaries, and even strings:&lt;/p&gt;

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

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

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

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

&lt;h2&gt;
  
  
  While loops
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;while&lt;/code&gt; loop in Python repeatedly executes its body &lt;strong&gt;as long as a condition is true&lt;/strong&gt;. Its syntax is:&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;while&lt;/code&gt; loops are ideal for scenarios where you don't know how many times you need to iterate. For example, adding 10% to a value, until it is &amp;gt; 5. It is hard to know before we start how many times we have to repeat the calculation, so if we use a &lt;code&gt;while&lt;/code&gt; loop, we can keep going until we get to the answer.It can be stopped if the condition is false or by using &lt;code&gt;break&lt;/code&gt; key word. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhh2rmq3we6c3y9gbjldf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhh2rmq3we6c3y9gbjldf.png" alt="Im" width="800" height="227"&gt;&lt;/a&gt;&lt;br&gt;
This loop prints the population with 10% added to each iteration, until the population is 2.85, and the loop stops because the next number is larger than 3. &lt;/p&gt;

&lt;p&gt;Be cautious with &lt;code&gt;while&lt;/code&gt; loops, because they result in infinite loops if the condition never becomes false. Always ensure there's a way for the condition to become false eventually.&lt;/p&gt;

&lt;p&gt;If your loop is infinitely looping, press the &lt;code&gt;i&lt;/code&gt; key twice rapidly, or click on the stop/interrupt button to interrupt the kernel. The cell below contains an example of an infinite loop. It will go into an infinite loop when running it, so beware!&lt;/p&gt;

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

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

&lt;p&gt;Loop control statements are used to change the execution flow of loops. They provide flexibility and control over how loops behave in different scenarios. The primary loop control statements in Python are &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, and &lt;code&gt;pass&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;break&lt;/code&gt; statement
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;break&lt;/code&gt; immediately stops the execution of a loop, and the control flows to the statement immediately after the loop.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;break&lt;/code&gt; is often used when searching for an item in a list. Once the item is found, there's no need to continue the loop.&lt;/p&gt;

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

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

&lt;p&gt;The loop stopped once we reached the &lt;code&gt;African Elephant&lt;/code&gt; animal, so printing out &lt;code&gt;print(f"The last animal checked = {animal}")&lt;/code&gt; after the loop has completed, results in &lt;code&gt;African Elephant&lt;/code&gt;, showing that the loop stopped there.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;continue&lt;/code&gt; statement
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;continue&lt;/code&gt; skips the rest of the loop's &lt;strong&gt;body&lt;/strong&gt; for the current iteration and moves to the next iteration.&lt;/p&gt;

&lt;p&gt;This is useful when we need to skip certain elements in a loop, like filtering out specific values.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;code&gt;pass&lt;/code&gt; statement
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pass&lt;/code&gt; is a statement that does nothing. It's used as a placeholder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pass&lt;/code&gt; is used when we need a statement to have the correct syntax but want to implement no action, like in empty definitions, loops, or conditionals. &lt;code&gt;pass&lt;/code&gt; is very useful as a placeholder for the code we are going to add later.&lt;br&gt;
Suppose we want to check all animals, but skip &lt;code&gt;African Elephants&lt;/code&gt;:&lt;/p&gt;

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

&lt;p&gt;We've learned that &lt;strong&gt;loops are essential&lt;/strong&gt; for automating &lt;strong&gt;repetitive&lt;/strong&gt; tasks and efficiently processing collections of data. By understanding the nuances of &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loops, as well as loop control statements like &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, and &lt;code&gt;pass&lt;/code&gt;, we can write more effective and efficient Python code.&lt;/p&gt;

</description>
      <category>python</category>
      <category>pythonloops</category>
    </item>
    <item>
      <title>Teaching Python to Think: A Guide to Operators and Conditionals</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Mon, 21 Sep 2026 18:53:50 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/teaching-python-to-think-a-guide-to-operators-and-conditionals-4dml</link>
      <guid>https://dev.to/ken_ndungu/teaching-python-to-think-a-guide-to-operators-and-conditionals-4dml</guid>
      <description>&lt;h2&gt;
  
  
  Introduction: Teaching Python to Think
&lt;/h2&gt;

&lt;p&gt;Every Python program, no matter how sophisticated it appears, ultimately boils down to two fundamental capabilities: the ability to compare values and the ability to make decisions based on those comparisons. A banking app checks whether your balance exceeds the purchase amount. A game determines whether your character has collided with an obstacle. A script decides whether a file exists before attempting to open it. Strip away the libraries and the elegant syntax, and you'll find the same humble building blocks at work: &lt;strong&gt;operators&lt;/strong&gt; and &lt;strong&gt;conditionals&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Operators are the tools Python gives us to perform computations and comparisons—adding numbers, checking equality, combining logical statements with &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, and &lt;code&gt;not&lt;/code&gt;. Conditionals are the structures that let our programs branch, choosing one path over another depending on the outcome of those comparisons. With Python's readable &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt; syntax, these concepts feel almost like plain English, but they hide surprising depth. Should you use &lt;code&gt;==&lt;/code&gt; or &lt;code&gt;is&lt;/code&gt;? How does Python's truthiness treat empty lists versus zero? What's the difference between &lt;code&gt;and&lt;/code&gt; returning a boolean and returning one of its operands? These subtleties trip up beginners and seasoned developers alike.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore how operators and conditionals work in Python, examine the different categories of each, and look at practical examples that show how these concepts combine to create logic that's greater than the sum of its parts. Whether you're writing your first &lt;code&gt;if&lt;/code&gt; statement or brushing up on the nuances of comparison chaining and short-circuit evaluation, understanding these fundamentals will make you a more deliberate and effective Python programmer.&lt;/p&gt;

&lt;p&gt;Let's dive in.&lt;/p&gt;

&lt;p&gt;For one to understand conditionals its important to know arithmetic,comparison and Logical operators.&lt;br&gt;
Arithmetic operators include&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 + 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;8&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 - 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 * 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 / 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.6666...&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Floor Division&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 // 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Modulus (remainder)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 % 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;**&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exponentiation&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 ** 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;125&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Comparison operators include&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison operators&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;==&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;!=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Not equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;lt;=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;gt;=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Logical operators include&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Logical operators&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;and&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True if both are true(&lt;code&gt;x and y&lt;/code&gt;). This operator is used to check whether both conditions are true.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;or&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True if at least one is true (&lt;code&gt;x or y&lt;/code&gt;). This operator is used to check if either of the conditions is true.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;not&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True only if false (&lt;code&gt;not x&lt;/code&gt;). This operator is used to check for inequality.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Conditional statements in programming are used to execute specific blocks of code based on whether certain conditions are met. They are fundamental for decision-making in our code, allowing for different outcomes depending on variable states or inputs. Typically, we use &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt; statements to handle these scenarios, providing flexibility and control over the flow of our program's execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;if&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are the most basic form of conditional execution. They are used to execute a block of code only if a specified condition is &lt;code&gt;True&lt;/code&gt;. For example, if we wanted to issue a warning when deforestation exceeds a certain level.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Nested &lt;code&gt;if&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;Nested &lt;code&gt;if&lt;/code&gt; statements are used when we need to perform another conditional check within an &lt;code&gt;if&lt;/code&gt; block. They are useful for more complex decision-making processes. For example, suppose we want to prioritise environmental protection in sensitive areas. We must check whether the deforestation rate exceeds a certain level and if an area is protected.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;code&gt;if&lt;/code&gt;-&lt;code&gt;else&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;if-else&lt;/code&gt; structure executes one block of code if the condition is &lt;code&gt;True&lt;/code&gt; and another block if it is &lt;code&gt;False&lt;/code&gt;. For example, suppose we want to create a simple notification system for deforestation activity.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;code&gt;elif&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;elif&lt;/code&gt; (short for else if) provides a middle ground between &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt;. It is used when we have multiple conditions to check sequentially. For example, suppose we need to categorise deforestation rates into different levels of concern, such as &lt;code&gt;"Critical level"&lt;/code&gt;, &lt;code&gt;"High level"&lt;/code&gt;, or &lt;code&gt;"Normal level"&lt;/code&gt;, based on predefined thresholds.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Chained conditional statements
&lt;/h3&gt;

&lt;p&gt;Chained conditionals use &lt;code&gt;elif&lt;/code&gt; (else if) for multiple checks. They are used when there are more than two possibilities and exactly one must be chosen. For example, suppose we need to implement specific environmental actions based on varying levels of deforestation.&lt;/p&gt;

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

&lt;p&gt;The program sequentially evaluates each condition from the top down. It stops further checks as soon as one condition is fulfilled. In a scenario where there are mistakenly two true conditions for a variable, the program executes only up to the first met condition, ignoring subsequent ones. For example, both &lt;code&gt;elif deforestation_rate == 0.1&lt;/code&gt; and elif &lt;code&gt;deforestation_rate &amp;gt;= 0.1&lt;/code&gt; are true when &lt;code&gt;deforestation_rate&lt;/code&gt; is &lt;code&gt;0.1&lt;/code&gt;. However, only the first true condition is executed.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Conditional statement keywords: &lt;code&gt;not&lt;/code&gt; and &lt;code&gt;pass&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In Python, there are keywords within conditional statements that allow us to add more flexibility to our code. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;if&lt;/code&gt; &lt;code&gt;not&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;if not&lt;/code&gt; is used to check the negation of a condition. It's a more readable way to check &lt;code&gt;if not true&lt;/code&gt;. For example, suppose we want to create an automated alert system for forest conservation that tells us the forest is healthy if no deforestation is detected and alerts us if this is not the case.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;pass&lt;/code&gt; statements
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pass&lt;/code&gt; is a null statement in Python. It is used when a statement is syntactically required but we do not want any command or code to execute. It is often used as a placeholder for future code. When the pass statement is executed, nothing happens, but we avoid getting an error when empty code is not allowed. For example, suppose we are creating a system to monitor deforestation and take action only when necessary. However, we are still planning what should be done if deforestation exceeds the predefined limits. &lt;/p&gt;

&lt;p&gt;We can attempt to leave an &lt;code&gt;if&lt;/code&gt; statement block empty, meaning no code is executed within it. However, this approach results in an error, as Python expects to find an indented block following an &lt;code&gt;if&lt;/code&gt; statement, even if no action is to be performed.&lt;/p&gt;

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

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

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

&lt;p&gt;To resolve this error, we can insert a &lt;code&gt;pass&lt;/code&gt; statement in the &lt;code&gt;if&lt;/code&gt; block. The &lt;code&gt;pass&lt;/code&gt; statement serves as a placeholder, doing nothing but preventing the error caused by an empty code block.&lt;br&gt;
Note: It's essential to use &lt;code&gt;pass&lt;/code&gt; wisely as it can hide real issues in the code by overlooking errors that could offer valuable insights.&lt;/p&gt;

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

&lt;p&gt;By exploring the above concepts, I hope you have gained practical insights into why and how we use various types of conditional statements in Python.&lt;/p&gt;

</description>
      <category>python</category>
      <category>operations</category>
    </item>
    <item>
      <title>Python Basics</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Mon, 21 Sep 2026 17:14:29 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/python-basics-1o52</link>
      <guid>https://dev.to/ken_ndungu/python-basics-1o52</guid>
      <description>&lt;h2&gt;
  
  
  Variables. Data Types.  Input/Output.  Syntax.
&lt;/h2&gt;

&lt;p&gt;Every programmer who you idolize began their journey right where you are, staring at a blinking cursor, searching for answers.&lt;/p&gt;

&lt;p&gt;The good news is that all of them had to learn these four concepts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variables&lt;/strong&gt; – the labeled boxes where a computer stores its information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data types&lt;/strong&gt; – numbers, words, and booleans.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input/output&lt;/strong&gt; – the ways a program consumes and produces information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; – what makes computer languages different than English.&lt;/p&gt;

&lt;p&gt;These concepts are the foundation of any successful coding journey. You won’t be able to build something meaningful without understanding them at a fundamental level.&lt;/p&gt;

&lt;p&gt;Once you learn the basics, you’ll unlock the knowledge that can help you achieve extraordinary outcomes. Instagram and  AI revolution are all built with computer programs.&lt;/p&gt;

&lt;p&gt;This guide will give you an overview of the most important programming concepts in Python. It will explain what you need to know to become a better programmer, regardless of your goals. Some of these ideas are universal, and you’ll encounter them in any language. Moreover, Python is exceptionally beginner-friendly because it isolates these concepts and makes them easier to grasp.&lt;/p&gt;

&lt;p&gt;Whether you just opened a Python book for the first time or haven’t touched the language in years, this guide will bring you up to speed. Let’s get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Assigning a variable
&lt;/h3&gt;

&lt;p&gt;Assigning a variable in programming refers to the process of &lt;strong&gt;associating a value with a symbolic name&lt;/strong&gt; (the variable name) so that the program can &lt;strong&gt;refer to and manipulate that value&lt;/strong&gt; using the given name. It is essentially storing a piece of data in a memory location and giving it a label for convenient reference.&lt;br&gt;
To assign a variable, we need three components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Variable name&lt;/strong&gt;: We can decide what we would like to name our variable but keep in mind it can be short and descriptive. We will learn about certain naming conventions we must follow in a bit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Assignment operator&lt;/strong&gt;: The variable name will be followed by the assignment operator. The assignment operator is an equal sign (&lt;code&gt;=&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The value&lt;/strong&gt;: The value we assign to a variable can be numerical or consist of characters, known as strings. In this part of the lesson, we will only be focusing on using numerical values.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;We assign values to variables for the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To label and store information in memory.&lt;/li&gt;
&lt;li&gt;This information can then be referenced later on and even be manipulated.&lt;/li&gt;
&lt;li&gt;It makes it easier for a reader, and even ourselves, to understand our code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;examples&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frssdgxusyp1uhezhnrv5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frssdgxusyp1uhezhnrv5.png" alt="Iine" width="800" height="94"&gt;&lt;/a&gt;&lt;br&gt;
Many variables can be assigned to one value.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7i3n0f0yktjelfmob4p0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7i3n0f0yktjelfmob4p0.png" alt="des" width="798" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Rules
&lt;/h4&gt;

&lt;p&gt;When naming variables, certain &lt;strong&gt;rules&lt;/strong&gt; must be followed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Must start with a letter or underscore&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;myvarname&lt;/code&gt; or &lt;code&gt;_myvarname&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Not allowed to start with a number&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2myvarname&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Only allowed to contain alpha-numeric characters and underscores&lt;/td&gt;
&lt;td&gt;&lt;code&gt;myvarname_2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Variable names are case-sensitive&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;myvar&lt;/code&gt; $\neq$ &lt;code&gt;Myvar&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Case types
&lt;/h4&gt;

&lt;p&gt;It is also important to be consistent when using a naming convention for variables.&lt;br&gt;
We can use the following case types to ensure consistency:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pascal case&lt;/td&gt;
&lt;td&gt;All the first letters in the variable name are capitalised, with no spaces and characters between the words&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MyVarName&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Camel case&lt;/td&gt;
&lt;td&gt;The first word's letter is not capitalised, and it doesn't have any characters between the words&lt;/td&gt;
&lt;td&gt;&lt;code&gt;myVarName&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Snake case&lt;/td&gt;
&lt;td&gt;Words are separated by underscores and usually all lowercase&lt;/td&gt;
&lt;td&gt;&lt;code&gt;my_var_name&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

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

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

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

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

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

&lt;h2&gt;
  
  
  Data types
&lt;/h2&gt;

&lt;p&gt;Like other programming languages, variables in Python have &lt;strong&gt;values&lt;/strong&gt; and &lt;strong&gt;types&lt;/strong&gt;. &lt;strong&gt;Data types&lt;/strong&gt; dictate what &lt;strong&gt;kind of data a variable can store&lt;/strong&gt; and, in some cases, the &lt;strong&gt;amount of memory&lt;/strong&gt; allocated to it. Allocating variable types allows us to make assumptions about the &lt;strong&gt;kind of operations&lt;/strong&gt; that can be applied to a given variable. &lt;/p&gt;

&lt;p&gt;Python makes use of five primitive variable types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integers&lt;/li&gt;
&lt;li&gt;Floats &lt;/li&gt;
&lt;li&gt;Complex numbers&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Booleans&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;(a) Numbers&lt;/strong&gt;&lt;br&gt;
Three main data types exist to store numerical data:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integers (ints)&lt;/strong&gt;: These are positive or negative whole numbers with no fractional components. By using built-in functions in Python, such as  &lt;code&gt;type()&lt;/code&gt;,  we can determine if a number is an integer or a float, for example, 5, -10. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Floats&lt;/strong&gt;: This is another numerical data type that is used to represent real numbers. A decimal point is used to divide the integer and fractional components of the value, for example, 3.14, -0.5.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complex numbers&lt;/strong&gt;: A complex number is a distinct data type used to represent numbers in the form &lt;code&gt;a + bj&lt;/code&gt;, where &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are real numbers, and &lt;code&gt;j&lt;/code&gt; is the imaginary unit (for example, the square root of -1). Complex numbers play a crucial role in various mathematical and engineering applications, and Python provides native support for them, for example, 2 + 3j, 1 - 1j.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Strings in Python are &lt;strong&gt;sequences of characters enclosed in quotes&lt;/strong&gt;, either single (') or double ("). They are versatile and widely used for representing textual data.&lt;/p&gt;

&lt;p&gt;Characteristics of strings include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sequence of characters&lt;/strong&gt;: Strings can contain letters, numbers, symbols, and spaces.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutable&lt;/strong&gt;: Once a string is defined, its content cannot be changed. Any operation that appears to modify a string actually creates a new string.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;(c) Booleans&lt;/strong&gt;&lt;br&gt;
Booleans are built-in data types capable of taking one of two possible values: &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;(interchangeable with the integers &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;). Booleans control the flow of a program and are used to make comparisons, showing that despite the fancy name (nicknamed &lt;code&gt;bool&lt;/code&gt; in Python) they play an integral role. &lt;/p&gt;

&lt;p&gt;Boolean data types can be used with &lt;code&gt;comparison&lt;/code&gt; and &lt;code&gt;logical&lt;/code&gt; operators: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison operators&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;==&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;!=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Not equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;lt;=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;gt;=&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Logical operators&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;and&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True if both are true(&lt;code&gt;x and y&lt;/code&gt;). This operator is used to check whether both conditions are true.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;or&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True if at least one is true (&lt;code&gt;x or y&lt;/code&gt;). This operator is used to check if either of the conditions is true.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;not&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True only if false (&lt;code&gt;not x&lt;/code&gt;). This operator is used to check for inequality.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These boolean operators will either equate to &lt;code&gt;True&lt;/code&gt; if the condition is met or &lt;code&gt;False&lt;/code&gt; if the condition is not met. &lt;br&gt;
Below we will be testing some conditions using logical operators.&lt;/p&gt;

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

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

&lt;p&gt;The &lt;strong&gt;print()&lt;/strong&gt; function is used for output in various formats and the &lt;strong&gt;input()&lt;/strong&gt; function enables interaction with users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;input() function&lt;/strong&gt; is used to take user input and it returns the user input in form of a string.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;print()&lt;/strong&gt; function allows us to display text, variables and expressions on the console.&lt;/p&gt;

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

&lt;p&gt;Casting variables to different data types is a fundamental concept in programming that involves transforming a variable from one data type to another. In Python, this process is commonly referred to as "type casting" or simply "casting." The ability to cast variables enables programmers to adapt and manipulate data efficiently, ensuring that the correct operations, methods, and functions can be applied to specific types of data.&lt;br&gt;
We can confirm data type using the following syntax&lt;br&gt;
&lt;code&gt;variable_type = type(variable)&lt;/code&gt;&lt;/p&gt;

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

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

&lt;p&gt;Casting data types is a more explicit or forceful change in type, normally actioned by the user.&lt;br&gt;
&lt;code&gt;new_variable = target_data_type(existing_variable)&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;I hope this article will be useful to you the reader and any python beginner.If you find this article useful share it widely.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>WINDOW FUNCTIONS</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Sun, 13 Sep 2026 11:16:33 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/window-functions-4ga9</link>
      <guid>https://dev.to/ken_ndungu/window-functions-4ga9</guid>
      <description>&lt;p&gt;&lt;strong&gt;What are Window Functions?&lt;/strong&gt;&lt;br&gt;
It is a function that performs calculations across a set of rows related to the current one and returns the result of its computation for each row. Unlike GROUP BY, Window functions in PostgreSQL do not aggregate values and therefore do not reduce the number of rows in the output dataset. All rows from the input table are present in the output, and computations are attached to the corresponding rows.&lt;/p&gt;

&lt;p&gt;In other words, you can think of a window function as a computation that for each row requests a value that is the result of some calculation applied to a certain set of rows (a window).&lt;/p&gt;

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

&lt;p&gt;In our previous article we have 'Postgresql functions' we had gone through aggregate functions,therefore we will not repeat aggregate functions . A Window function has the following syntax&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;1.Value&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1.1 FIRST_VALUE()&lt;/strong&gt;&lt;br&gt;
The FIRST_VALUE() function allows the retrieval of the value of a column from the first row within a partition.&lt;/p&gt;

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

&lt;p&gt;The FIRST_VALUE() function is applied to the First_name column and ordered by Start_date. It returns the First_name from the &lt;br&gt;
first row as First_in_dept.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.2 LAST_VALUE()&lt;/strong&gt;&lt;br&gt;
The LAST_VALUE() function allows the retrieval of the value of a column from the last row within a window frame.&lt;/p&gt;

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

&lt;p&gt;The LAST_VALUE() function is applied to the First_name column &lt;br&gt;
and ordered by Start_date. It returns the First_name from the &lt;br&gt;
first row as Last_employee.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.3 LEAD()&lt;/strong&gt;&lt;br&gt;
The LEAD(column, n) function allows access of a value within a column from the following nth-row relative to the current row.  It is the counterpart of the LAG() function.&lt;/p&gt;

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

&lt;p&gt;The LEAD(Salary, 1) function is applied to the Salary column and &lt;br&gt;
ordered by Date_started. It returns the salary from the previous &lt;br&gt;
row, since n = 1, as the column Next_salary. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.4 LAG()&lt;/strong&gt;&lt;br&gt;
The LAG(column, n) function allows access of a value within a column from the previous nth-row relative to the current row. &lt;/p&gt;

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

&lt;p&gt;The LAG(Salary, 1) function is applied to the Salary column and &lt;br&gt;
ordered by Date_started. It returns the salary from the previous &lt;br&gt;
row, since n = 1, as the column Previous_salary. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.0 Ranking()&lt;/strong&gt;&lt;br&gt;
Ranking window functions assign a rank or row number to each row within a specified window or subset of rows. Ranking window functions typically need an ORDER BY clause in order to work as intended. They include&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.1 RANK()&lt;/strong&gt;&lt;br&gt;
The RANK() function assigns a rank to each row based on the order specified within the window. &lt;strong&gt;Rows with the same values receive the same rank, and the next rank is skipped.&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2.2 DENSE_RANK()&lt;/strong&gt;&lt;br&gt;
The DENSE_RANK() function operates similarly to the RANK() function except &lt;strong&gt;it does not skip any ranks even if rows have the same values.&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2.3 ROW_NUMBER()&lt;/strong&gt;&lt;br&gt;
The ROW_NUMBER() function assigns a unique sequential number to each row within a partition, regardless of the column values. It makes sure that no two rows can have the same row number within a division.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2.4 NTILE()&lt;/strong&gt;&lt;br&gt;
NTILE() divides sorted partitions into &lt;strong&gt;n-number of equal groups&lt;/strong&gt;. Each row in a partition is assigned a group number.&lt;/p&gt;

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

&lt;p&gt;I would advise you to read and practice these functions for you to master them.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>postgressql</category>
      <category>windowfunctions</category>
    </item>
    <item>
      <title>POSTRESQL FUNCTIONS</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Sun, 13 Sep 2026 08:38:37 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/postresql-functions-ko0</link>
      <guid>https://dev.to/ken_ndungu/postresql-functions-ko0</guid>
      <description>&lt;p&gt;Forget about using your database simply as an advanced version of Microsoft Excel.&lt;br&gt;
When you are bringing down thousands of rows of unrefined data to your app in order to perform simple actions such as calculating average, counting distinct users, and formatting dates, then you are wasting your valuable bandwidth and time. The truth is that SQL is more than just data storage; it is a highly advanced computational tool. With the help of SQL functions, one can refine data and derive useful insights even before it gets downloaded from the server.In this article we shall ocus on the commoly used postgresql functions.&lt;/p&gt;

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

&lt;p&gt;Postgresql functions are built-in operations that can be used to perform various calculations, manipulations, or transformations on data within an postgresql database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Types&lt;/strong&gt;&lt;br&gt;
Functions can be categorized by what &lt;strong&gt;input&lt;/strong&gt; they take.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax of postgresql functions&lt;/strong&gt;&lt;br&gt;
The output of a function in postgresql is treated as a derived column and appears in the SELECT clause of a query. The general syntax of an postgresql function is:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;1.Numeric Functions&lt;/strong&gt;&lt;br&gt;
These functions perform calculations on a set of values in a &lt;br&gt;
column and return a numerical value.Numeric functions is grouped &lt;br&gt;
into &lt;strong&gt;aggregate numeric functions and scalar numeric functions&lt;/strong&gt;.&lt;br&gt;
Aggregate numeric functions include&lt;br&gt;
&lt;strong&gt;1.1 SUM()&lt;/strong&gt;&lt;br&gt;
The SUM() function returns the total sum of a specified numeric column.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgq32i5i3b314aa5pbmov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgq32i5i3b314aa5pbmov.png" alt="image" width="622" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.2 AVG()&lt;/strong&gt;&lt;br&gt;
The AVG() function returns the average value of the selected numeric column.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn310d20aa4jv9zg4mb30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn310d20aa4jv9zg4mb30.png" alt="average" width="765" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.3 MIN()&lt;/strong&gt;&lt;br&gt;
The MIN() function returns the smallest or lowest value of the selected column.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg8skoq978cjryswxk2wv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg8skoq978cjryswxk2wv.png" alt="min" width="794" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.4 MAX()&lt;/strong&gt;&lt;br&gt;
The MAX() function returns the largest or highest value of the selected column.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;scalar numeric functions include&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1.5 ROUND()&lt;/strong&gt;&lt;br&gt;
The ROUND() function rounds a numerical value to a specified number of decimal places.&lt;br&gt;
The following is the syntax of round function.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6cx044aa1mzgvsfr135g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6cx044aa1mzgvsfr135g.png" alt="syntax" width="800" height="142"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flyfaht9plgiv9pv13xp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flyfaht9plgiv9pv13xp6.png" alt="round" width="794" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.6 SQRT()&lt;/strong&gt;&lt;br&gt;
The SQRT() function returns the square root of a numerical value. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8dhtzocbk88udq1069gn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8dhtzocbk88udq1069gn.png" alt="Square root" width="709" height="199"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.0 String Functions&lt;/strong&gt;&lt;br&gt;
These functions operate on string values and perform &lt;br&gt;
operations such as concatenation, manipulation, and text &lt;br&gt;
formatting.They include&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.1 UPPER() and LOWER() functions&lt;/strong&gt;&lt;br&gt;
The UPPER() function is used to convert a string to uppercase while the LOWER() function is used to convert a string to lowercase. Their syntaxes are as follows:&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;2.2 LTRIM() and RTRIM() functions&lt;/strong&gt;&lt;br&gt;
The LTRIM() function is used to remove leading spaces from the left end of a string while the RTRIM() function is used to remove trailing spaces from the right end of a string.You can use TRIM()&lt;br&gt;
to remove both the leading and trailing spaces.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;2.3 LEFT() and RIGHT() functions&lt;/strong&gt;&lt;br&gt;
The LEFT() function is used to extract a specified number of characters from the beginning (leftmost side) of a string while the RIGHT() function is used to extract a specified number of &lt;br&gt;
characters from the end (rightmost side) of a string.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;2.4 SUBSTRING() function&lt;/strong&gt;&lt;br&gt;
The SUBSTRING() function is used to extract a substring from a string. It takes three arguments: the original string, the starting position of the substring, and optionally, the length &lt;br&gt;
of the substring.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;2.5 CONCAT() function&lt;/strong&gt;&lt;br&gt;
The CONCAT() function is used to concatenate or join multiple strings together. It takes two or more string arguments (separated by commas) and returns a single concatenated string.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;2.6 REPLACE() function&lt;/strong&gt;&lt;br&gt;
The REPLACE() function is used to replace all occurrences of a specified substring within a string with a new substring. It takes three arguments: the original string, the substring to be &lt;br&gt;
replaced, and the new substring.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;3.0 Miscellaneous functions&lt;/strong&gt;&lt;br&gt;
This category represents a variety of functions that do a &lt;br&gt;
variety of things such as converting data types and dealing &lt;br&gt;
with NULL values.They include&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.1 CAST() function&lt;/strong&gt;&lt;br&gt;
The CAST() function is used to convert a value from its current data type into a specified data type. Its basic syntax is as follows&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;3.2 CONVERT() function&lt;/strong&gt;&lt;br&gt;
CONVERT() is another function that can be used for conversion from one data type to another. Its basic syntax is as follows:&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;3.3 IFNULL() function&lt;/strong&gt;&lt;br&gt;
The IFNULL() function returns a specified value if the given expression is null. Otherwise, it returns the value of the expression itself. Its basic syntax is as follow&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;3.4 NULLIF() function&lt;/strong&gt;&lt;br&gt;
The NULLIF() function is used to compare two expressions and return NULL if they are equal. Otherwise, the first expression is returned. Its basic syntax is as follows:&lt;/p&gt;

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

&lt;p&gt;example&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;3.5 ISNULL() function&lt;/strong&gt;&lt;br&gt;
The ISNULL() function helps to determine whether an expression is NULL or not. If the expression is NULL, this function returns 1. Otherwise, it returns 0. Its basic syntax is as follows:&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;3.6 COALESCE() function&lt;/strong&gt;&lt;br&gt;
The COALESCE() function evaluates a list of expressions from left to right, searching for the first non-NULL value and returning it. If all the expressions are NULL, the function returns &lt;br&gt;
NULL. Its basic syntax is as follows:&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;4.0 Datetime&lt;/strong&gt;&lt;br&gt;
These are functions used to handle date and time values and &lt;br&gt;
perform operations like formatting, extraction, and manipulation.They include&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.1 CURRENT_DATE()&lt;/strong&gt;&lt;br&gt;
The CURRENT_DATE() function is used to retrieve the current date without the time component.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;4.2 NOW()&lt;/strong&gt;&lt;br&gt;
The NOW() function is used to retrieve the current date and time from the system. It returns a datetime value representing the current timestamp.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;4.3 DATEDIFF()&lt;/strong&gt;&lt;br&gt;
The DATEDIFF() function is used to calculate the difference between two dates. It takes three parameters: the part of the date for which to calculate the difference (day, month, or year), the start date, and the end date.&lt;/p&gt;

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

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

&lt;p&gt;*&lt;em&gt;4.4 DATE_ADD() *&lt;/em&gt;&lt;br&gt;
The DATE_ADD() function is used to add a specified interval to a date or datetime value. It takes three parameters: a date or datetime to which the interval will be added, a value representing the interval you want to add, and an interval unit, which can be DAY, MONTH, or YEAR.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;4.5 TO_DATE()&lt;/strong&gt;&lt;br&gt;
TO_DATE function evaluates a character string according to the date-formatting directive that you specify and returns a DATETIME value.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;4.6 TO_CHAR&lt;/strong&gt;&lt;br&gt;
It converts a date, number, or other value into a text string.&lt;/p&gt;

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

&lt;p&gt;I hope you read this article and continuously practice these functions because that is the only way you will master them.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>sqlfunctions</category>
      <category>analysis</category>
    </item>
    <item>
      <title>SUBQUERIES AND CTEs</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Fri, 11 Sep 2026 19:17:41 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/subqueries-and-ctes-1eb8</link>
      <guid>https://dev.to/ken_ndungu/subqueries-and-ctes-1eb8</guid>
      <description>&lt;p&gt;There comes a time in the life of any SQL student when they find themselves writing queries in a certain way. Before this moment, they write their queries in a straight line, selecting this, joining that, grouping by the other. After this moment, they write queries like dragons: constructing a query from blocks, each one giving a small amount of data, naming it something understandable, and moving on. All the complex beasts of SQL that once terrified them are now simple littleizards that they can debug without fear. This moment comes when they learn about subqueries and Common Table Expressions (CTEs).&lt;/p&gt;

&lt;p&gt;A subquery is simply a query nested within another query. A CTE is a named subquery, useful for organizing more complex SQL statements.&lt;/p&gt;

&lt;p&gt;In this article, we will explore both, using each to solve the same problem in order to highlight their similarities and differences.&lt;/p&gt;

&lt;p&gt;Subqueries serve many different purposes and can be used in the SELECT, FROM, WHERE, JOIN, and HAVING clauses. &lt;/p&gt;

&lt;h2&gt;
  
  
  1.Subqueries in  SELECT
&lt;/h2&gt;

&lt;p&gt;A subquery in the SELECT section of a query always has to return a &lt;strong&gt;scalar value&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2.Correlated subquery&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;correlated&lt;/strong&gt; subquery is a type of  query that uses values from the outer query. The inner query executes, referencing these value(s), and returns the result to the outer query. This happens &lt;br&gt;
row by row.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;3. Subqueries in FROM/JOIN&lt;/strong&gt;&lt;br&gt;
ubqueries can be used in FROM and JOIN to create intermediate or derived tables, which can be queried again. This is particularly useful when we would like to use aggregated data along with &lt;br&gt;
column data.&lt;br&gt;
This is the syntax&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ddmitf52ry3qhp31sa8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ddmitf52ry3qhp31sa8.png" alt="subqueries" width="633" height="132"&gt;&lt;/a&gt;&lt;br&gt;
example&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;4.Subqueries in WHERE/HAVING&lt;/strong&gt;&lt;br&gt;
Subqueries can be used in WHERE and HAVING to enable customized or advanced filtering of results.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Common Table Expressions&lt;/strong&gt;&lt;br&gt;
A Common Table Expression, or CTE, is a named query that exists within the context of a larger query. Its results are temporarily stored such that they can be referenced later by other queries, other CTEs, or even itself.&lt;br&gt;
CTE syntax&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmokd3unyfd2vd7upkek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmokd3unyfd2vd7upkek.png" alt="syntax" width="800" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Multiple CTEs&lt;/strong&gt;&lt;br&gt;
It is possible to specify more than one CTE within a single query. In such a case, each CTE definition is separated by a &lt;strong&gt;comma.&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8skasvgd9efl2a6wdb6v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8skasvgd9efl2a6wdb6v.png" alt="syntax" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>subqueries</category>
      <category>commontableexpressions</category>
      <category>analytics</category>
    </item>
    <item>
      <title>SQL JOINS</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Fri, 11 Sep 2026 15:19:45 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/sql-joins-3clp</link>
      <guid>https://dev.to/ken_ndungu/sql-joins-3clp</guid>
      <description>&lt;p&gt;Think of your database as a city.&lt;/p&gt;

&lt;p&gt;Your tables are the different buildings; the library, the hospital, the post office. Each has their own records, their own purpose, their own filing system.&lt;/p&gt;

&lt;p&gt;A primary key is the address of the building, a foreign key is a note saying "see the hospital on 5th street" and a JOIN is the road that connects them.&lt;/p&gt;

&lt;p&gt;Without these connecting roads, otherwise known as join clauses, your city is pretty much useless as each building is isolated. By joining two or more tables you can answer questions that required information from more than one table, like "which patients checked out medical books from the library?"&lt;/p&gt;

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

&lt;p&gt;In structured query language (SQL), a join is used to join two or more tables in a relational database. As their name suggests, relational databases are ones that store data according to pre-defined relationships, which define how data that is stored in one table connects to that which is stored in another (or several others).&lt;/p&gt;

&lt;p&gt;The join clause is used to retrieve data from related tables in a database. Because it retrieves data from multiple tables, the SQL join clause is much more complex than a simple query that retrieves data from just one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TYPES OF SQL JOINS&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Inner join
&lt;/h2&gt;

&lt;p&gt;An inner join combines two tables by using a key. For instance, the key might be a column called “product id” where each user has a unique number. You could combine this table with another that contains information about each user by joining on the “product id” column. The following example uses an &lt;em&gt;inner join&lt;/em&gt; clause to join two tables:In this example we are joining the &lt;strong&gt;drivers_trips&lt;/strong&gt; table to &lt;strong&gt;safari.drivers&lt;/strong&gt; on common column &lt;strong&gt;driver_id&lt;/strong&gt;. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2. Left outer join&lt;/strong&gt;&lt;br&gt;
The left outer joins return all rows from the first table and only those rows from the second table that match,the tables are joined on a common column.&lt;em&gt;Left outer join&lt;/em&gt; and &lt;em&gt;Left join&lt;/em&gt; is one and the same thing .Here is an example of how to use the &lt;em&gt;Left outer join&lt;/em&gt; clause to join two tables:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;3. Right outer join&lt;/strong&gt;&lt;br&gt;
Right joins are logical opposites of left joins: they return all rows from the second table, and only the rows in the first table that match.Left outer join and Left join is one and the same thing,both of them can be used interchangeably. This example shows how to use a &lt;em&gt;right outer join&lt;/em&gt; clause to join two tables:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;4. Full outer join&lt;/strong&gt;&lt;br&gt;
Full joins combine both left and right joins, and return all rows from both tables, provided that both have at least one matching row. Here is an example of using the full outer join clause to join two tables:&lt;/p&gt;

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

&lt;p&gt;To visually understand what is how join happens take a look at the following table.&lt;/p&gt;

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

</description>
      <category>sql</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>Postgres commands</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Tue, 21 Jul 2026 11:04:33 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/postgres-commands-13a6</link>
      <guid>https://dev.to/ken_ndungu/postgres-commands-13a6</guid>
      <description>&lt;p&gt;These commands can be classified into group based on their nature&lt;br&gt;
1.Data Definition Language - (DDL)&lt;br&gt;
The commands include &lt;br&gt;
CREATE,ALTER,DROP&lt;br&gt;
2.Data Manipulation Language -(DML)&lt;br&gt;
The commands include &lt;br&gt;
INSERT,UPDATE,DELETE&lt;br&gt;
3.Data Control Language - (DCL)&lt;br&gt;
The commands include&lt;br&gt;
GRANT,GRANT&lt;br&gt;
4.Dta Query Language - (DQL)&lt;br&gt;
The commands include &lt;br&gt;
SELECT&lt;br&gt;
We shall learn these commands through practice,first its important to create a Schema  where most of our tables will reside.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhbwihbq26tyd3kcb0fb9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhbwihbq26tyd3kcb0fb9.png" alt="schemapostgres" width="459" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead and set the path to schema.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbylxdmb785egz2nsxkst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbylxdmb785egz2nsxkst.png" alt="setting schema path" width="495" height="65"&gt;&lt;/a&gt;&lt;br&gt;
Create a table with the following syntax.&lt;/p&gt;

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

&lt;p&gt;create the following 2 tables.&lt;/p&gt;

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

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

&lt;p&gt;&lt;em&gt;INSERT INTO command&lt;/em&gt; is used to insert data into tables.When inserting data into a table its important to specify the columns&lt;br&gt;
in chronological order.Make sure the data being inserted is presented in the correct way.Date,texts and phone_numbers should be in single quotes.Integers,decimals and percentages should not be in single quotes.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp43e0ifi5wdryozjo4zx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp43e0ifi5wdryozjo4zx.png" alt="Inserting info into the database" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To confirm if the tables have data run the following commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fopu5dcdetblkvm7p0i0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fopu5dcdetblkvm7p0i0m.png" alt="confirmation commands" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
It's evident that we have 3 tables exams_result,students and subjects table.&lt;/p&gt;

&lt;p&gt;In the comment section(/* ...*/) of the data definition language&lt;br&gt;
,there is  a syntax showing how to write such a query.&lt;br&gt;
Data definition language like &lt;em&gt;alter table&lt;/em&gt; can be used to rename &lt;br&gt;
a table,rename a column,change dat type,remove a column and add a column.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxr4laxt8lmqvaz70mbz2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxr4laxt8lmqvaz70mbz2.png" alt="data deinition language" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have also outlined the syntax for the where clause in the comment section.The where clause can be used in a filtering context and combining logic.On combining logic we use different operators such as between,and,or,greater than,less than and eaqual to.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbl41e17j7zxu6hgun4tk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbl41e17j7zxu6hgun4tk.png" alt="where clause " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Count&lt;/em&gt; function can be used in different way.First to count the number of rows in the dataset with the following syntax &lt;em&gt;SELECT COUNT(*) FROM table_name;&lt;/em&gt;.Second to count the number of values in a certain column with the following syntax &lt;em&gt;SELECT COUNT(column_name) FROM table_name WHERE condition;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Facrx8fyekpaymteoy1or.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Facrx8fyekpaymteoy1or.png" alt="count" width="750" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;CASE&lt;/em&gt; expression is used to define different results based on specified conditions in an SQL statement.&lt;br&gt;
The &lt;em&gt;CASE&lt;/em&gt; expression goes through the conditions and stops at the first match (like an if-then-else statement). So, once a condition is true, it will stop processing and return the result. If no conditions are true, it returns the value in the &lt;em&gt;ELSE&lt;/em&gt; clause. If there is no &lt;em&gt;ELSE&lt;/em&gt; clause and no conditions are true, it returns &lt;em&gt;NULL&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl43voy63cfq263fo4h4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl43voy63cfq263fo4h4a.png" alt="case when" width="729" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>postgressql</category>
    </item>
    <item>
      <title>JOINING DATABASES TO POWER BI</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Sat, 04 Jul 2026 12:43:24 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/joining-databases-to-power-bi-1ofk</link>
      <guid>https://dev.to/ken_ndungu/joining-databases-to-power-bi-1ofk</guid>
      <description>&lt;p&gt;Databases are like containers used to store data,the data may be structured, semi structured, or unstructured.The databases may be located on the local machines or on the cloud. In this article we shall discuss how to join databases to powerbi.&lt;br&gt;
On our local machines we need to have a database management system like &lt;em&gt;Dbeaver&lt;/em&gt; to manage all the activities happening on the database.&lt;br&gt;
In Dbeaver , there is a ribbon with &lt;em&gt;Database&lt;/em&gt; title.Click it,  a drop down will appear and select a &lt;em&gt;new connection&lt;/em&gt;.&lt;/p&gt;

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

&lt;p&gt;Select your preferred database in this case we choose postgresql.&lt;/p&gt;

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

&lt;p&gt;In the connection settings we are given the host,database,port,username but we have to input the password(The password should be the one we created when we were installing postgresql).&lt;/p&gt;

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

&lt;p&gt;Proceed by clicking Test Connection ,if you  are prompted to download database drivers  click download.Once connection has been established click ok .&lt;/p&gt;

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

&lt;p&gt;On the defaultdb create a database and and Schema with the following  SQL commands.&lt;br&gt;
CREATE database mytrial;&lt;br&gt;
CREATE Schema Powerbi;&lt;/p&gt;

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

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

&lt;p&gt;The database is empty and it's important to load data into the database.Hover the cursor on the Schema,right click it and import  data.Click input files and then browse the file in your computer.Select the file  you  want in your computer and select open.The file will be loaded in your database.&lt;br&gt;
To connect the database to powerbi  open powerbi, click Get Data then more and select Database. On the Database  tab select your preferred database e.g. postgresql.&lt;/p&gt;

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

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

&lt;p&gt;On the Postgresql database tab there are server  and database spaces and it's important to fill  the  spaces. On the server  paste this ip 127.0.0.1 full colon  and the port 5432.Type  the database. &lt;br&gt;
Type the username and the password.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8gvq1p9mrb4mp5l6snb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8gvq1p9mrb4mp5l6snb.png" alt="select the table you want" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Now we have connected  database on our machines  with power bi.&lt;br&gt;
If the database is on the cloud we  need to have a Saas subscription (Software as a service) platforn that gives us the password,host,ca certificate,port,username and password.&lt;/p&gt;

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

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

&lt;p&gt;Once we have the above information open powerbi and select Get Data,select more and click  Database.On the database tab click on Postgres.A small tab will appear titled Postgres database with database and server spaces.On the Saas platform copy host,port fullcolon and database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpig7six1jkb3c9bya88b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpig7six1jkb3c9bya88b.png" alt="join database to powerbi" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Go ahead and type the username and password then click connect.&lt;br&gt;
You will encounter &lt;em&gt;"Unable to connect"&lt;/em&gt; error in powerbi.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo5ciom3ij5rf6utdiy75.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo5ciom3ij5rf6utdiy75.png" alt="unable to connect error" width="800" height="421"&gt;&lt;/a&gt;&lt;br&gt;
On the Saas platform download ca certificate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F076b6i8itugrr6a2al9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F076b6i8itugrr6a2al9i.png" alt="ca certificate" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
In your computer there is a start button,search Manage user certificate  and select it.Select the Trusted Root Certification Authorities.Click on the greater than sign before Trusted Root Certification Authorities.Right click on certificates.A dropdown will appear,click on the greater sign on "All Task" an import table will appear select it.Click next then browse,select the ca certificate then open it.Click next and finish.Certificate import wizard will appear showing th import was successful.&lt;/p&gt;

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

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

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

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

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

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

&lt;p&gt;On powerbi click the close button and open powerbi.&lt;/p&gt;

&lt;p&gt;Select Get Data,select more and click  Database.On the database tab click on Postgres.A small tab will appear titled Postgres database with database and server spaces.On the Saas platform copy host,port fullcolon and database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpig7six1jkb3c9bya88b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpig7six1jkb3c9bya88b.png" alt="join database to powerbi" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Go ahead and type the username and password then click connect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8vjsx5mgotma4m57mo9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8vjsx5mgotma4m57mo9.png" alt="aivendatabse to powerbi connection" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
We have successfully connected database on aiven to powerbi&lt;/p&gt;

</description>
      <category>database</category>
      <category>saas</category>
      <category>analytics</category>
    </item>
    <item>
      <title>POWER BI</title>
      <dc:creator>KENNEDY NDUNGU WANJIRU</dc:creator>
      <pubDate>Tue, 23 Jun 2026 06:30:40 +0000</pubDate>
      <link>https://dev.to/ken_ndungu/power-bi-49bn</link>
      <guid>https://dev.to/ken_ndungu/power-bi-49bn</guid>
      <description>&lt;p&gt;Data modeling in Power bi is  the process of structuring, organizing, and defining relationships between your data tables so they can be accurately analyzed and visualized.&lt;br&gt;
There are  different Schemas in data analysis; they are Star Schema and Snowflake Schema. Star Schema entails a  fact table (central table)  surrounded by many dimensional tables.Dimensional tables are joined to the central table using  one to many relationship, many to one relationship or one to one. In one to many relationships  one record can be attributed to many other records and vice versa . In one to one one record can be attributed to another record.This is possible by having primary key columns  and foreign key columns..Furthermore, one is able to move from one table to another through a defined direction.&lt;/p&gt;

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

&lt;p&gt;Snowflake Schema is built on Star Schema’s structure but the dimensional tables are joined to other subdimensional tables through  table  relationships.&lt;/p&gt;

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

&lt;p&gt;In power bi there different types of joins they include &lt;/p&gt;

&lt;p&gt;-Inner Join &lt;br&gt;
This is where two tables are joined through a  common column in both tables.&lt;br&gt;
-Left Join&lt;br&gt;
This is where the table on the left is joined to the table on the right through a common  column.The empty cells in the left table will be joined to the right and they will be highlighted as NULL.&lt;br&gt;
-Right Join&lt;br&gt;
This is where the table on the right  is joined to the table on the left through a common  column.The empty cells in the right  table will be joined to the left  and they will be highlighted as NULL.&lt;br&gt;
-full outer join&lt;br&gt;
It joins both the tables from the left and right. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv89g7ezels600f3joa0b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv89g7ezels600f3joa0b.png" alt="This diagram shows all types of joins" width="799" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>modellingjoinsschemas</category>
    </item>
  </channel>
</rss>
