<?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: Owoeye Anjolaoluwa Khalifa</title>
    <description>The latest articles on DEV Community by Owoeye Anjolaoluwa Khalifa (@khalifa_43).</description>
    <link>https://dev.to/khalifa_43</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F826370%2Fb42aa08a-94f9-426b-a3ae-6c3364010df9.jpg</url>
      <title>DEV Community: Owoeye Anjolaoluwa Khalifa</title>
      <link>https://dev.to/khalifa_43</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khalifa_43"/>
    <language>en</language>
    <item>
      <title>Basic Fundamentals In Python</title>
      <dc:creator>Owoeye Anjolaoluwa Khalifa</dc:creator>
      <pubDate>Sun, 06 Mar 2022 19:16:29 +0000</pubDate>
      <link>https://dev.to/khalifa_43/basic-fundamentals-in-python-2nac</link>
      <guid>https://dev.to/khalifa_43/basic-fundamentals-in-python-2nac</guid>
      <description>&lt;p&gt;Python is a programming language loved by so many data scientists, web developers, and even software engineers. To master Python for any profession, you have to master the fundamentals of the Python programming language. So if you want to learn the fundamentals of the Python programming language, this article is for you. In this article, I’m going to be explaining to you the basic fundamentals in Python that you need to know before you jump into data science, web development, software development or any field that interests you.&lt;/p&gt;

&lt;p&gt;Basic Fundamentals In Python:&lt;br&gt;
This are some basic fundamentals &lt;strong&gt;NOT ALL&lt;/strong&gt; to know before going in some python majors like web development, data science, software development and so on.&lt;/p&gt;

&lt;p&gt;Data Types in Python:&lt;/p&gt;

&lt;p&gt;Data types make programming easier. A data type is a set of values and a set of operations defined on data. An implementation of a data type is an expression of data and operations in terms of a specific programming language. So, here are the data types in Python that you should know before you start learning the Python programming language:&lt;/p&gt;

&lt;p&gt;Data Types  Examples&lt;/p&gt;

&lt;p&gt;Numeric Types:  int, float, complex&lt;br&gt;
Sequence Types: list, tuple, range&lt;br&gt;
Mapping Type:   dict&lt;br&gt;
Set Types:  set, frozenset&lt;br&gt;
Boolean Type:   bool&lt;/p&gt;

&lt;p&gt;Lists:&lt;/p&gt;

