<?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>Forem: elsie-n</title>
    <description>The latest articles on Forem by elsie-n (@elsien).</description>
    <link>https://forem.com/elsien</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%2F849997%2F605f2f43-f830-4be4-914f-824dab2909c6.PNG</url>
      <title>Forem: elsie-n</title>
      <link>https://forem.com/elsien</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/elsien"/>
    <language>en</language>
    <item>
      <title>Detecting Fake News with Python and Machine Learning</title>
      <dc:creator>elsie-n</dc:creator>
      <pubDate>Wed, 04 May 2022 13:43:52 +0000</pubDate>
      <link>https://forem.com/elsien/detecting-fake-news-with-python-and-machine-learning-56m5</link>
      <guid>https://forem.com/elsien/detecting-fake-news-with-python-and-machine-learning-56m5</guid>
      <description>&lt;p&gt;We consume news through several mediums throughout the day in our daily routine, but sometimes it becomes difficult to decide which one is fake and which one is authentic not every piece of news that we consume is not real. &lt;/p&gt;

&lt;h2&gt;
  
  
  Terminologies
&lt;/h2&gt;

&lt;p&gt;-&lt;strong&gt;Fake News&lt;/strong&gt;&lt;br&gt;
A sort of sensationalist reporting, counterfeit news embodies bits of information that might be lies and is, for the most part, spread through web-based media and other online media.&lt;br&gt;
This is regularly done to further or force certain kinds of thoughts or for false promotion of products and is frequently accomplished with political plans.&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;Tfidf Vectorizer&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;TF(Term Frequency)&lt;/em&gt;&lt;br&gt;
These are the number of times a word is present in a document. Large values mean that a word is present so many times with respect to other words.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;IDF(Inverse Document Frequency)&lt;/em&gt;&lt;br&gt;
IDF is a proportion of how critical a term is in the whole corpus of data.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Project&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;To detect fake news and real news. Using sklearn, we build a TfidfVectorizer on our dataset. Then, we initialize a PassiveAggressive Classifier and fit the model. In the end, the accuracy score and the confusion matrix tell us how well our model fares.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PassiveAggressive&lt;/em&gt;&lt;br&gt;
Passive Aggressive algorithms are online learning algorithms. Such an algorithm remains passive for a correct classification outcome, and turns aggressive in the event of a miscalculation, updating and adjusting. Unlike most other algorithms, it does not converge.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Data Analysis&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;The data set used can be found [(url)]&lt;/p&gt;

&lt;p&gt;This dataset has four columns,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;unnamed&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;title&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;text&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;label&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Libraries&lt;/em&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import pandas as pd
import itertools
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.metrics import accuracy_score, confusion_matrix

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

&lt;/div&gt;



&lt;p&gt;The output is in form of a vector;&lt;br&gt;
confusion_matrix(y_test,y_pred, labels=['FAKE','REAL'])&lt;br&gt;
Fake=True Real=False&lt;/p&gt;