&lt;p&gt;Lists are ordered collections of items and the most general data type provided by the Python programming language. They are mutable, which means that items stored in a list can be edited. A list is typically used to perform operations on a collection of items at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mylist = ["apple", "banana", "cherry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tuples:&lt;/p&gt;

&lt;p&gt;A tuple is also a collection of items very similar to a list in Python. Like lists, they allow you to store an ordered collection of items to perform operations at one time. But unlike lists, a tuple cannot be modified once created. The only advantage of using tuples over lists is that tuples are slightly faster than lists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mytuple = ("apple", "banana", "cherry")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionary:&lt;/p&gt;

&lt;p&gt;A dictionary in Python is completely different from lists and tuples, they are not sequences but mappings. Mappings are also collections of items but in the form of key and value pairs. Simply put, a dictionary contains indexes with keys mapped to certain values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Else Statements:&lt;/p&gt;

&lt;p&gt;If-else statements are conditional statements found in all programming languages. These statements are used to write an event-driven program. Simply put, these statements are used when we want to execute a set of statements only if the given condition is met.&lt;br&gt;
Mastering all this before the If Else Statements code is very important: &lt;br&gt;
Equals: a == b&lt;br&gt;
Not Equals: a != b&lt;br&gt;
Less than: a &amp;lt; b&lt;br&gt;
Less than or equal to: a &amp;lt;= b&lt;br&gt;
Greater than: a &amp;gt; b&lt;br&gt;
Greater than or equal to: a &amp;gt;= b&lt;/p&gt;

&lt;p&gt;If statement:&lt;/p&gt;

&lt;p&gt;a = 33&lt;br&gt;
b = 200&lt;br&gt;
if b &amp;gt; a:&lt;br&gt;
 &lt;code&gt;print("b is greater than a")&lt;/code&gt;&lt;br&gt;
return&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;b is greater than a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example we use two variables, a and b, which are used as part of the if statement to test whether b is greater than a. As a is 33, and b is 200, we know that 200 is greater than 33, and so we print to screen that "b is greater than a".&lt;/p&gt;

&lt;p&gt;Indentation&lt;/p&gt;

&lt;p&gt;Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
If statement, without indentation (will raise an error):&lt;/p&gt;

&lt;p&gt;a = 33&lt;br&gt;
b = 200&lt;br&gt;
if b &amp;gt; a:&lt;br&gt;
&lt;code&gt;print("b is greater than a") # you will get an error&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Elif&lt;br&gt;
The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition".&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
a = 33&lt;br&gt;
b = 33&lt;br&gt;
if b &amp;gt; a:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("b is greater than a")
elif a == b:
  print("a and b are equal")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example a is equal to b, so the first condition is not true, but the elif condition is true, so we print to screen that "a and b are equal".&lt;/p&gt;

&lt;p&gt;Else&lt;br&gt;
The else keyword catches anything which isn't caught by the preceding conditions.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
a = 200&lt;br&gt;
b = 33&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if b &amp;gt; a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
else:
  print("a is greater than b")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example a is greater than b, so the first condition is not true, also the elif condition is not true, so we go to the else condition and print to screen that "a is greater than b".&lt;/p&gt;

&lt;p&gt;Loops:&lt;br&gt;
Loops are statements used to iterate over an object. There are two types of loops in Python:&lt;/p&gt;

&lt;p&gt;While Loops&lt;br&gt;
For Loops&lt;br&gt;
A for loop is used to iterate through a collection of items. The While Loop allows you to execute a set of instructions until the given condition is true.&lt;/p&gt;

&lt;p&gt;while loops:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Print i as long as i is less than 6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 1
while i &amp;lt; 6:
  print(i)
  i += 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: remember to increment i, or else the loop will continue forever.&lt;/p&gt;

&lt;p&gt;The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.&lt;/p&gt;

&lt;p&gt;The break Statement&lt;br&gt;
With the break statement we can stop the loop even if the while condition is true:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Exit the loop when i is 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 1
while i &amp;lt; 6:
  print(i)
  if i == 3:
    break
  i += 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The continue Statement&lt;br&gt;
With the continue statement we can stop the current iteration, and continue with the next:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Continue to the next iteration if i is 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 0
while i &amp;lt; 6:
  i += 1
  if i == 3:
    continue
  print(i)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The else Statement&lt;br&gt;
With the else statement we can run a block of code once when the condition no longer is true:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Print a message once the condition is false:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 1
while i &amp;lt; 6:
  print(i)
  i += 1
else:
  print("i is no longer less than 6")

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

&lt;/div&gt;



&lt;p&gt;For loops:&lt;br&gt;
Example&lt;br&gt;
Print each fruit in a fruit list:&lt;/p&gt;

&lt;p&gt;fruits = ["apple", "banana", "cherry"]&lt;br&gt;
for x in fruits:&lt;br&gt;
  print(x)&lt;br&gt;
The for loop does not require an indexing variable to set beforehand.&lt;/p&gt;

&lt;p&gt;Looping Through a String&lt;br&gt;
Even strings are iterable objects, they contain a sequence of characters:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Loop through the letters in the word "banana":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in "banana":
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The break Statement&lt;br&gt;
With the break statement we can stop the loop before it has looped through all the items:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Exit the loop when x is "banana":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)
  if x == "banana":
    break
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
Exit the loop when x is "banana", but this time the break comes before the print:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "cherry"]
for x in fruits:
  if x == "banana":
    break
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The continue Statement&lt;br&gt;
With the continue statement we can stop the current iteration of the loop, and continue with the next:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Do not print banana:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "cherry"]
for x in fruits:
  if x == "banana":
    continue
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The range() Function&lt;br&gt;
To loop through a set of code a specified number of times, we can use the range() function,&lt;br&gt;
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Using the range() function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in range(6):
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that range(6) is not the values of 0 to 6, but the values 0 to 5.&lt;/p&gt;

&lt;p&gt;The range() function defaults to 0 as a starting value, however it is possible to specify the starting value by adding a parameter: range(2, 6), which means values from 2 to 6 (but not including 6):&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Using the start parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in range(2, 6):
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3):&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Increment the sequence with 3 (default is 1):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in range(2, 30, 3):
  print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Else in For Loop&lt;br&gt;
The else keyword in a for loop specifies a block of code to be executed when the loop is finished:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Print all numbers from 0 to 5, and print a message when the loop has ended:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in range(6):
  print(x)
else:
  print("Finally finished!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: The else block will NOT be executed if the loop is stopped by a break statement.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Break the loop when x is 3, and see what happens with the else block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in range(6):
  if x == 3: break
  print(x)
else:
  print("Finally finished!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nested Loops&lt;br&gt;
A nested loop is a loop inside a loop.&lt;/p&gt;

&lt;p&gt;The "inner loop" will be executed one time for each iteration of the "outer loop":&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Print each adjective for every fruit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]

for x in adj:
  for y in fruits:
    print(x, y)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pass Statement&lt;br&gt;
for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for x in [0, 1, 2]:
  pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functions:&lt;br&gt;
Python has a lot of built-in functions like print, input, etc. Besides the built-in functions of Python, you can also define your functions. A function is a block of code defined to perform a certain action. They are primarily used to replace repetitive statements in your code.&lt;br&gt;
Example of python built in function is the print, step on how to use the 'print function'.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;print("Hello, World!")&lt;/code&gt;&lt;br&gt;
printing this code will return&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling a Function&lt;br&gt;
To call a function, you will use the function name followed by parenthesis:&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;code&gt;def my_function():&lt;br&gt;
  print("Hello from a function")&lt;br&gt;
my_function()&lt;/code&gt;&lt;br&gt;
it will return&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello from a function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
So these were all the fundamental concepts that you should know before starting with learning Python for Data Science, Web Development or any other profession. Learn these fundamentals of Python is very important to master Python for any profession that interests you. I hope you liked this article on the fundamentals of Python. Feel free to ask your valuable questions in the comments section.&lt;/p&gt;

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