&lt;p&gt;Link to the project code &lt;br&gt;
[(&lt;a href="https://github.com/elsie-n/FakeNews/tree/main)"&gt;https://github.com/elsie-n/FakeNews/tree/main)&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>machinelearning</category>
      <category>news</category>
    </item>
    <item>
      <title>Mastering Python for Web Development.</title>
      <dc:creator>elsie-n</dc:creator>
      <pubDate>Wed, 04 May 2022 07:13:50 +0000</pubDate>
      <link>https://forem.com/elsien/mastering-python-for-web-development-20b6</link>
      <guid>https://forem.com/elsien/mastering-python-for-web-development-20b6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Web Development&lt;/strong&gt; is loosely defined as building, creating, and maintaining websites. It involves a frontend, everything that interacts with the client, and a backend, which contains business logic and interacts with a database.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Advantages of using python for web development&lt;/em&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Wide spread popularity&lt;/em&gt;&lt;br&gt;
Python is one of the most popular languages in the world, with communities from all over the world it provides extensive support and framework for one to begin their developer journey.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Easy to learn&lt;/em&gt;&lt;br&gt;
Python is popular among first time learners since it has lower barrier to entry since the code is easily understood.The language relies on common expressions and whitespace, which allows you to write significantly less code compared to some other languages like Java or C++. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Rich ecosystem and libraries&lt;/em&gt;&lt;br&gt;
Python offers a vast range of library tools and packages, which allows you to access much pre-written code, streamlining your application development time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Large Community&lt;/em&gt;&lt;br&gt;
Python has a large community of developers using it, which is because of its wide acceptance. This makes it easy for beginners &lt;br&gt;
who have questions. Moreover, the issues that developers face when developing applications are either already resolved or will be resolved quickly as there are a large number of developers who are willing to help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Fast,Powerful &amp;amp; Productive&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;User friendly runs everywhere&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;More Versatile than PHP&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Readable Flexible &amp;amp; Secure&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Extensible &amp;amp; Intergrable&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Python Web Framework&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;framework&lt;/strong&gt; is a collection of pre-written packages and modules that supports the development of web applications, making development faster and easier, and your programs more reliable and scalable.&lt;/p&gt;

&lt;p&gt;Python is mostly used for building the backend. Python frameworks take care of dealing with tasks that are related to backend application development, such as parsing HTTP requests, generating HTTP responses, accessing the database, authentication, authorization, etc.&lt;br&gt;
Some of the popular python web frameworks include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Django&lt;/em&gt;
Is a Python web framework that offers an open-source, high-level framework that “encourages rapid development and clean, pragmatic design.” It’s fast, secure, and scalable. Django offers strong community support and detailed documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the reasons for Django’s popularity is that it is quite easy to learn and use, especially because of its pluggable architecture. Django allows you to build small decoupled apps that can be included or plugged into larger projects. In Django, you get apps and projects, where an app is a small self-contained codebase, while a project is a collection of multiple apps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Flask&lt;/em&gt;
It is a microframework meaning, it does not have a lot of features baked into it that the other web frameworks might have, such as templating, account authorization, authentication, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flask is minimalistic and lightweight, meaning that you add extensions and libraries that you need as you code without automatically being provided with it by the framework.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pyramid&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web2Py&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Turbogears&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CherryPy&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The framework one chooses is dependent on your skill level as a web developer:&lt;/p&gt;

&lt;p&gt;If you are quite experienced, consider developing your program with something more “barebones”;Flask.You can also use it if you know a few libraries and only need a framework to deal with common webserver tasks such as HTTP communication, request parsing, etc.&lt;/p&gt;

&lt;p&gt;For a developer with not much experience in web development or if you are tackling a big project and do not wish to deal with annoying low-level details, then Django is the right choice for you. You can also use it if you do not wish to deal with managing individual packages and integrating them later as Django comes with many packages by default&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Python Libraries&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Some useful Python libraries for web development to keep note of:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you ever need a web crawler to extract data for your application, &lt;strong&gt;Scrapy&lt;/strong&gt; is great for that. It’s a widely used library for scraping, data mining, automated testing, and more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zappa&lt;/strong&gt; is a powerful library for developing a serverless application on AWS Lambda.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requests&lt;/strong&gt; is a library that allows you to send HTTP requests easily, which is used to communicate with an application, allowing you to get HTML pages or data, for example.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another useful library is &lt;strong&gt;Dash&lt;/strong&gt;, which helps those developing web applications that have to do with data visualization. Built on top of Flask, it offers features like charts, graphs, dashboards, and more.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Introduction to Python</title>
      <dc:creator>elsie-n</dc:creator>
      <pubDate>Wed, 27 Apr 2022 08:22:42 +0000</pubDate>
      <link>https://forem.com/elsien/introduction-to-python-1b2o</link>
      <guid>https://forem.com/elsien/introduction-to-python-1b2o</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is python?&lt;/strong&gt;&lt;br&gt;
Python is a high-level, general purpose, interpreted programming language meaning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is easy to learn&lt;/li&gt;
&lt;li&gt;Can be used in various domains, i.e web applications,automation,data science, machine learning and AI, 
the targeted language like SQL which can be used for querying data from relational databases.&lt;/li&gt;
&lt;li&gt;It is an interpreted language,turns the source code, line by line, once at a time, into the machine code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why Python&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python increases your productivity. Python allows you to solve complex problems in less time and fewer lines of code. It’s quick to make a prototype in Python.&lt;/li&gt;
&lt;li&gt;Python becomes a solution in many areas across industries, from web applications to data science and machine learning.&lt;/li&gt;
&lt;li&gt;Python is quite easy to learn in comparison with other programming languages. Python syntax is clear and beautiful.&lt;/li&gt;
&lt;li&gt;Python has a large ecosystem that includes lots of libraries and frameworks.&lt;/li&gt;
&lt;li&gt;Python is cross-platform. Python programs can run on Windows, Linux, and macOS.&lt;/li&gt;
&lt;li&gt;Python has a huge community. Whenever you get stuck, you can get help from an active community.&lt;/li&gt;
&lt;li&gt;Python developers are in high demand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
To download the latest version click [(&lt;a href="https://www.python.org/downloads/)"&gt;https://www.python.org/downloads/)&lt;/a&gt;], run the program and install.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Basics&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Fundamentals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Whitespaces and Indentations&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Unlike other programming languages ,Python uses whitespace and indentation to construct the code structure to separate statements instead of single colon(;)&lt;br&gt;
This whitespaces should be uniform otherwise an error occurs while running the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def studentcode():
    i = 1
    max = 10
    while (i &amp;lt; max):
        print(i)
        i = i + 1

# call function studentcode 
studentcode()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Comments&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Comments are part of the code that does not get executed rather  are as important since they describe why a piece of code was written.&lt;br&gt;
In Python there are two ways  of writing comments :&lt;br&gt;
a single line comment begins with a hash (#) symbol followed by the comment. &lt;br&gt;
&lt;code&gt;# call function studentcode&lt;/code&gt;&lt;br&gt;
multiline comments (""" comment   """)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
def studentcode():
    i = 1
    max = 10
    while (i &amp;lt; max):
        print(i)
        i = i + 1

# call function studentcode 
studentcode()"""

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Identifiers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This are names that identify variables, functions, modules, classes, and other objects in Python, they are case sensitive and cannot use keywords.&lt;br&gt;
some features to consider while choosing variables(containers for storing data values) include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable names are case sensitive;studentcode is different from Studentcode&lt;/li&gt;
&lt;li&gt;A variable name can only contain alphanumeric characters and underscores.&lt;/li&gt;
&lt;li&gt;A variable name cannot start with a number, it must start with a letters or an underscore character.&lt;/li&gt;
&lt;li&gt;Variable names cannot contain spaces. To separate words in variables, you use underscores.&lt;/li&gt;
&lt;li&gt;String variables are declared either by using  a single/double quotes.
&lt;code&gt;code = 'studentcode'&lt;/code&gt;
&lt;code&gt;code = "studentcode"&lt;/code&gt;
&lt;em&gt;Bonus&lt;/em&gt;
Too get the data type of a variable
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ()function
 code = 56
print(type(code))

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

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Strings&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;strings are declared using single or double quotes.&lt;br&gt;
To concatenate strings use (+)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print "This is" +" a good string"

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

&lt;/div&gt;



&lt;p&gt;To access a specific element in  a string use index of that particular string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str = "Python String"
print(str[0]) # P
print(str[1]) # y

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+---+---+---+---+---+---+---+---+---+---+---+---+---+
| P | y | t | h | o | n |   | S | t | r | i | n | g | 
+---+---+---+---+---+---+---+---+---+---+---+---+---+
  0   1   2   3   4   5   6   7   8   9   10  11  12
-12  -11  -10 -9  -8  -7  -6  -5  -4  -3  -2  -1   0 

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

&lt;/div&gt;



&lt;p&gt;To get the length of a string, you use the len() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str = "Python String"
str_len = len(str)
print(str_len)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Numbers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Python supports integers int(),float float() and complex numbers.&lt;br&gt;
There are different types of operations;&lt;br&gt;
    Arithmetic Operators&lt;br&gt;
    Comparison Operators&lt;br&gt;
    Logical Operators&lt;br&gt;
The different &lt;em&gt;Arithmetic operators&lt;/em&gt; used include :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(5 + 2)  # 7 (addition)
print(5 - 2)  # 3 (subtraction)
print(5 * 2)  # 10 (multiplication)
print(5 / 2.0)  # 2.5 (division)
print(2 ** 8)  # 256 (exponent)
print(5 % 2)  # 1 (remainder of the division)
print(5 // 2)  # 2 (floor division)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;notice to get float when dividing you should indicate either of the numbers as a float type or both,i.e&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(5 / 2.0)  # 2.5 float
print(5.0 / 2.0)  # 2.5 float
print float(5)/2 #2.5 float
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also some of the different &lt;em&gt;Comparison operators&lt;/em&gt; include;&lt;br&gt;
Equal to (==)&lt;br&gt;
Not equal to (!=)&lt;br&gt;
less than (&amp;lt;)&lt;br&gt;
Less than or equal to (&amp;lt;=)&lt;br&gt;
Greater than (&amp;gt;)&lt;br&gt;
Greater than or equal to (&amp;gt;=)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Logical operators&lt;/em&gt; are and/or/not;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And&lt;/em&gt; checks if both the statements are true &lt;br&gt;
&lt;em&gt;Or&lt;/em&gt; checks if either of the statements is true &lt;br&gt;
&lt;em&gt;Not&lt;/em&gt; which gives the opposite of the given condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5 
    b = 2 
# True if both conditions are true  
print(a &amp;gt; 3 and a &amp;lt; 7)  

# True if one condition is true  
print(a &amp;gt; 6 or b &amp;lt; 7)  

# True if given condition is false (inverse of given condition)  
print(not(a &amp;gt; 3))  

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Boolean&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Checks if a statement given a condition is true or false .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = "Elsie"
if a is "Elsie" 
   ("true")
 else 
 print "False"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;List&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Python uses the square brackets ([]) to indicate a list and a comma(,) to separate the elements in the list.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;students = ['Elsie', 'Judy', 'Lawrence']&lt;/code&gt;&lt;br&gt;
To get rid of the quotes and commas while printing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;students = ['Elsie', 'Judy', 'Lawrence']
 print "".join(students)
#or 
 print "...".join(students)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Tuple&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Tuples are just like lists, but immutable (cannot be modified). They are surrounded by ()&lt;br&gt;
&lt;code&gt;students = ('Elsie', 'Judy', 'Lawrence')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dictionaries&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A Python dictionary is a collection of key-value pairs where each key is associated with a value. Python uses the curly braces {} to define a dictionary. Inside the curly braces, you can place zero, one, or many key-value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = {
    'first_name': 'John',
    'last_name': 'Doe',
    'age': 25,
    'favorite_colors': ['blue', 'green'],
    'active': True
}
print(person['first_name']) #retrieves the first name
print(person['last_name']) #retrieves the last name

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Control flow&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Some of the control flow options include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if statements;
if statement
if…else statement 
nested if 
if ladder&lt;/li&gt;
&lt;li&gt;for loop&lt;/li&gt;
&lt;li&gt;while loop &lt;/li&gt;
&lt;li&gt;break &amp;amp; clause&lt;/li&gt;
&lt;li&gt;ternary operator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;if statement&lt;/em&gt;&lt;br&gt;
There are different kinds of if statements &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if statement
This checks if  a statement satisfies one condition and prints.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;student_mark = input('Enter your marks:')
  if int(student_marks) &amp;gt;= 60:
    print("pass")

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

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;if…else 
Use the if...else statement when you want to run another code block if the condition is not True.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;student_mark = input('Enter your marks:')
  if int(student_marks) &amp;gt;= 60:
    print("pass")
  else 
    print ("fail")

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

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;for loop&lt;/em&gt;&lt;br&gt;
The for loop enables you to execute a block of code multiple times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for index in range(n):
    statement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The index is called a loop counter .And n is the number of times that the loop will execute the statement.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While loop&lt;/em&gt;&lt;br&gt;
While statement allows you to execute a code block repeatedly as long as a condition is True, checks the condition at the beginning of each iteration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;max = 5
counter = 0

while counter &amp;lt; max:
    print(counter)
    counter += 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Break&lt;/em&gt;&lt;br&gt;
While using the if or loop statements one would want to terminate prematurely to do this use break &lt;/p&gt;

&lt;p&gt;&lt;code&gt;break&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Functions&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A function is a named code block that performs a job or returns a value. This enables one to perform a task multiple times without rewriting the code all over again. Use def to define a new function.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;def students():&lt;/code&gt;&lt;/p&gt;

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