<?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: Abdikhafar</title>
    <description>The latest articles on DEV Community by Abdikhafar (@abdikhafarhub).</description>
    <link>https://dev.to/abdikhafarhub</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%2F2194881%2Fdfe67cbf-b63b-4fde-9c51-f7fecdc692bd.jpeg</url>
      <title>DEV Community: Abdikhafar</title>
      <link>https://dev.to/abdikhafarhub</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdikhafarhub"/>
    <language>en</language>
    <item>
      <title>How Pulse Manor is Redefining Property Security: Preventing Data Leaks and Fraud with AI</title>
      <dc:creator>Abdikhafar</dc:creator>
      <pubDate>Mon, 23 Mar 2026 11:17:58 +0000</pubDate>
      <link>https://dev.to/abdikhafarhub/how-pulse-manor-is-redefining-property-security-preventing-data-leaks-and-fraud-with-ai-l4a</link>
      <guid>https://dev.to/abdikhafarhub/how-pulse-manor-is-redefining-property-security-preventing-data-leaks-and-fraud-with-ai-l4a</guid>
      <description>&lt;p&gt;The real estate industry is no longer just about buildings, tenants, and rent collection.&lt;br&gt;
It has quietly become a data-driven ecosystem — and with that comes a serious risk:&lt;/p&gt;

&lt;p&gt;👉 Data leaks, fraud, and unauthorized access.&lt;/p&gt;

&lt;p&gt;From tenant identities to financial records and legal documents, property management systems today handle highly sensitive data. One mistake, one vulnerability, and the consequences can be devastating.&lt;/p&gt;

&lt;p&gt;But here’s the shift happening right now:&lt;/p&gt;

&lt;p&gt;Modern property systems — powered by AI — are not just managing properties anymore. They are actively protecting them.&lt;/p&gt;

&lt;p&gt;🚨 The Growing Risk in Property Management&lt;/p&gt;

&lt;p&gt;Traditional property management methods were never built for today’s digital risks.&lt;/p&gt;

&lt;p&gt;Common vulnerabilities include:&lt;/p&gt;

&lt;p&gt;Manual record keeping (spreadsheets, paper files)&lt;br&gt;
Weak access controls&lt;br&gt;
Shared logins across staff&lt;br&gt;
Poor data isolation between properties or organizations&lt;br&gt;
Unsecured document storage (leases, IDs, contracts)&lt;/p&gt;

&lt;p&gt;These gaps create opportunities for:&lt;/p&gt;

&lt;p&gt;Data breaches&lt;br&gt;
Identity theft&lt;br&gt;
Financial fraud&lt;br&gt;
Cross-organization data exposure&lt;/p&gt;

&lt;p&gt;In multi-tenant systems (like modern SaaS platforms), the risk becomes even higher if data is not strictly isolated per organization, property, and user role.&lt;/p&gt;

&lt;p&gt;🧠 Enter AI-Powered Property Systems&lt;/p&gt;

&lt;p&gt;Modern platforms like Pulse Manor are redefining how property data is handled — by combining:&lt;/p&gt;

&lt;p&gt;Intelligent automation&lt;br&gt;
Advanced access control&lt;br&gt;
Real-time monitoring&lt;br&gt;
AI-driven anomaly detection&lt;/p&gt;

&lt;p&gt;This isn’t just software.&lt;/p&gt;

&lt;p&gt;👉 It’s an active security layer.&lt;/p&gt;

&lt;p&gt;🔒 1. Strict Data Isolation (Multi-Tenant Security)&lt;/p&gt;

&lt;p&gt;At the core of secure property systems is one principle:&lt;/p&gt;

&lt;p&gt;👉 Every piece of data must belong to the correct organization — and only that organization.&lt;/p&gt;

&lt;p&gt;Modern systems enforce:&lt;/p&gt;

&lt;p&gt;Organization-level isolation&lt;br&gt;
Property-level segmentation&lt;br&gt;
Unit-level data boundaries&lt;/p&gt;

&lt;p&gt;This ensures that:&lt;/p&gt;

&lt;p&gt;A tenant from Property A can never see data from Property B&lt;br&gt;
A property manager cannot access another organization’s records&lt;br&gt;
Reports, analytics, and exports remain fully scoped&lt;/p&gt;

&lt;p&gt;This eliminates one of the most dangerous risks in SaaS systems:&lt;br&gt;
👉 Cross-organization data leakage&lt;/p&gt;

&lt;p&gt;👥 2. Role-Based Access Control (RBAC)&lt;/p&gt;

&lt;p&gt;Not everyone should see everything.&lt;/p&gt;

&lt;p&gt;Modern systems define precise roles, such as:&lt;/p&gt;

&lt;p&gt;Property Admin&lt;br&gt;
Property Manager&lt;br&gt;
Tenant&lt;br&gt;
Buyer&lt;br&gt;
Caretaker&lt;br&gt;
Facility Manager&lt;/p&gt;

&lt;p&gt;Each role has strict permissions, for example:&lt;/p&gt;

&lt;p&gt;Tenants cannot access financial records of others&lt;br&gt;
Caretakers cannot view legal documents&lt;br&gt;
Managers cannot override ownership-level data&lt;/p&gt;

&lt;p&gt;AI enhances this further by:&lt;/p&gt;

&lt;p&gt;👉 Detecting unusual access patterns and flagging suspicious behavior.&lt;/p&gt;

&lt;p&gt;🤖 3. AI-Powered Fraud Detection&lt;/p&gt;

&lt;p&gt;This is where things get powerful.&lt;/p&gt;

&lt;p&gt;AI doesn’t just store and protect data — it understands behavior.&lt;/p&gt;

&lt;p&gt;Modern systems use AI to:&lt;/p&gt;

&lt;p&gt;Detect unusual payment patterns&lt;br&gt;
Identify duplicate or suspicious transactions&lt;br&gt;
Flag abnormal login activity&lt;br&gt;
Monitor access attempts across roles and locations&lt;/p&gt;

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

&lt;p&gt;If a user suddenly tries to access multiple tenant records across different properties,&lt;br&gt;
👉 the system can instantly flag or block it.&lt;/p&gt;

&lt;p&gt;This turns your system from passive storage into:&lt;/p&gt;

&lt;p&gt;👉 A real-time fraud detection engine&lt;/p&gt;

&lt;p&gt;🔐 4. Secure Document Handling&lt;/p&gt;

&lt;p&gt;Property systems handle sensitive documents like:&lt;/p&gt;

&lt;p&gt;National IDs&lt;br&gt;
Passports&lt;br&gt;
Lease agreements&lt;br&gt;
Ownership contracts&lt;/p&gt;

&lt;p&gt;Modern architecture separates document storage by risk level:&lt;/p&gt;

&lt;p&gt;Low-risk files (images, maintenance uploads)&lt;br&gt;
High-risk documents (legal, identity, financial data)&lt;/p&gt;

&lt;p&gt;These are stored in segregated environments, often with:&lt;/p&gt;

&lt;p&gt;Encryption at rest&lt;br&gt;
Access-restricted URLs&lt;br&gt;
Signed access tokens&lt;/p&gt;

&lt;p&gt;AI can also scan documents for anomalies or mismatches, reducing fraud during onboarding.&lt;/p&gt;

&lt;p&gt;📊 5. Real-Time Monitoring &amp;amp; Audit Logs&lt;/p&gt;

&lt;p&gt;Every action in a modern system is tracked.&lt;/p&gt;

&lt;p&gt;This includes:&lt;/p&gt;

&lt;p&gt;Who accessed what&lt;br&gt;
When it happened&lt;br&gt;
What changes were made&lt;/p&gt;

&lt;p&gt;With AI, this becomes even more powerful:&lt;/p&gt;

&lt;p&gt;Detects abnormal patterns over time&lt;br&gt;
Identifies insider threats&lt;br&gt;
Predicts potential risks before they happen&lt;/p&gt;

&lt;p&gt;This creates full transparency and accountability across the system.&lt;/p&gt;

&lt;p&gt;⚡ 6. Automated Workflows Reduce Human Error&lt;/p&gt;

&lt;p&gt;Most data breaches don’t happen because of hackers.&lt;/p&gt;

&lt;p&gt;They happen because of:&lt;/p&gt;

&lt;p&gt;👉 Human mistakes.&lt;/p&gt;

&lt;p&gt;Modern systems eliminate this by automating:&lt;/p&gt;

&lt;p&gt;Tenant onboarding&lt;br&gt;
Billing and invoicing&lt;br&gt;
Payment tracking&lt;br&gt;
Communication flows&lt;/p&gt;

&lt;p&gt;Less manual handling = fewer opportunities for errors or manipulation.&lt;/p&gt;

&lt;p&gt;🌍 7. The Shift to Intelligent, Self-Protecting Systems&lt;/p&gt;

&lt;p&gt;We are entering a new era where property systems are not just tools.&lt;/p&gt;

&lt;p&gt;They are:&lt;/p&gt;

&lt;p&gt;Self-monitoring&lt;br&gt;
Self-correcting&lt;br&gt;
Self-protecting&lt;/p&gt;

&lt;p&gt;AI is making it possible for systems to:&lt;/p&gt;

&lt;p&gt;Learn from behavior&lt;br&gt;
Adapt to threats&lt;br&gt;
Prevent issues before they occur&lt;br&gt;
🚀 Why This Matters Now&lt;/p&gt;

&lt;p&gt;As real estate becomes more digital:&lt;/p&gt;

&lt;p&gt;Data volume is increasing&lt;br&gt;
Threats are becoming more sophisticated&lt;br&gt;
Regulations around data privacy are tightening&lt;/p&gt;

&lt;p&gt;Any system that is not built with security at its core is a liability.&lt;/p&gt;

&lt;p&gt;🏁 Final Thoughts&lt;/p&gt;

&lt;p&gt;The future of property management is not just about automation.&lt;/p&gt;

&lt;p&gt;It’s about trust.&lt;/p&gt;

&lt;p&gt;And trust is built on:&lt;/p&gt;

&lt;p&gt;Security&lt;br&gt;
Transparency&lt;br&gt;
Intelligence&lt;/p&gt;

&lt;p&gt;Modern property systems — powered by AI — are setting a new standard:&lt;/p&gt;

&lt;p&gt;👉 Not just managing properties&lt;br&gt;
👉 But actively protecting people, data, and assets&lt;/p&gt;

&lt;p&gt;🔗 Experience the Future&lt;/p&gt;

&lt;p&gt;Pulse Manor is built with enterprise-grade security, AI intelligence, and strict data isolation at its core.&lt;/p&gt;

&lt;p&gt;👉 From tenant management to financial tracking and document security — everything is designed to prevent leaks, fraud, and operational risk.&lt;/p&gt;

&lt;p&gt;Ready to see it in action?&lt;br&gt;
Explore Pulse Manor and experience the future of secure property management.&lt;/p&gt;

</description>
      <category>pulemanor</category>
      <category>ai</category>
      <category>startup</category>
    </item>
    <item>
      <title>SQL: The Backbone of Modern Data Management</title>
      <dc:creator>Abdikhafar</dc:creator>
      <pubDate>Thu, 10 Oct 2024 22:51:45 +0000</pubDate>
      <link>https://dev.to/abdikhafarhub/sql-the-backbone-of-modern-data-management-2f0</link>
      <guid>https://dev.to/abdikhafarhub/sql-the-backbone-of-modern-data-management-2f0</guid>
      <description>&lt;p&gt;Memory updated&lt;br&gt;
SQL: The Backbone of Modern Data Management&lt;br&gt;
In today’s digital age, where vast amounts of data are generated every second, managing this data effectively is crucial for businesses and organizations. Structured Query Language (SQL) is the tool that powers this data-driven world, serving as the standard language for managing and manipulating relational databases. Whether you’re a seasoned developer, a data analyst, or just starting your journey in tech, understanding SQL can significantly enhance your ability to work with data.&lt;/p&gt;

&lt;p&gt;What is SQL?&lt;br&gt;
SQL, pronounced “sequel” or “S-Q-L,” stands for Structured Query Language. It was designed in the 1970s to interact with relational databases, a system where data is organized into tables. Each table consists of rows and columns, much like a spreadsheet, and SQL allows users to query, insert, update, delete, and manipulate this data in a highly structured manner.&lt;/p&gt;

&lt;p&gt;SQL is an industry-standard language, used in various systems like MySQL, PostgreSQL, Microsoft SQL Server, SQLite, and Oracle Database. Despite slight differences in syntax between these systems, the core SQL commands remain the same, making it a universally valuable skill.&lt;/p&gt;

&lt;p&gt;Why is SQL Important?&lt;br&gt;
SQL is essential for several reasons:&lt;/p&gt;

&lt;p&gt;Data Management: SQL allows users to efficiently manage and retrieve data from large databases. You can store data, retrieve specific records, and update information all within a few lines of SQL commands.&lt;br&gt;
Data Analysis: With SQL, analysts can extract meaningful insights from raw data, allowing businesses to make informed decisions. Complex queries can be written to analyze trends, filter information, or join multiple datasets.&lt;br&gt;
Widely Used in Industries: SQL is used across industries like finance, healthcare, retail, and technology. Any industry that uses data relies on SQL to process and retrieve it.&lt;br&gt;
High Demand Skill: As more companies rely on data to drive their decision-making processes, SQL has become a high-demand skill. It's often listed as a required skill in job descriptions for roles like data analyst, database administrator, and software engineer.&lt;br&gt;
SQL Basics: Core Concepts&lt;br&gt;
Let’s explore some of the basic concepts of SQL that form the foundation of this language.&lt;/p&gt;

&lt;p&gt;Databases and Tables:&lt;/p&gt;

&lt;p&gt;A database is a collection of related data, and within a database, data is stored in tables.&lt;br&gt;
Tables are made up of rows (records) and columns (fields). Each column holds a specific type of data like text, integers, or dates.&lt;br&gt;
SQL Queries: SQL queries are the commands that you write to interact with a database. They can be as simple as retrieving all data from a table or as complex as joining multiple tables with specific conditions.&lt;/p&gt;

&lt;p&gt;Here are some of the basic SQL commands:&lt;/p&gt;

&lt;p&gt;SELECT: Retrieves data from one or more tables.&lt;br&gt;
INSERT: Adds new rows to a table.&lt;br&gt;
UPDATE: Modifies existing data in a table.&lt;br&gt;
DELETE: Removes rows from a table.&lt;br&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;SELECT * FROM customers;

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

&lt;/div&gt;



&lt;p&gt;This query selects all columns from the "customers" table.&lt;br&gt;
Filtering Data: The WHERE clause is used to filter records based on specific conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM customers WHERE age &amp;gt; 30;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will retrieve all customers older than 30 years.&lt;/p&gt;

&lt;p&gt;Joins: SQL allows you to combine data from multiple tables using JOIN clauses. This is useful when you have related data spread across several tables.&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;SELECT orders.order_id, customers.name
FROM orders
JOIN customers ON orders.customer_id = customers.customer_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query retrieves order IDs along with customer names by joining the "orders" table and the "customers" table on a common column.&lt;/p&gt;

&lt;p&gt;Aggregate Functions: SQL provides functions to perform calculations on data, such as:&lt;/p&gt;

&lt;p&gt;COUNT(): Counts the number of rows.&lt;br&gt;
AVG(): Finds the average value of a column.&lt;br&gt;
SUM(): Adds up the values in a column.&lt;br&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;SELECT COUNT(*) FROM orders WHERE order_status = 'completed';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This counts the total number of completed orders.&lt;/p&gt;

&lt;p&gt;Indexes: Indexes improve the speed of data retrieval in large databases. By indexing certain columns, SQL queries can be executed faster, as it reduces the need to scan entire tables.&lt;/p&gt;

&lt;p&gt;Advanced SQL Concepts&lt;br&gt;
Once you are comfortable with the basics, you can move on to more advanced SQL concepts.&lt;/p&gt;

&lt;p&gt;Subqueries: A subquery is a query within another query, useful when you need to perform multiple operations to get your result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM customers WHERE customer_id IN (SELECT customer_id FROM orders WHERE order_date &amp;gt; '2024-01-01');

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

&lt;/div&gt;



&lt;p&gt;Transactions: Transactions ensure that a group of SQL operations are executed atomically, meaning either all succeed, or none do. This helps maintain data integrity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN TRANSACTION;
UPDATE account SET balance = balance - 100 WHERE account_id = 1;
UPDATE account SET balance = balance + 100 WHERE account_id = 2;
COMMIT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stored Procedures: A stored procedure is a set of SQL statements saved in the database, which can be executed as a single unit. This is helpful for tasks that need to be repeated frequently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE PROCEDURE get_customers()
BEGIN
   SELECT * FROM customers;
END;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Views: Views are virtual tables that result from a SQL query. They simplify complex queries by storing the results in a table-like format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE VIEW active_customers AS
SELECT * FROM customers WHERE status = 'active';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best Practices for Writing SQL Queries&lt;br&gt;
Writing SQL queries effectively is an important skill to develop. Here are a few best practices:&lt;/p&gt;

&lt;p&gt;Write Readable Queries: Use indentation, aliases, and comments to make your queries more readable, especially when dealing with complex joins and conditions.&lt;br&gt;
Use Proper Indexing: Indexing can dramatically speed up your queries, but excessive indexing can slow down data insertion. Use it wisely.&lt;br&gt;
Limit the Number of Rows: When querying large datasets, use LIMIT to reduce the number of rows returned. This can save processing time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM customers LIMIT 100;

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

&lt;/div&gt;



&lt;p&gt;*Avoid SELECT : Instead of selecting all columns, choose only the columns you need. This reduces the amount of data being processed and speeds up the query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, email FROM customers;

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

&lt;/div&gt;



&lt;p&gt;SQL in the Real World&lt;br&gt;
SQL is used in a wide range of applications. Here are a few real-world use cases that demonstrate the power of SQL:&lt;/p&gt;

&lt;p&gt;E-commerce Platforms: SQL is used to manage product inventories, customer data, orders, and payments. Advanced SQL queries help analyze purchasing behavior and optimize product recommendations.&lt;/p&gt;

&lt;p&gt;Banking Systems: Banks use SQL to manage transactions, customer accounts, loans, and reports. SQL ensures that transactions are processed securely and accurately, preventing issues like double payments or incorrect balances.&lt;/p&gt;

&lt;p&gt;Social Media Platforms: Platforms like Facebook, Twitter, and Instagram rely on SQL databases to store vast amounts of user data. SQL helps in retrieving user profiles, managing relationships between users, and providing personalized content.&lt;/p&gt;

&lt;p&gt;Healthcare: In healthcare, SQL databases are used to manage patient records, medical histories, and billing information. Hospitals use SQL to analyze data for improving patient care and streamlining operations.&lt;/p&gt;

&lt;p&gt;The Future of SQL&lt;br&gt;
While new database technologies, like NoSQL, have emerged, SQL continues to remain relevant. The structured nature of relational databases and SQL's ability to handle large-scale data operations ensure its longevity.&lt;/p&gt;

&lt;p&gt;The future of SQL is expected to evolve alongside trends like:&lt;/p&gt;

&lt;p&gt;Cloud Databases: SQL databases are moving to the cloud with platforms like Amazon RDS, Google Cloud SQL, and Azure SQL Database, offering scalable and cost-effective solutions.&lt;br&gt;
Big Data Integration: SQL is increasingly being used in conjunction with big data technologies like Hadoop and Spark, ensuring structured querying capabilities even in large, unstructured datasets.&lt;br&gt;
AI and Machine Learning: SQL databases are now being optimized to handle AI-driven queries&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
SQL is a powerful and versatile language that forms the backbone of modern data management. From simple queries to complex transactions, it allows you to handle massive datasets efficiently. Whether you’re analyzing customer data, building backend systems, or managing large-scale applications, SQL is an invaluable tool.&lt;/p&gt;

&lt;p&gt;By mastering SQL, you not only gain a crucial technical skill but also unlock the ability to extract meaningful insights from data, contributing to better decision-making and business outcomes.&lt;/p&gt;

&lt;p&gt;So, what’s next? Start practicing! Dive into databases, explore different SQL systems like MySQL or PostgreSQL, and apply what you’ve learned in real-world scenarios. As you continue to refine your SQL skills, you’ll see how it empowers you to harness the full potential of data.&lt;/p&gt;

&lt;p&gt;Happy querying!&lt;/p&gt;

</description>
      <category>database</category>
      <category>backend</category>
    </item>
    <item>
      <title>Introduction to Data Structures and Algorithms.</title>
      <dc:creator>Abdikhafar</dc:creator>
      <pubDate>Thu, 10 Oct 2024 22:18:56 +0000</pubDate>
      <link>https://dev.to/abdikhafarhub/introduction-to-data-structures-and-algorithms-f7p</link>
      <guid>https://dev.to/abdikhafarhub/introduction-to-data-structures-and-algorithms-f7p</guid>
      <description>&lt;p&gt;Why do I need to learn Data Structures and Algorithms in the first place? Will I use them in my workspace?&lt;/p&gt;

&lt;p&gt;Hello and welcome. We are going to demystify the importance of familiarizing oneself with data structures and algorithms and why the interviewers prefer them in the interviews.&lt;br&gt;
Set? Buckle up and let's set off...&lt;/p&gt;

&lt;p&gt;To start off, what is a Data Structure as well as an Algorithm?&lt;br&gt;
From Wikipedia, a data structure is a data organization, management, and storage format that enables efficient access and modification. In simple terms, a data structure is a way of storing data in an efficient or structured manner. In the real world examples, we have examples like a book rack, kitchen cabinets and shoe racks.&lt;br&gt;
In my Python from the word ...Go article, I have covered inbuilt python data structures which comprise: lists, dictionaries, tuples, and sets. Inbuilt data structures mean that they come with ready syntax to be used by the user. In addition to inbuilt data structures, we have user-defined data structures which comprise: array, stack, queue, linked list, tree, graph, and hashmap. This means that the user has to create them from scratch.&lt;br&gt;
We will not go into depths on the inbuilt data structures but can be found explained in depths in the article.&lt;/p&gt;

&lt;p&gt;What then is an algorithm?&lt;br&gt;
An algorithm is a collection of steps to solve a particular problem which can be understood by non-technical people as well. There can be multiple ways and steps to solve a given problem hence there can be multiple algorithms for a specific problem.&lt;/p&gt;

&lt;p&gt;Why are Data Structures and Algorithms important?&lt;br&gt;
To start off, data structures and algorithms in interviews act as a clear demonstration to the interviewer on your problem-solving skills.&lt;br&gt;
Secondly, data structures refer to the way we organize information on our computers and you can guess that the way we organize information can have a lot of impact on the performance. A good example is a library. Suppose, one wants to have a book on Calculus from a library, to do so, one has to first go to the math section, then to the Calculus section. If these books had not been organized in this manner and just distributed randomly then it would have been really a cumbersome process to find the book.&lt;br&gt;
In addition, an Algorithm is a step-by-step process in solving a given task. They are developed to help perform a task more efficiently by one applying a predefined approach or methodology. If you write code as per your perception and judgement without applying any predefined algorithm, your code will probably be botched up after a certain time.&lt;/p&gt;

&lt;p&gt;To sum up, they help one write efficient code and solve problems in optimal or near-optimal ways. Without them, one will be reinventing the wheel which is not always successfully.&lt;/p&gt;

&lt;p&gt;Built-in Data Structures&lt;br&gt;
List&lt;br&gt;
Lists are data structures used to store data in a sequential manner.&lt;br&gt;
They use square brackets.&lt;br&gt;
Every single element in a list is indexed from index 0.&lt;br&gt;
Negative indexing in lists is also supported where the last item in a list is given a -1 index. This helps access of elements from the last to the first.&lt;br&gt;
Data in lists can be modified.&lt;br&gt;
Example of a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
sample_list = [3, 5, "hello", True, 4.76]
Output: [3, 5, "hello", True, 4.76]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tuples&lt;br&gt;
Tuples work like lists but data in tuples cannot be modified (immutable).&lt;br&gt;
They use parenthesis/round brackets.&lt;br&gt;
Example of a tuple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
sample_tuple = (1, 3, "Abdikhafar")
Output: (1, 3, "Abdikhafar")

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

&lt;/div&gt;



&lt;p&gt;Dictionaries&lt;br&gt;
Data in dictionaries is stored as key-value pairs.&lt;br&gt;
The pairs can be accessed, added, and deleted when needed.&lt;br&gt;
Data is stored in curly braces.&lt;br&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;
sample_dict = {"first":"Abdikhafar", "Second":"Issack"}
Output: sample_dict{'first': 'Abdikhafar', 'Second': 'Issack'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sets&lt;br&gt;
Sets, like dictionaries, use curly brackets.&lt;br&gt;
They store a collection of unordered unique elements where each data element must be unique.&lt;br&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;
my_set = {1, 2, 3, 3, 4, 5, 5}
Output: {1, 2, 3, 4, 5}
Assuming you have a 'stack' of books, to get a book in the middle of the stack, one has to get the book at the top book first followed by the second book... to the book that the person wants to access. In Stack, this approach is known as LIFO (Last-in First-out).
This means that it is a linear data structure where elements are accessed only from the top position.
In Stack, elements can be pushed, accessed, and popped as required.



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

&lt;/div&gt;



&lt;p&gt;User-defined data structures&lt;br&gt;
Stack&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5y9hl0obdhv3xjzyl6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5y9hl0obdhv3xjzyl6y.png" alt="Image description" width="541" height="461"&gt;&lt;/a&gt;&lt;br&gt;
Assuming you have a 'stack' of books, to get a book in the middle of the stack, one has to get the book at the top book first followed by the second book... to the book that the person wants to access. In Stack, this approach is known as LIFO (Last-in First-out).&lt;br&gt;
This means that it is a linear data structure where elements are accessed only from the top position.&lt;br&gt;
In Stack, elements can be pushed, accessed, and popped as required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fonaqomymilz9k8kn140l.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fonaqomymilz9k8kn140l.jpg" alt="Image description" width="592" height="421"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
stack = ['first', 'second', 'third']
print(stack)

print()

# pushing elements
stack.append('fourth')
stack.append('fifth')
print(stack)
print()

# printing top
n = len(stack)
print(stack[n-1])
print()

# poping element
stack.pop()
print(stack)

------
(Output)

[‘first’, ‘second’, ‘third’]

[‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]

fifth

[‘first’, ‘second’, ‘third’, ‘fourth’]



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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/stack-data-structure/" rel="noopener noreferrer"&gt;More on stacks&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Queue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqnhdclmeiecm9nzauys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqnhdclmeiecm9nzauys.png" alt="Image description" width="420" height="438"&gt;&lt;/a&gt;&lt;br&gt;
Unlike Stack, Queue works on a principle known as FIFO (Fist-in First-out).&lt;br&gt;
Queues have both head and tail sections and operations can be performed from both the head and the tail.&lt;br&gt;
This means that data in a queue can be accessed and modified either from both the head and/or the tail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbhm0yn914w76vn1ij8n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbhm0yn914w76vn1ij8n.jpg" alt="Image description" width="592" height="421"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
queue = ['first', 'second', 'third']
print(queue)

print()

# pushing elements
queue.append('fourth')
queue.append('fifth')
print(queue)
print()

# printing head
print(queue[0])

# printing tail
n = len(queue)
print(queue[n-1])
print()

# poping element
queue.remove(queue[0])
print(queue)

------
(Output)

[‘first’, ‘second’, ‘third’]

[‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]

first

fifth

[‘second’, ‘third’, ‘fourth’, ‘fifth’]


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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/queue-data-structure/" rel="noopener noreferrer"&gt;More on Queue&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Tree&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk4l8sw77ks3rktwlz9p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk4l8sw77ks3rktwlz9p.jpg" alt="Image description" width="592" height="421"&gt;&lt;/a&gt;&lt;br&gt;
A tree is a non-linear but hierarchical data structure where data originates from the root node.&lt;br&gt;
Each node that precedes another node is known as a parent node while that node is referred to as a child node.&lt;br&gt;
The last nodes in a tree are called leaves&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
class node:
    def __init__(self, ele):
        self.ele = ele
        self.left = None
        self.right = None


def preorder(self):
    if self:
        print(self.ele)
        preorder(self.left)
        preorder(self.right)


n = node('first')
n.left = node('second')
n.right = node('third')
preorder(n)

------
(Output)

first

second

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/binary-tree-data-structure/" rel="noopener noreferrer"&gt;More on Trees&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Graph&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6fbecratzb5c4ts05g24.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6fbecratzb5c4ts05g24.png" alt="Image description" width="491" height="212"&gt;&lt;/a&gt;&lt;br&gt;
A Graph is a non-linear data structure which has a structure which is similar to a tree but works differently. It has nodes which are also referred to as vertices and edges which are lines or arcs that connect any two nodes in the graph.&lt;br&gt;
A valid graph structure consists of a finite set of nodes and edges.&lt;br&gt;
An example is the use of Facebook where everyone is a vertex in the network.&lt;br&gt;
&lt;/p&gt;

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


class adjnode:
    def __init__(self, val):
        self.val = val
        self.next = None


class graph:
    def __init__(self, vertices):
        self.v = vertices
        self.ele = [None]*self.v

    def edge(self, src, dest):
        node = adjnode(dest)
        node.next = self.ele[src]
        self.ele[src] = node

        node = adjnode(src)
        node.next = self.ele[dest]
        self.ele[dest] = node

    def __repr__(self):
        for i in range(self.v):
            print("Adjacency list of vertex {}\n head".format(i), end="")
            temp = self.ele[i]
            while temp:
                print(" -&amp;gt; {}".format(temp.val), end="")
                temp = temp.next


g = graph(4)
g.edge(0, 2)
g.edge(1, 3)
g.edge(3, 2)
g.edge(0, 3)
g.__repr__()

------
(Output)

Adjacency list of vertex 0

head -&amp;gt; 3 -&amp;gt; 2

Adjacency list of vertex 1

head -&amp;gt; 3

Adjacency list of vertex 2

head -&amp;gt; 3 -&amp;gt; 0

Adjacency list of vertex 3

head -&amp;gt; 0 -&amp;gt; 2 -&amp;gt; 1

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/" rel="noopener noreferrer"&gt;More on Graphs&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Linked List&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h7hvt2zwtvhgm9n9aoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h7hvt2zwtvhgm9n9aoe.png" alt="Image description" width="759" height="169"&gt;&lt;/a&gt;&lt;br&gt;
A linked list is a linear data structure which consists of a sequence of elements that are connected to each other and not stored at contiguous memory locations. The elements in a linked list are linked using pointers.&lt;br&gt;
Python does not have linked lists in its standard library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
llist = ['first', 'second', 'third']
print(llist)

print()

# adding elements
llist.append('fourth')
llist.append('fifth')
llist.insert(3, 'sixth')
print(llist)
print()

llist.remove('second')
print(llist)
print()

------
(Output)

[‘first’, ‘second’, ‘third’]

[‘first’, ‘second’, ‘third’, ‘sixth’, ‘fourth’, ‘fifth’]

[‘first’, ‘third’, ‘sixth’, ‘fourth’, ‘fifth’]




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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/linked-list-data-structure/" rel="noopener noreferrer"&gt;More on Linked List&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hashmap&lt;/strong&gt;&lt;br&gt;
Hash maps are indexed data structures which make use of a hash function to compute the index with a key into an array of slots or buckets.&lt;br&gt;
Its value is mapped to the bucket with a corresponding index.&lt;br&gt;
The key cannot be changed (immutable) and is unique.&lt;br&gt;
In python, dictionaries are examples of hash maps.&lt;br&gt;
&lt;/p&gt;

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

def printdict(d):
    for key in d:
        print(key, "-&amp;gt;", d[key])


hm = {0: 'first', 1: 'second', 2: 'third'}
printdict(hm)
print()

hm[3] = 'fourth'
printdict(hm)
print()

hm.popitem()
printdict(hm)

------
(Output)

0 -&amp;gt; first

1 -&amp;gt; second

2 -&amp;gt; third

0 -&amp;gt; first

1 -&amp;gt; second

2 -&amp;gt; third

3 -&amp;gt; fourth

0 -&amp;gt; first

1 -&amp;gt; second

2 -&amp;gt; third


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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/hash-map-in-python/" rel="noopener noreferrer"&gt;More on HashMaps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We now have the basics of data structures. Let's meet in the next session where we expound more on data structures and algorithms as we focus on types of algorithms too.&lt;br&gt;
Can't wait to see you...🥳&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>datastructures</category>
      <category>interview</category>
    </item>
    <item>
      <title>Advanced Python</title>
      <dc:creator>Abdikhafar</dc:creator>
      <pubDate>Thu, 10 Oct 2024 21:05:37 +0000</pubDate>
      <link>https://dev.to/abdikhafarhub/advanced-python-n72</link>
      <guid>https://dev.to/abdikhafarhub/advanced-python-n72</guid>
      <description>&lt;p&gt;Basics Part2&lt;/p&gt;

&lt;p&gt;Helloooo there! Welcome back!!&lt;/p&gt;

&lt;p&gt;Wait, are you new here? Don't worry, I got you covered. Here, we are breaking the flow. Have you checked "Python from the word ...Go" Basics Part1? It's an awesome resource to first check out if you are not familiar with Python's variables and data types which comprise a few in-built Python data structures.&lt;br&gt;
They are really gonna come in handy for this section.&lt;/p&gt;

&lt;p&gt;Set? Lets' go!!&lt;/p&gt;

&lt;p&gt;In the previous module, we learnt about the fundamental Python data types and also covered some of the terms used when talking about code like variables, statements, expressions, functions, methods ...etc.&lt;br&gt;
Most importantly, we covered how to perform actions on the data types (Both functions and methods for each data type).&lt;br&gt;
Up until now, we were still scratching the surface. Every time we write code, we wrote it line by line and hence our interpreter would go line by line running each code up to the last line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; #do something
&amp;gt;&amp;gt;&amp;gt; #do something
&amp;gt;&amp;gt;&amp;gt; #do something
&amp;gt;&amp;gt;&amp;gt; #do something
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are now going to incorporate the idea of running multiple lines over and over to discover the true power of programming for machines, haha!&lt;br&gt;
Hence, in this section, we gonna talk about the idea of conditions and conditional logic. We gonna discuss more on looping and loops where we can perform actions multiple times over and over.&lt;br&gt;
We are now going to break into a new world where instead of going from line by line in order, we gonna loop over till a condition is met.&lt;/p&gt;

&lt;p&gt;Conditional Logic&lt;br&gt;
We previously covered Boolean variables (True or False). When we come to conditional logic, Booleans are super important.&lt;br&gt;
Example:&lt;br&gt;
A person(a) wants to purchase a car from a company with specific conditions:&lt;/p&gt;

&lt;p&gt;The car must be new.&lt;br&gt;
The car must have a license.&lt;br&gt;
Hence for person(a) to purchase the car:&lt;/p&gt;

&lt;p&gt;is_new = True&lt;/p&gt;

&lt;p&gt;is_licensed = True&lt;/p&gt;

&lt;p&gt;In conditional logic, we use the 'if' keyword.&lt;br&gt;
"If the car is new and licensed, then person(a) can purchase it".&lt;br&gt;
Then, if any of the conditions in purchasing the car is not met, person(a) cannot purchase the car.&lt;/p&gt;

&lt;p&gt;Example2:&lt;br&gt;
Let's assume that for one to get into a specific event, the person has to be old(35 years and above). Create a program to only allow old people to the event.&lt;br&gt;
If is_old = True, "allowed to get into the event."&lt;br&gt;
For the syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_old = True
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
You are allowed to get in

&amp;gt;&amp;gt;&amp;gt; is_old = False
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
#nothing will be printed out.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Any code that comes after the colon in the condition is automatically indented hence run if the condition is True whereas any code that ain't indented after the condition is not under the condition and hence run separately.&lt;br&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;&amp;gt;&amp;gt;&amp;gt; is_old = True
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
&amp;gt;&amp;gt;&amp;gt; print("Hello there")
You are allowed to get in
Hello there

&amp;gt;&amp;gt;&amp;gt; is_old = False
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
&amp;gt;&amp;gt;&amp;gt; print("Hello there")
Hello there
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if when a condition is not met(False), we want to perform another condition?&lt;/p&gt;

&lt;p&gt;Here is an example:&lt;br&gt;
I leave my house;&lt;br&gt;
If it's cloudy, I bring an umbrella;&lt;br&gt;
otherwise, I bring sunglasses.&lt;/p&gt;

&lt;p&gt;We use the keyword 'else'.&lt;br&gt;
Using our example of letting people in for the event, we can add:&lt;br&gt;
If is_old = True, "allowed to get into the event.", otherwise if is_old = False, "not allowed to get in",&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_old = True
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed in")
You are allowed to get in

&amp;gt;&amp;gt;&amp;gt; is_old = False
&amp;gt;&amp;gt;&amp;gt; if is_old:
&amp;gt;&amp;gt;&amp;gt;   print("You are allowed to get in")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed in")
Not allowed in
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if by chance you have more than one condition?&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
I'm in a restaurant;&lt;br&gt;
If I want meat, I order steak;&lt;br&gt;
otherwise, If I want Pasta, I order spaghetti and meatballs;&lt;br&gt;
otherwise, I order salad.&lt;/p&gt;

&lt;p&gt;For such cases, we use the 'elif' keyword (else if).&lt;br&gt;
Using a different example.&lt;/p&gt;

&lt;p&gt;A person(b) wants to order chicken pizza. If there is no chicken pizza, the person(b) can order beef pizza; otherwise, if there is none, the person(b) can order rice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; chicken_pizza = True
&amp;gt;&amp;gt;&amp;gt; beef_pizza = True

&amp;gt;&amp;gt;&amp;gt; if chicken_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me chicken pizza.")
&amp;gt;&amp;gt;&amp;gt; elif beef_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me beef pizza.")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me rice.")
Serve me chicken pizza.

&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;&amp;gt;&amp;gt;&amp;gt; chicken_pizza = False
&amp;gt;&amp;gt;&amp;gt; beef_pizza = True

&amp;gt;&amp;gt;&amp;gt; if chicken_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me chicken pizza.")
&amp;gt;&amp;gt;&amp;gt; elif beef_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me beef pizza.")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me rice.")
Serve me beef pizza.

&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;&amp;gt;&amp;gt;&amp;gt; chicken_pizza = False
&amp;gt;&amp;gt;&amp;gt; beef_pizza = False

&amp;gt;&amp;gt;&amp;gt; if chicken_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me chicken pizza.")
&amp;gt;&amp;gt;&amp;gt; elif beef_pizza:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me beef pizza.")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Serve me rice.")
Serve me rice.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"For a person to be legalized to drive a car in public, one must have a national identification card and a driving license."&lt;br&gt;
These are two conditions that one must have to avoid being fined by the cops.&lt;br&gt;
To develop such a program, we must have both conditions True hence we can use the keyword 'and' to check whether both conditions are True.&lt;br&gt;
When using 'and' both conditions must be True to execute the condition, if any of them is False, the program will run the 'elif' and 'else' part.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; has_id = True
&amp;gt;&amp;gt;&amp;gt; has_license = True

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Allowed to drive

&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;&amp;gt;&amp;gt;&amp;gt; has_id = False
&amp;gt;&amp;gt;&amp;gt; has_license = True

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Not allowed to drive

&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;&amp;gt;&amp;gt;&amp;gt; has_id = True
&amp;gt;&amp;gt;&amp;gt; has_license = False

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not allowed to drive&lt;br&gt;
Python Indentation&lt;br&gt;
The interpreter in python finds meaning in the spacing hence indentation(tabs) and white spaces in python is essential.&lt;/p&gt;

&lt;p&gt;Truthy Vs Falsy&lt;br&gt;
In python, whenever there's a value, the interpreter recognizes that as True. Otherwise, when there's a zero(0) or no value, python interpreter recognizes that as False.&lt;br&gt;
These are referred to as Truthy and Falsy values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(bool('hello'))
&amp;gt;&amp;gt;&amp;gt; print(bool(5))
&amp;gt;&amp;gt;&amp;gt; print(bool(''))
&amp;gt;&amp;gt;&amp;gt; print(bool(0))
&amp;gt;&amp;gt;&amp;gt; print(bool(None))
True
True
False
False
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All values are considered "truthy" except the following; which are considered "falsy":&lt;/p&gt;

&lt;p&gt;None&lt;/p&gt;

&lt;p&gt;False&lt;/p&gt;

&lt;p&gt;0&lt;/p&gt;

&lt;p&gt;0.0&lt;/p&gt;

&lt;p&gt;0j&lt;/p&gt;

&lt;p&gt;Decimal(0)&lt;/p&gt;

&lt;p&gt;Fraction(0, 1)&lt;/p&gt;

&lt;p&gt;[] - an empty list&lt;/p&gt;

&lt;p&gt;{} - an empty dict&lt;/p&gt;

&lt;p&gt;() - an empty tuple&lt;/p&gt;

&lt;p&gt;'' - an empty str&lt;/p&gt;

&lt;p&gt;b'' - an empty bytes&lt;/p&gt;

&lt;p&gt;set() - an empty set&lt;/p&gt;

&lt;p&gt;range(0) - an empty range&lt;/p&gt;

&lt;p&gt;Objects for which:&lt;/p&gt;

&lt;p&gt;obj.&lt;strong&gt;bool&lt;/strong&gt;() returns False&lt;br&gt;
obj.&lt;strong&gt;len&lt;/strong&gt;() returns 0&lt;br&gt;
Note: A "truthy" value will satisfy the check performed by if or while statements. We use "truthy" and "falsy" to differentiate from the bool values True and False.&lt;br&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;&amp;gt;&amp;gt;&amp;gt; has_id = 'hello'
&amp;gt;&amp;gt;&amp;gt; has_license = 5

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Allowed to drive

&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;&amp;gt;&amp;gt;&amp;gt; has_id = 'hello'
&amp;gt;&amp;gt;&amp;gt; has_license = 0

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Not allowed to drive

&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;&amp;gt;&amp;gt;&amp;gt; has_id = None
&amp;gt;&amp;gt;&amp;gt; has_license = True

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Not allowed to drive

&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;&amp;gt;&amp;gt;&amp;gt; has_id = True
&amp;gt;&amp;gt;&amp;gt; has_license = ''

&amp;gt;&amp;gt;&amp;gt; if has_id and has_license:
&amp;gt;&amp;gt;&amp;gt;   print("Allowed to drive")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Not allowed to drive")
Not allowed to driv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e&lt;br&gt;
A good though not perfect example on the use of "truthy" and "falsy" application is in forms or in keying in log in credentials.&lt;/p&gt;

&lt;p&gt;Image description&lt;/p&gt;

&lt;p&gt;When a field is set to as 'a required field', the system expects the field to be "truthy" hence should not be left blank as this will lead to it being assigned "falsy".&lt;/p&gt;

&lt;p&gt;Ternary Operator (Conditional Expression)&lt;br&gt;
This is another way to do conditional logic. This works the same as 'if statements' but can in a way be referred to as a 'shortcut' so can only be used in certain conditional logic.&lt;br&gt;
In this mode, we start with the condition then incorporate the "if statement".&lt;br&gt;
"condition_if_true" if condition else "condition_if_false"&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Let's use an example to determine if a user is your friend (eg. on Facebook whether the user can message you).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; can_message = "Message allowed" if is_friend else "not allowed to message"
&amp;gt;&amp;gt;&amp;gt; print(can_message)
Message allowed

&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; can_message = "Message allowed" if is_friend else "not allowed to message"
&amp;gt;&amp;gt;&amp;gt; print(can_message)
not allowed to message

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

&lt;/div&gt;



&lt;p&gt;Short Circuiting&lt;br&gt;
Previously we saw how to use the 'and' keyword to validate whether both statements are True:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; is_user = True
&amp;gt;&amp;gt;&amp;gt; print(is_friend and is_user)
True

&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; is_user = False
&amp;gt;&amp;gt;&amp;gt; print(is_friend and is_user)
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In short circuiting, the interpreter ignores one part of the condition(despite it being false) and returns either True or False.&lt;br&gt;
Example, using the 'or' keyword, if the first part of the condition is True the interpreter returns True without checking the second part.&lt;br&gt;
When we use the 'and' keyword, when the the first part of the statement is False, the interpreter ignores(short circuits) the second part and returns False.&lt;br&gt;
An example using the 'or' keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; is_user = False
&amp;gt;&amp;gt;&amp;gt; print(is_friend or is_user)
True

&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; is_user = True
&amp;gt;&amp;gt;&amp;gt; print(is_friend or is_user)
True

&amp;gt;&amp;gt;&amp;gt; is_friend = False
&amp;gt;&amp;gt;&amp;gt; is_user = True
&amp;gt;&amp;gt;&amp;gt; if is_friend or is_user:
&amp;gt;&amp;gt;&amp;gt;   print("Best friends forever")
Best friends forever

&amp;gt;&amp;gt;&amp;gt; is_friend = False
&amp;gt;&amp;gt;&amp;gt; is_user = True
&amp;gt;&amp;gt;&amp;gt; if False or is_user:
&amp;gt;&amp;gt;&amp;gt;   print("Best friends forever")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Never friends")
Best friends forever

&amp;gt;&amp;gt;&amp;gt; is_friend = True
&amp;gt;&amp;gt;&amp;gt; is_user = False
&amp;gt;&amp;gt;&amp;gt; if False or is_user:
&amp;gt;&amp;gt;&amp;gt;   print("Best friends forever")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Never friends")
Never friends

&amp;gt;&amp;gt;&amp;gt; if True or True:
&amp;gt;&amp;gt;&amp;gt;   print("Best friends forever")
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;   print("Never friends")
Best friends forever
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Logical Operators&lt;br&gt;
We have looked at a few logical operators previously 'and' and 'or'. A logical operator allows us to perform logic between two things.&lt;br&gt;
Other logical operators include:&lt;/p&gt;

&lt;p&gt;Greater than &amp;gt;&lt;/p&gt;

&lt;p&gt;Less than &amp;lt;&lt;/p&gt;

&lt;p&gt;Equal to ==&lt;/p&gt;

&lt;p&gt;Greater than or equal to &amp;gt;=&lt;/p&gt;

&lt;p&gt;Less than or equal to &amp;lt;=&lt;/p&gt;

&lt;p&gt;Not equal to != (Opposite of equal to)&lt;/p&gt;

&lt;p&gt;not keyword / Function - It negates the statement. Can also be written with bracket: not().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
They return either True or False:
&amp;gt;&amp;gt;&amp;gt; print(4 &amp;gt; 5)
False

&amp;gt;&amp;gt;&amp;gt; print(4 &amp;lt; 5)
True

&amp;gt;&amp;gt;&amp;gt; print(4 == 5)
False

&amp;gt;&amp;gt;&amp;gt; print(1 &amp;gt;= 0)
True

&amp;gt;&amp;gt;&amp;gt; print(1 &amp;lt;= 0)
False

&amp;gt;&amp;gt;&amp;gt; print(0 &amp;gt;= 0)
True

&amp;gt;&amp;gt;&amp;gt; print(0 != 0)
False

&amp;gt;&amp;gt;&amp;gt; print(not(True))
False

&amp;gt;&amp;gt;&amp;gt; print(not True)
False

&amp;gt;&amp;gt;&amp;gt; print(not False)
True

&amp;gt;&amp;gt;&amp;gt; print(not(1 == 1))
False

&amp;gt;&amp;gt;&amp;gt; print(not(1 != 1))
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: A single equal sign = symbol is used in assigning values to variables hence to use the "equal to" operator for comparison, we use a double == symbol.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print('a' &amp;gt; 'b')
False

&amp;gt;&amp;gt;&amp;gt; print('a' &amp;gt; 'A')
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But why/how is 'a' &amp;gt; 'b' False; and 'a' &amp;gt; 'A' True?&lt;/p&gt;

&lt;p&gt;In the case of strings, Python compares the ASCII values of the characters. Hence, 'a' ASCII value is 97, 'b' is 98 and 'A' ASCII value is 65 that's why 'a' is greater than 'A' and 'b' is greater than 'a'.&lt;/p&gt;

&lt;p&gt;*optional&lt;br&gt;
In the case of, print('abc' &amp;lt; 'bac'), the result will be True. (Though this is a bit beyond the scope of the course).&lt;br&gt;
This kind of comparison uses lexicographical ordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted.&lt;/p&gt;

&lt;p&gt;Lexicographical ordering for strings uses the Unicode code point number to order individual characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(1 &amp;lt; 2 &amp;lt; 3 &amp;lt; 4)
True

&amp;gt;&amp;gt;&amp;gt; print(1 &amp;lt; 2 &amp;gt; 3 &amp;lt; 4)
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exercise1 (Done below)&lt;br&gt;
You have been hired by a gaming company to create a program for a game where the character has magic powers and is an expert.&lt;br&gt;
If the character has magic and is an expert, the output should be "You are a master magician". Otherwise, if the character has magic but is not an expert, the output should be "At least you're getting there". Else, if the character has no magic, the output should be "You need magic powers".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print("Enter '1'(Yes) or '0'(No) for each question.")
&amp;gt;&amp;gt;&amp;gt; has_magic = bool(int(input("Does the character has magic? ")))
&amp;gt;&amp;gt;&amp;gt; is_expert = bool(int(input("Is the character an expert? ")))

&amp;gt;&amp;gt;&amp;gt; if has_magic and is_expert:
&amp;gt;&amp;gt;&amp;gt;   print("You are a master magician.")
&amp;gt;&amp;gt;&amp;gt; elif has_magic and not is_expert:
&amp;gt;&amp;gt;&amp;gt;   print("At least you're getting there.")
&amp;gt;&amp;gt;&amp;gt; elif not has_magic:
&amp;gt;&amp;gt;&amp;gt;  print("You need magic powers.")
Enter '1'(Yes) or '0'(No) for each question.
Does the character has magic? _1_
Is the character an expert? _1_
You are a master magician.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Re-run the program)&lt;br&gt;
Enter '1'(Yes) or '0'(No) for each question.&lt;br&gt;
Does the character has magic? &lt;em&gt;0&lt;/em&gt;&lt;br&gt;
Is the character an expert? &lt;em&gt;1&lt;/em&gt;&lt;br&gt;
You need magic powers.&lt;/p&gt;

&lt;p&gt;(Re-run the program)&lt;br&gt;
Enter '1'(Yes) or '0'(No) for each question.&lt;br&gt;
Does the character has magic? &lt;em&gt;1&lt;/em&gt;&lt;br&gt;
Is the character an expert? &lt;em&gt;0&lt;/em&gt;&lt;br&gt;
At least you're getting there.&lt;br&gt;
'is' keyword&lt;br&gt;
Unlike the double equal sign ==, which compares the equality in values, is is a keyword that checks if the location in memory where one value is stored is the same as the other's.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
&amp;gt;&amp;gt;&amp;gt; print(True == 1)
&amp;gt;&amp;gt;&amp;gt; print('' == 1)
&amp;gt;&amp;gt;&amp;gt; print('1' == 1)
&amp;gt;&amp;gt;&amp;gt; print([] == 0)
&amp;gt;&amp;gt;&amp;gt; print(10 == 10.0)
&amp;gt;&amp;gt;&amp;gt; print([] == [])
&amp;gt;&amp;gt;&amp;gt; print([1, 2, 3] == [1, 2, 3])
True
False
False
False
True
True
True

&amp;gt;&amp;gt;&amp;gt; print(True is 1)
&amp;gt;&amp;gt;&amp;gt; print('' is 1)
&amp;gt;&amp;gt;&amp;gt; print('1' is 1)
&amp;gt;&amp;gt;&amp;gt; print([] is 0)
&amp;gt;&amp;gt;&amp;gt; print(10 is 10.0)
&amp;gt;&amp;gt;&amp;gt; print([] is [])
&amp;gt;&amp;gt;&amp;gt; print([1, 2, 3] is [1, 2, 3])
False
False
False
False
False
False
False

&amp;gt;&amp;gt;&amp;gt; print(True is True)
True

&amp;gt;&amp;gt;&amp;gt; print('1' is '1')
True

&amp;gt;&amp;gt;&amp;gt; print(10 is 10)
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once a list is created, it is stored in different memory space hence print([] is []) or print([1, 2, 3] is [1, 2, 3]) will always evaluate to False.&lt;/p&gt;

&lt;p&gt;All Data Structures in Python are stored in different memory locations.&lt;/p&gt;

&lt;p&gt;For Loops&lt;br&gt;
Loops are one of the most powerful features of a programming languages. The concept of looping allows us to run lines of code over and over till we accomplish a specific task.&lt;br&gt;
In creating a for loop, we use the keyword 'for'.&lt;br&gt;
Example: for i in 'name':&lt;br&gt;
'i' in the loop is a variable for each element in the loop and can be any different name: for item in 'name':, for teddy in 'name': and is created for each item in 'name'(iterable).&lt;br&gt;
An iterable is something that can be looped over.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; for item in 'name':
&amp;gt;&amp;gt;&amp;gt;    print(item)
n
a
m
e

&amp;gt;&amp;gt;&amp;gt; for item in [1, 2, 3, 4]:
&amp;gt;&amp;gt;&amp;gt;    print(item)
1
2
3
4

&amp;gt;&amp;gt;&amp;gt; name = 'Mark'
&amp;gt;&amp;gt;&amp;gt; for i in name:
&amp;gt;&amp;gt;&amp;gt;    print(i)
M
a
r
k

&amp;gt;&amp;gt;&amp;gt; for item in {1, 2, 3, 4}:
&amp;gt;&amp;gt;&amp;gt;    print(item)
1
2
3
4

&amp;gt;&amp;gt;&amp;gt; for item in (1, 2, 3, 4):
&amp;gt;&amp;gt;&amp;gt;    print(item)
1
2
3
4

&amp;gt;&amp;gt;&amp;gt; for item in (1, 2, 3, 4):
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt; print("Hello")

1
1
1
2
2
2
3
3
3
4
4
4
Hello

&amp;gt;&amp;gt;&amp;gt; for item in (1, 2, 3, 4):
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt;    print(item)
&amp;gt;&amp;gt;&amp;gt; print(item)
1
1
1
2
2
2
3
3
3
4
4
4
4
Nested for loops
&amp;gt;&amp;gt;&amp;gt; for item in (1, 2, 3, 4, 5):
&amp;gt;&amp;gt;&amp;gt;     for x in ['a', 'b', 'c']:
&amp;gt;&amp;gt;&amp;gt;         print(item, x)
1 a
1 b
1 c
2 a
2 b
2 c
3 a
3 b
3 c
4 a
4 b
4 c
5 a
5 b
5 c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Iterables&lt;br&gt;
An iterable is an object or a collection that can be iterated over (looped over).&lt;br&gt;
An iterable can be a list, tuple, dictionary, set and string. This means that one can go one by one checking each item in the collection.&lt;/p&gt;

&lt;p&gt;Iterating over a dictionary&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for item in user:
&amp;gt;&amp;gt;&amp;gt;     print(item)
name
age
can_swim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we iterate over a dictionary we only get the keys but can use the dictionary methods to loop over the dictionary items which includes its values.&lt;/p&gt;

&lt;p&gt;One is 'x.items()' where we get the key-value pairs in tuples form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for item in user.items():
&amp;gt;&amp;gt;&amp;gt;     print(item)
('name', 'Mark')
('age', 30)
('can_swim', False)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second is 'x.values()' where we get only the values in the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dictionary.
&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for item in user.values():
&amp;gt;&amp;gt;&amp;gt;     print(item)
Mark
30
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Third is 'x.keys()' where we get only the keys in the dictionary. Works the same as iterating the dictionary without including a method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for item in user.keys():
&amp;gt;&amp;gt;&amp;gt;     print(item)
name
age
can_swim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if you want to print the items (key and values) in the dictionary separately? We can use tuple unpacking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for item in user.items():
&amp;gt;&amp;gt;&amp;gt;     key, value = item
&amp;gt;&amp;gt;&amp;gt;     print(key, value)
name Mark
age 30
can_swim False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(second way of unpacking)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;gt;&amp;gt;&amp;gt; user = {
&amp;gt;&amp;gt;&amp;gt;     'name' : 'Mark',
&amp;gt;&amp;gt;&amp;gt;     'age' : 30,
&amp;gt;&amp;gt;&amp;gt;     'can_swim' : False
&amp;gt;&amp;gt;&amp;gt;   }

&amp;gt;&amp;gt;&amp;gt; for key, value in user.items():
&amp;gt;&amp;gt;&amp;gt;     print(key, value)
name Mark
age 30
can_swim False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exercise2 (Done below)&lt;br&gt;
Building a simple 'counter' to loop over a list and sum up the items in the list. The list is provided below.&lt;br&gt;
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
&amp;gt;&amp;gt;&amp;gt; sum = 0
&amp;gt;&amp;gt;&amp;gt; for i in my_list:
&amp;gt;&amp;gt;&amp;gt;     sum += i
&amp;gt;&amp;gt;&amp;gt; print (sum)
55
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;range() in loops&lt;br&gt;
It returns an object that produces a sequence of integers from the start (which is inclusive) to stop (exclusive).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(range(100))
range(0, 100)

&amp;gt;&amp;gt;&amp;gt; print(range(0, 100))
range(0, 100)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can iterate a range of numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; for num in range(20)
&amp;gt;&amp;gt;&amp;gt;    print(num)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

&amp;gt;&amp;gt;&amp;gt; for i in range(2, 15)
&amp;gt;&amp;gt;&amp;gt;    print(i)
2
3
4
5
6
7
8
9
10
11
12
13
14

&amp;gt;&amp;gt;&amp;gt; for i in range(10):
&amp;gt;&amp;gt;&amp;gt;    print('my name is')
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When one 'does not want to use' a variable name in the loop, the person can use an underscore _:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; for _ in range(20)
&amp;gt;&amp;gt;&amp;gt;    print(_)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

&amp;gt;&amp;gt;&amp;gt; for _ in range(10):
&amp;gt;&amp;gt;&amp;gt;    print('my name is')
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
my name is
(start: stop: stepover) in range()
&amp;gt;&amp;gt;&amp;gt; for _ in range(0, 10, 2)
&amp;gt;&amp;gt;&amp;gt;    print(_)
0
2
4
6
8

&amp;gt;&amp;gt;&amp;gt; for _ in range(0, 10, -1)
&amp;gt;&amp;gt;&amp;gt;    print(_)
#nothing will be printed out

&amp;gt;&amp;gt;&amp;gt; for _ in range(10, 0, -1)
&amp;gt;&amp;gt;&amp;gt;    print(_)
10
9
8
7
6
5
4
3
2
1

&amp;gt;&amp;gt;&amp;gt; for _ in range(10, 0, -2)
&amp;gt;&amp;gt;&amp;gt;    print(_)
10
8
6
4
2

&amp;gt;&amp;gt;&amp;gt; for _ in range(2)
&amp;gt;&amp;gt;&amp;gt;    print(list(range(10)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;enumerate()&lt;br&gt;
It returns each item in the iterable with its index in tuple form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; for i in enumerate('mark'):
&amp;gt;&amp;gt;&amp;gt;    print(i)
(0, 'm')
(1, 'a')
(2, 'r')
(3, 'k')

&amp;gt;&amp;gt;&amp;gt; for i, j in enumerate('mark'):
&amp;gt;&amp;gt;&amp;gt;    print(i, j)
0 m
1 a
2 r
3 k

&amp;gt;&amp;gt;&amp;gt; for i, char in enumerate(list(range(100))):
&amp;gt;&amp;gt;&amp;gt;     if char == 50:
&amp;gt;&amp;gt;&amp;gt;         print(f"The index of 50 is: {i}")
The index of 50 is: 50

&amp;gt;&amp;gt;&amp;gt; for i, j in enumerate('Mark'):
&amp;gt;&amp;gt;&amp;gt;     if j == 'r':
&amp;gt;&amp;gt;&amp;gt;         print(f"The index of r is: {i}")
The index of r is: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While Loops&lt;br&gt;
In While loop, a command is run when a specific condition is met till the condition becomes false after constant looping.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eg:
&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while 0 &amp;lt; 50:
&amp;gt;&amp;gt;&amp;gt;     print(i)
0
0
0
0
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  will run infinitely for 0 will always be less than 50.
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; 50:
&amp;gt;&amp;gt;&amp;gt;     i += 5
&amp;gt;&amp;gt;&amp;gt;     print(i)
5
10
15
20
25
30
35
40
45
50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;break command in while loop&lt;br&gt;
When a break keyword is used in while loop, it breaks the loop after the first run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while 0 &amp;lt; 50:
&amp;gt;&amp;gt;&amp;gt;     print(i)
&amp;gt;&amp;gt;&amp;gt;     break
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using else in while loop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; 50:
&amp;gt;&amp;gt;&amp;gt;     i += 5
&amp;gt;&amp;gt;&amp;gt;     print(i)
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;     print("Done with work")
5
10
15
20
25
30
35
40
45
50
Done with work

&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;gt; 50:
&amp;gt;&amp;gt;&amp;gt;     i += 5
&amp;gt;&amp;gt;&amp;gt;     print(i)
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;     print("Done with work")
Done with work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The else block in while loop will only execute when there is no break statement in the while loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; 50:
&amp;gt;&amp;gt;&amp;gt;     i += 5
&amp;gt;&amp;gt;&amp;gt;     print(i)
&amp;gt;&amp;gt;&amp;gt;     break
&amp;gt;&amp;gt;&amp;gt; else:
&amp;gt;&amp;gt;&amp;gt;     print("Done with work")
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How for loops and while loops relates&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; for item in my_list:
&amp;gt;&amp;gt;&amp;gt;     print(item)
1
2
3
&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;------------------------------------
&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; len(my_list):
&amp;gt;&amp;gt;&amp;gt;     print(my_list[i])
&amp;gt;&amp;gt;&amp;gt;     i += 1 
1
2
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While loops are more flexible for we have a conditional statement but for loops are simpler. With the while loop, we have to remember to hope the loop in the course or use a break statement, to avoid getting an infinite loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; while True:
&amp;gt;&amp;gt;&amp;gt;     input("Say something: ")
&amp;gt;&amp;gt;&amp;gt;     break
Say something: _hi_

&amp;gt;&amp;gt;&amp;gt; while True:
&amp;gt;&amp;gt;&amp;gt;     response = input("Say something: ")
&amp;gt;&amp;gt;&amp;gt;     if (response == "bye"):
&amp;gt;&amp;gt;&amp;gt;         break
Say something: _hi_
Say something: _hi_
Say something: _bye_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;break, continue, pass&lt;br&gt;
The break keyword breaks out of the loop. The continue keyword continues the loop till the condition is met without running the indented line(s) below it. The pass keyword is used to pass to the next line. It is mainly used as a placeholder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; for item in my_list:
&amp;gt;&amp;gt;&amp;gt;    continue
&amp;gt;&amp;gt;&amp;gt;    print(item)
#nothing will be printed

&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; len(my_list):
&amp;gt;&amp;gt;&amp;gt;    i += 1
&amp;gt;&amp;gt;&amp;gt;    continue
&amp;gt;&amp;gt;&amp;gt;    print(my_list[i])
#nothing will be printed

&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; for item in my_list:
&amp;gt;&amp;gt;&amp;gt;    pass

&amp;gt;&amp;gt;&amp;gt; i = 0
&amp;gt;&amp;gt;&amp;gt; while i &amp;lt; len(my_list):
&amp;gt;&amp;gt;&amp;gt;    print(my_list[i])
&amp;gt;&amp;gt;&amp;gt;    i += 1
&amp;gt;&amp;gt;&amp;gt;    pass
1
2
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functions&lt;br&gt;
Up until now, we've worked with python functions like print, list, input function and many more that allowed us to perform actions on our data types.&lt;br&gt;
We can also create our own functions and use them on our program.&lt;br&gt;
When creating functions in Python we use the def - 'define' keyword. We then give our function a name (defining the function) as we do with variables then we add the brackets () and a colon at the end.&lt;br&gt;
For one to use a function one has to 'call it'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(): #defining the function
&amp;gt;&amp;gt;&amp;gt;    print("Hellooo")
&amp;gt;&amp;gt;&amp;gt; say_hello() #calling the function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hellooo&lt;br&gt;
Functions are super useful because the work under the principle of 'DRY - Don't Repeat Yourself' because instead of the programmer re-typing the code each and every time, the programmer can just call the function as many times as possible to run a specific block of code.&lt;/p&gt;

&lt;p&gt;Example: Using our Christmas tree example above, we can use the function to output it multiple of times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; picture = [
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0]
    ]

&amp;gt;&amp;gt;&amp;gt; def show_tree():
&amp;gt;&amp;gt;&amp;gt;    for row in picture:
&amp;gt;&amp;gt;&amp;gt;        for pixel in row:
&amp;gt;&amp;gt;&amp;gt;            if pixel == 0:
&amp;gt;&amp;gt;&amp;gt;                print(" ", end = ' ')
&amp;gt;&amp;gt;&amp;gt;            else:
&amp;gt;&amp;gt;&amp;gt;                print("*", end = ' ')
&amp;gt;&amp;gt;&amp;gt;        print(" ")

&amp;gt;&amp;gt;&amp;gt; show_tree()
&amp;gt;&amp;gt;&amp;gt; show_tree()
&amp;gt;&amp;gt;&amp;gt; show_tree()

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

&lt;/div&gt;



&lt;p&gt;The function is stored in a specific place in memory once created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(): 
&amp;gt;&amp;gt;&amp;gt;    print("Hellooo")
&amp;gt;&amp;gt;&amp;gt; print(say_hello)
&amp;lt;function say_hello at 0x000002332BB33E20&amp;gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  The characters '0x000002332BB33E20' show the memory location where the function has been stored.
&lt;/h1&gt;

&lt;p&gt;Arguments Vs Parameters(in functions)&lt;br&gt;
The power of functions beyond it being able to be called multiple times, is the ability of the programmer to make it dynamic. In its brackets, one can pass parameters.&lt;br&gt;
The values which are defined at the time of the function prototype or definition of the function are called as parameters.&lt;br&gt;
When a function is 'called', the actual values that are passed during the 'call' are called as arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(name, age): #name and age are parameters.
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello("Abdikhafar", 20) #"Mark" and 20 are arguments.
Hello Abdikhafar, You're 20 yrs

&amp;gt;&amp;gt;&amp;gt; def say_hello(name, age):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello("Mark", 20)
&amp;gt;&amp;gt;&amp;gt; say_hello("Emily", 19)
&amp;gt;&amp;gt;&amp;gt; say_hello("Dan", 17)
Hello Mark, You're 20 yrs
Hello Emily, You're 19 yrs
Hello Dan, You're 17 yrs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above arguments are referred to as positional arguments because they are required to be in the proper position.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(name, age):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello(20, "Abdikhafar")
Hello 20, You're Abdikhafar yrs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Default Parameters and Keyword Arguments&lt;br&gt;
Keyword arguments, as opposed to positional arguments, allow us to not worry about the position hence the arguments can be in any position.&lt;br&gt;
However this makes the code more complicated and not a proper practice way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(name, age):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello(age = 20, name = "Abdikhafar")
Hello Abdikhafar, You're 20 yrs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Default parameters allow us to give constant values as we define the function. Default parameters only work when no values have been passed as arguments to the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def say_hello(name = "Emily", age = 17):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello()
Hello Emily, You're 17 yrs
&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;&amp;gt;&amp;gt;&amp;gt; def say_hello(name = "Emily", age = 17):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello("Dan", 23)
&amp;gt;&amp;gt;&amp;gt; say_hello()
Hello Dan, You're 23 yrs
Hello Emily, You're 17 yrs

&amp;gt;&amp;gt;&amp;gt; def say_hello(name = "Emily", age = 17):
&amp;gt;&amp;gt;&amp;gt;    print(f"Hello {name}, You're {age} yrs")
&amp;gt;&amp;gt;&amp;gt; say_hello("Irene")
Hello Irene, You're 17 yrs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return Statement&lt;br&gt;
This is a keyword in python mostly used together with functions.&lt;br&gt;
Functions always have to return something and when there is no return statement, the function will always return None.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    num1 + num2
&amp;gt;&amp;gt;&amp;gt; print(sum(4, 5))
None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the return statement is used;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    return num1 + num2
&amp;gt;&amp;gt;&amp;gt; print(sum(4, 5))
9

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

&lt;/div&gt;



&lt;p&gt;A function should do one thing really well and/or should return something. This however doesn't mean that the code only has to be one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    return num1 + num2
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 5)
&amp;gt;&amp;gt;&amp;gt; print(sum(10, total))
25

&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    return num1 + num2
&amp;gt;&amp;gt;&amp;gt; print(sum(10, sum(10, 5)))
25

&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    def another_func(num1, num2):
&amp;gt;&amp;gt;&amp;gt;       return num1 + num2
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 20)
&amp;gt;&amp;gt;&amp;gt; print(total)
None

def sum(num1, num2):
   def another_func(num1, num2):
      return num1 + num2
   return another_func
total = sum(10, 20)
print(total)
&amp;lt;function sum.&amp;lt;locals&amp;gt;.another_func at 0x000002387BF49B40&amp;gt;

&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    def another_func(num1, num2):
&amp;gt;&amp;gt;&amp;gt;       return num1 + num2
&amp;gt;&amp;gt;&amp;gt;    return another_func
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 20)
&amp;gt;&amp;gt;&amp;gt; print(total(10, 20))
30

&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    def another_func(num1, num2):
&amp;gt;&amp;gt;&amp;gt;       return num1 + num2
&amp;gt;&amp;gt;&amp;gt;    return another_func(num1, num2)
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 20)
&amp;gt;&amp;gt;&amp;gt; print(total)
30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To avoid confusion when working with more than one function (function in a function), it is advisable to use different names for the parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    def another_func(n1, n2):
&amp;gt;&amp;gt;&amp;gt;       return num1 + num2
&amp;gt;&amp;gt;&amp;gt;    return another_func(num1, num2)
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 20)
&amp;gt;&amp;gt;&amp;gt; print(total)
30
Note: A return keyword automatically exits the function in that any code (to output) below the return statement is never run.
&amp;gt;&amp;gt;&amp;gt; def sum(num1, num2):
&amp;gt;&amp;gt;&amp;gt;    def another_func(n1, n2):
&amp;gt;&amp;gt;&amp;gt;       return num1 + num2
&amp;gt;&amp;gt;&amp;gt;    return another_func(num1, num2)
&amp;gt;&amp;gt;&amp;gt;    return 5
&amp;gt;&amp;gt;&amp;gt;    print("Hello")
&amp;gt;&amp;gt;&amp;gt; total = sum(10, 20)
&amp;gt;&amp;gt;&amp;gt; print(total)
30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Methods Vs Functions&lt;br&gt;
Examples of inbuilt functions in python include : list(), print(), max(), min(), input(). We've also found out that we can use the keyword def to define our own functions.&lt;/p&gt;

&lt;p&gt;When using methods, we use the dot(.) notation. Methods are owned by 'whatever is to the left of the dot(.)' be it strings, tuples, integers etc. Methods of the fundamental data types have been covered in the previous module where all the data types have been covered too.&lt;br&gt;
Both Functions and Methods allow us to take actions on the data types.&lt;br&gt;
None: Similar to functions, we can also build our own methods which will be explained in details in the next module as we discuss on 'classes and objects'.&lt;/p&gt;

&lt;p&gt;Docstrings&lt;br&gt;
This is using triple quotes ('''...''') to 'comment' multiple lines. It can also be used in functions to give more info about a function.&lt;/p&gt;

&lt;p&gt;Image description&lt;/p&gt;

&lt;p&gt;It works the same as the more info about a function provided by the developer environments when typing the inbuilt functions.&lt;/p&gt;

&lt;p&gt;Image description&lt;/p&gt;

&lt;p&gt;Help function&lt;br&gt;
Used to give more info about a function. When a docstring is passed in a function, the help function returns the docstring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; help(print)

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
&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;Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
&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;&amp;gt;&amp;gt;&amp;gt; def test(a):
       '''
       Info: This is a function that prints the testing data.
       '''
       print(a)
&amp;gt;&amp;gt;&amp;gt; help(test)
test(a)
&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;Info: This is a function that prints the testing data.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can also use the dunder method (Magic method) 'will get into it later in the course' to get more info on a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def test(a):
       '''
       Info: This is a function that prints the testing data.
       '''
       print(a)
&amp;gt;&amp;gt;&amp;gt;print(test.__doc___)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Info: This is a function that prints the testing data.&lt;br&gt;
Docstrings are really useful to add comments and definition to a function to enable other people understand what your function does without searching through your multiple files.&lt;/p&gt;

&lt;p&gt;Writing clean code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def is_even(num):
&amp;gt;&amp;gt;&amp;gt;    if num % 2 == 0:
&amp;gt;&amp;gt;&amp;gt;      return True
&amp;gt;&amp;gt;&amp;gt;    elif num % 2 != 0:
&amp;gt;&amp;gt;&amp;gt;      return False
&amp;gt;&amp;gt;&amp;gt; print(is_even(50))
True
Vs
&amp;gt;&amp;gt;&amp;gt; def is_even(num):
&amp;gt;&amp;gt;&amp;gt;    if num % 2 == 0:
&amp;gt;&amp;gt;&amp;gt;      return True
&amp;gt;&amp;gt;&amp;gt;    else:
&amp;gt;&amp;gt;&amp;gt;      return False
&amp;gt;&amp;gt;&amp;gt; print(is_even(50))
True
Vs
&amp;gt;&amp;gt;&amp;gt; def is_even(num):
&amp;gt;&amp;gt;&amp;gt;    if num % 2 == 0:
&amp;gt;&amp;gt;&amp;gt;      return True
&amp;gt;&amp;gt;&amp;gt;    return False
&amp;gt;&amp;gt;&amp;gt; print(is_even(50))
True
Vs
&amp;gt;&amp;gt;&amp;gt; def is_even(num):
&amp;gt;&amp;gt;&amp;gt;    return num % 2 == 0
&amp;gt;&amp;gt;&amp;gt; print(is_even(50))
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*args and **kwargs&lt;br&gt;
*args - arguments&lt;br&gt;
**kwargs - Keyword arguments&lt;/p&gt;

&lt;p&gt;In function we have special characters called *args and **kwargs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def super_func(num):
&amp;gt;&amp;gt;&amp;gt;    return sum(num)
&amp;gt;&amp;gt;&amp;gt; super_func(1, 2, 3, 4, 5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  returns an error because the function should take just 1 positional argument but we gave 5.
&lt;/h1&gt;

&lt;p&gt;_args (adding an asterisk at the start of the parameter) allows one to pass more than one positional argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def super_func(*num):
&amp;gt;&amp;gt;&amp;gt;    print(*num)
&amp;gt;&amp;gt;&amp;gt;    return sum(num)
&amp;gt;&amp;gt;&amp;gt; super_func(1, 2, 3, 4, 5)
1 2 3 4 5

&amp;gt;&amp;gt;&amp;gt; def super_func(*num):
&amp;gt;&amp;gt;&amp;gt;    print(num)
&amp;gt;&amp;gt;&amp;gt;    return sum(num)
&amp;gt;&amp;gt;&amp;gt; super_func(1, 2, 3, 4, 5)
(1 2 3 4 5)

&amp;gt;&amp;gt;&amp;gt; def super_func(*num):
&amp;gt;&amp;gt;&amp;gt;    return sum(num)
&amp;gt;&amp;gt;&amp;gt; print(super_func(1, 2, 3, 4, 5))
15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;__kwargs allows us to use keyword arguments. It returns a dictionary of the values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def super_func(*num, **kwargs):
&amp;gt;&amp;gt;&amp;gt;    print(kwargs)
&amp;gt;&amp;gt;&amp;gt; super_func(1, 2, 3, 4, 5, num1=10, num2=15)
{'num1': 10, 'num2': 15}

&amp;gt;&amp;gt;&amp;gt; def super_func(*num, **kwargs):
&amp;gt;&amp;gt;&amp;gt;    print(kwargs)
&amp;gt;&amp;gt;&amp;gt;    total = 0
&amp;gt;&amp;gt;&amp;gt;     for items in kwargs.values():
&amp;gt;&amp;gt;&amp;gt;        total += items
&amp;gt;&amp;gt;&amp;gt;     return sum(num) + total
&amp;gt;&amp;gt;&amp;gt; print(super_func(1, 2, 3, 4, 5, num1=10, num2=15))
{'num1': 10, 'num2': 15}
40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's a rule of positioning when one is using parameters, default parameters, *args and **kwargs:&lt;/p&gt;

&lt;p&gt;parameters, *args, default parameters, **kwargs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; def super_func(name, *num, greet="hi", **kwargs):
&amp;gt;&amp;gt;&amp;gt;    print(kwargs)
&amp;gt;&amp;gt;&amp;gt;    total = 0
&amp;gt;&amp;gt;&amp;gt;     for items in kwargs.values():
&amp;gt;&amp;gt;&amp;gt;        total += items
&amp;gt;&amp;gt;&amp;gt;     return sum(num) + total
&amp;gt;&amp;gt;&amp;gt; print(super_func("Andy", 1, 2, 3, 4, 5, num1=10, num2=15))
{'num1': 10, 'num2': 15}
40
&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;
&amp;gt;&amp;gt;&amp;gt; my_list = [10, 2, 3, 4, 8, 11]
&amp;gt;&amp;gt;&amp;gt; even_list = []
&amp;gt;&amp;gt;&amp;gt; def highest_even():
&amp;gt;&amp;gt;&amp;gt;    for i in my_list:
&amp;gt;&amp;gt;&amp;gt;       if i % 2 == 0:
&amp;gt;&amp;gt;&amp;gt;          even_list.append(i)
&amp;gt;&amp;gt;&amp;gt;          even_list.sort()
&amp;gt;&amp;gt;&amp;gt;    print(even_list[-1])
&amp;gt;&amp;gt;&amp;gt; highest_even()
10
We can also use the max keyword to return the maximum even number:
&amp;gt;&amp;gt;&amp;gt; my_list = [10, 2, 3, 4, 8, 11]
&amp;gt;&amp;gt;&amp;gt; def highest_even():
&amp;gt;&amp;gt;&amp;gt;    even_list = []
&amp;gt;&amp;gt;&amp;gt;    for i in my_list:
&amp;gt;&amp;gt;&amp;gt;       if i % 2 == 0:
&amp;gt;&amp;gt;&amp;gt;          even_list.append(i)
&amp;gt;&amp;gt;&amp;gt;    return max(even_list)
&amp;gt;&amp;gt;&amp;gt; print(highest_even())
10

Scope
"What variables do I have access to?"
&amp;gt;&amp;gt;&amp;gt; print(name)
#returns an error; NameError: name 'name' is not defined
Once a variable is not defined, one cannot have access to it.
A variable with a global scope is a variable that can be accessed by anybody in the file and can be used anywhere; in the conditional logic; in the while loop; in a function, etc.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 100&lt;br&gt;
print(total)&lt;br&gt;
10&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

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

#total has a global scope
A variable with a functional scope is a variable that can only be accessed in within the function.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;def some_func():&lt;br&gt;
   total = 100&lt;br&gt;
print(total)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#returns an error; NameError: name 'total' is not defined

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;def some_func():&lt;br&gt;
   total = 100&lt;br&gt;
   print(total)&lt;br&gt;
100&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scope Rules
"What would you expect the output of the code below to be?"

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def confusion():&lt;br&gt;
  a = 5&lt;br&gt;
  return a&lt;br&gt;
print(a)&lt;br&gt;
print(confusion())&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The output will be 1 and 5. This is because the first print function, print(a), outputs the value stored in the a with the global scope while the second print function, print(confusion()), returns the value stored in the a variable in the function.
The a is not modified after the function because of scope.

Rules the interpreter follow in scope:

1. Local Scope - Scope within the functional scope.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def confusion():&lt;br&gt;
  a = 5&lt;br&gt;
  return a&lt;br&gt;
print(confusion())&lt;br&gt;
print(a)&lt;br&gt;
5&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def confusion():&lt;br&gt;
  return a&lt;br&gt;
print(confusion())&lt;br&gt;
print(a)&lt;br&gt;
1&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2. Parent Local scope - Works where there's a function within a function.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def parent():&lt;br&gt;
  a = 10&lt;br&gt;
  def confusion():&lt;br&gt;
     return a&lt;br&gt;
  return confusion()&lt;br&gt;
print(parent())&lt;br&gt;
print(a)&lt;br&gt;
10&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3. Global scope

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def parent():&lt;br&gt;
  def confusion():&lt;br&gt;
     return a&lt;br&gt;
  return confusion()&lt;br&gt;
print(parent())&lt;br&gt;
print(a)&lt;br&gt;
1&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4. Built in python functions

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;a = 1&lt;br&gt;
def parent():&lt;br&gt;
  def confusion():&lt;br&gt;
     return sum&lt;br&gt;
  return confusion()&lt;br&gt;
print(parent())&lt;br&gt;
print(a)&lt;br&gt;
&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Note: Parameters are part of the local scope:

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;b = 10&lt;br&gt;
def confusion(b):&lt;br&gt;
   print(b)&lt;br&gt;
confusion(300)&lt;br&gt;
300&lt;/p&gt;

&lt;p&gt;b = 10&lt;br&gt;
def confusion(b):&lt;br&gt;
   print(b)&lt;br&gt;
confusion(b)&lt;br&gt;
10&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Global keyword
"What if one wants to refer to a global variable while in the function without creating a new variable?"
Example:

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 0&lt;br&gt;
def count():&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
print(count())&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#returns an error; UnboundLocalError: local variable 'total' referenced before assignment
The error occurs because the function count does not recognize total. Hence, we have to add a variable total in the function:

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 0&lt;br&gt;
def count():&lt;br&gt;
   total = 0&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
print(count())&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To avoid recreating another variable in the function we can use the global keyword to tell the interpreter that we want to use the global scope on the variable in the function.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 0&lt;br&gt;
def count():&lt;br&gt;
   global total&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
print(count())&lt;br&gt;
1&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 0&lt;br&gt;
def count():&lt;br&gt;
   global total&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
count()&lt;br&gt;
count()&lt;br&gt;
print(count())&lt;br&gt;
3&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dependency injection (A simplified version of global scope)

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;total = 0&lt;br&gt;
def count(total):&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
print(count(total))&lt;br&gt;
1&lt;/p&gt;

&lt;p&gt;total = 0&lt;br&gt;
def count(total):&lt;br&gt;
   total += 1&lt;br&gt;
   return total&lt;br&gt;
print(count(count(count(total))))&lt;br&gt;
3&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nonlocal Keyword
This is a new keyword(feature) in python 3 and its used to refer to the parent local scope.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;def outer():&lt;br&gt;
   x = "local"&lt;br&gt;
   def inner():&lt;br&gt;
      nonlocal x&lt;br&gt;
      x = "nonlocal"&lt;br&gt;
      print("inner:", x)&lt;br&gt;
   inner()&lt;br&gt;
   print("outer:", x)&lt;br&gt;
outer()&lt;br&gt;
inner: nonlocal&lt;br&gt;
outer: nonlocal&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Without the nonlocal keyword

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;def outer():&lt;br&gt;
   x = "local"&lt;br&gt;
   def inner():&lt;br&gt;
      x = "nonlocal"&lt;br&gt;
      print("inner:", x)&lt;br&gt;
   inner()&lt;br&gt;
   print("outer:", x)&lt;br&gt;
outer()&lt;br&gt;
inner: nonlocal&lt;br&gt;
outer: local&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Why do we need scope?

"Why not just have every variable with a global scope so that everything has access to everything?"
Machines don't have infinite power/memory hence we need to be cautious of the resources we use. Scope is a good demonstration of this.
Eg. When a function is run, we create one memory space hence when for instance we use nonlocal, we instead of creating another memory space, we use an existing one.

Hurraay!! 🥳
We come to the end of the second module. Hope you've learnt a lot and ready to implement the skills in different fields.
As we wrap up, here is a simple exercise for you to try before checking the answer done below:

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;age = input("What is your age?: ")&lt;br&gt;
if int(age) &amp;lt; 18:&lt;br&gt;
    print("Sorry, you are too young to drive this car. Powering off!")&lt;br&gt;
elif int(age) &amp;gt; 18:&lt;br&gt;
    print("Powering On. Enjoy the ride!");&lt;br&gt;
else:&lt;br&gt;
    print("Congratulations on your first year of driving. Enjoy the ride!")&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Given the code above, perform the actions below on the code:

Wrap the above code in a function called checkDriverAge() that whenever you call this function, you will get prompted for age.

Instead of using the input(), make the checkDriverAge() function accept an argument of age, so that if you enter eg. checkDriverAge(92), it returns "Powering On. Enjoy the ride!"

Make the default age set to 0 if no argument is given.

Answer:

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;def checkDriverAge(age=0):&lt;br&gt;
   if int(age) &amp;lt; 18:&lt;br&gt;
       print("Sorry, you are too young to drive this car. Powering off")&lt;br&gt;
   elif int(age) &amp;gt; 18:&lt;br&gt;
       print("Powering On. Enjoy the ride!");&lt;br&gt;
   else:&lt;br&gt;
       print("Congratulations on your first year of driving. Enjoy the ride!")&lt;br&gt;
checkDriverAge(10)&lt;br&gt;
Sorry, you are too young to drive this car. Powering off&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;



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

What next? 🤔
Let's meet in the next module #Advanced Python1.

Till next time; bye bye.

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

&lt;/div&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Python from the word ...Go</title>
      <dc:creator>Abdikhafar</dc:creator>
      <pubDate>Thu, 10 Oct 2024 19:04:51 +0000</pubDate>
      <link>https://dev.to/abdikhafarhub/python-from-the-word-go-46el</link>
      <guid>https://dev.to/abdikhafarhub/python-from-the-word-go-46el</guid>
      <description>&lt;p&gt;Basics Part1&lt;br&gt;
By Abdikhafar Issack&lt;/p&gt;

&lt;p&gt;Introduction&lt;br&gt;
What is programming?&lt;br&gt;
In simple terms, programming is a way for us to give instructions to computers. "Giving it an instruction manual, and the computer follows".&lt;/p&gt;

&lt;p&gt;Computers don't understand English or any other human language for that matter. Computers speak in 1s and 0s; On or Off (So is all the other electronic component).&lt;br&gt;
But for humans, it would be gibberish or rather difficult to communicate in 1s or 0s. Humans have then developed programming languages that work in between human language and machine language (0s / 1s).&lt;br&gt;
Some programming languages are low-level (closer to machine language) while others are high-level (closer to human language).&lt;br&gt;
Examples of low-level programming languages include:&lt;/p&gt;

&lt;p&gt;Assembly&lt;br&gt;
Examples of high-level programming languages include:&lt;/p&gt;

&lt;p&gt;Python&lt;br&gt;
JavaScript&lt;br&gt;
What then is a programming language?&lt;br&gt;
A programming language is any set of rules that convert strings, or graphical program elements, to various kinds of machine code output (that is understandable to the computer).&lt;/p&gt;

&lt;p&gt;Note: At the end of the day, all programming languages do the same thing, they tell the machine what to do. However, different languages have different modes of doing it.&lt;br&gt;
The beauty is that "most languages have very similar principles."&lt;/p&gt;

&lt;p&gt;The hardest part is only in learning the first language.&lt;/p&gt;

&lt;p&gt;In between the programming language and the machine language, we need a 'translator' that understands both the programming language (source code) and machine language and hence can translate our code to machine language for the computers to understand.&lt;br&gt;
*The translator ain't a person but rather another program that can either be an interpreter or a compiler.&lt;br&gt;
Like a translator, an interpreter goes line by line throughout the code and executes the code on the machine. In contrast, a compiler takes the code and reads the entire file all at once and translates it to machine code. (Their other major differences are a little complicated and beyond the scope of the course)&lt;br&gt;
Python usually uses an interpreter hence to use python you have to download the interpreter.&lt;/p&gt;

&lt;p&gt;First "Hello World" Program&lt;br&gt;
After setting up the interpreter, we can use the terminal (Command Prompt, GIT Bash, PowerShell, Termux ...etc) to run a few of python commands.&lt;br&gt;
Open the terminal and first run 'python' command. Secondly, use the python command "print" to display characters.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print("I am using python")&lt;br&gt;
I am using python&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Setting up the environment (IDE Setup)&lt;br&gt;
We have previously just run our first python program but in a profession, one cannot run the entire company's program on the terminal. It is mainly used for quick testing.&lt;br&gt;
In most cases, we use code editors or IDEs to run python programs.&lt;/p&gt;

&lt;p&gt;Why not write code in a word document or a text file?&lt;/p&gt;

&lt;p&gt;In a word document, the code will be in form of text hence in case of a syntax error, no information will be returned. In addition, professional developers need some extra tools that code editors and IDEs provide that help them to be more efficient with their code.&lt;/p&gt;

&lt;p&gt;What is a code editor and an IDE, and what is their difference?&lt;br&gt;
Code editors are lightweight and give some features like auto-completion, while IDEs are full-fledged environments and provide a tone of extra features like debugging, auto-completion, code formatting, code snippets ...etc.&lt;br&gt;
The most popular code editors and IDEs for Python include: Sublime Text, Visual Studio Code, PyCharm and Jupyter Notebooks.&lt;/p&gt;

&lt;p&gt;Python Basics&lt;br&gt;
In order for any programmer to learn a language, there are 4 key things that they really need to master:&lt;/p&gt;

&lt;p&gt;i). Terms of the language - Different words and definitions are used in the language eg. Variables, statements, and instantiation.&lt;br&gt;
ii). Language Data Types - Integers, strings ...etc.&lt;br&gt;
iii). Actions - Using memory and performing some actions.&lt;br&gt;
iv). Best practices of writing a language.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables
Variables are memory locations that store information that can be used in a program.
They act like 'containers' that store/hold an item(s).
They can hold user(s) input, values ..etc.
eg.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; name = "Abdikhafar"
&amp;gt;&amp;gt;&amp;gt; print(name)
Abdikhafar

Hence, 'name' is a variable that stores the name, Mark.

&amp;gt;&amp;gt;&amp;gt; iq = 190
&amp;gt;&amp;gt;&amp;gt; print(iq)
190
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Note: Assigning a value to a variable is known as binding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rules of declaring variables&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;snake_case
&lt;code&gt;is_driving = True&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Python Data Types&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Text Type:
str - string

-Numeric Types:
int - integer
float
complex

-Sequence Types:
list
tuple
range

-Mapping Type:
dict - dictionary

-Set Types:
set
frozenset

-Boolean Type:
bool - boolean

-Binary Types:
bytes
bytearray
memoryview
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;a.) int - Integer&lt;br&gt;
An integer is a whole number with no decimal point; 1, 2, 3, 4, 456, -4643, -77.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(2 + 4)
6

&amp;gt;&amp;gt;&amp;gt; print(2 - 4)
-2

&amp;gt;&amp;gt;&amp;gt; print(2 * 4)
8

&amp;gt;&amp;gt;&amp;gt; print(type(2))
&amp;lt;class 'int'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(-29))
&amp;lt;class 'int'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(2 + 4))
&amp;lt;class 'int'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(2 - 4))
&amp;lt;class 'int'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b.) float&lt;br&gt;
These are numbers with a decimal point; 5.7, 8.0, 3.5554, 0.00003, -0.543, -4.229.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(2 / 4)
0.5

&amp;gt;&amp;gt;&amp;gt; print(type(2.7))
&amp;lt;class 'float'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(-27.554))
&amp;lt;class 'float'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(2.8 + 4))
&amp;lt;class 'float'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print(type(2 / 4))
&amp;lt;class 'float'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: - floats take up a lot of space in memory than integers.&lt;br&gt;
This is because the number(s) need to be stored in memory in binary form. But when there's a decimal place eg. 10.56, it is difficult to represent that in a binary form(0s / 1s) because of the point '.' hence a floating-point number is stored in two different locations eg. one for 10 and the other for 56.&lt;/p&gt;

&lt;p&gt;Operations on integers and floats.&lt;br&gt;
operators + , - , * , / , ** , // , %&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;----- addition&lt;/li&gt;
&lt;li&gt;----- subtraction&lt;/li&gt;
&lt;li&gt;----- multiplication
/ ----- division&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** ---- 'power of'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(2 ** 4)
16

&amp;gt;&amp;gt;&amp;gt; print(7 ** 9)
40,353,607
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;// ---- 'rounds down the quotient to the nearest whole number'&lt;br&gt;
eg.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(2 // 4)
0

&amp;gt;&amp;gt;&amp;gt; print(3 // 4)
0

&amp;gt;&amp;gt;&amp;gt; print(4 // 4)
1

&amp;gt;&amp;gt;&amp;gt; print(5 // 4)
1

&amp;gt;&amp;gt;&amp;gt; print(7 // 4)
1

&amp;gt;&amp;gt;&amp;gt; print(9 // 4)
2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Math Functions (Actions performed on integers and floats).&lt;br&gt;
i) round - rounds off the number to the nearest whole number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(round(3.1))
3

&amp;gt;&amp;gt;&amp;gt; print(round(3.9))
4

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

&lt;/div&gt;



&lt;p&gt;ii) abs - returns the absolute value of the argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(abs(-20))
20

&amp;gt;&amp;gt;&amp;gt; print(abs(-354))
354

&amp;gt;&amp;gt;&amp;gt; print(abs(44))
44

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

&lt;/div&gt;



&lt;p&gt;iii) pow - used to calculate a number to its specific power.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(pow(2,3))
8

&amp;gt;&amp;gt;&amp;gt; print(pow(4,3))
64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;iv) max - returns the highest number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(max(2,3))
3

&amp;gt;&amp;gt;&amp;gt; print(max(2,-9))
2

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

&lt;/div&gt;



&lt;p&gt;v) min - returns the least number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(min(3,8))
3

&amp;gt;&amp;gt;&amp;gt; print(min(2,-9))
-9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For most of the other mathematical functions to be used, they have to be 'imported' from the math module.&lt;br&gt;
from math import *&lt;br&gt;
The * symbol means 'everything' hence we import all the functions from the math module.&lt;/p&gt;

&lt;p&gt;i) floor - rounds down the number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from math import *

&amp;gt;&amp;gt;&amp;gt; print(floor(3.7))
3

&amp;gt;&amp;gt;&amp;gt; print(floor(5.9))
5

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

&lt;/div&gt;



&lt;p&gt;ii) ceil - rounds up the number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from math import *

&amp;gt;&amp;gt;&amp;gt; print(ceil(3.2))
4

&amp;gt;&amp;gt;&amp;gt; print(ceil(5.9))
5

&amp;gt;&amp;gt;&amp;gt; print(ceil(5.3))
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;iii) sqrt - returns the square root of a number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from math import *

&amp;gt;&amp;gt;&amp;gt; print(sqrt(4))
2.0

&amp;gt;&amp;gt;&amp;gt; print(sqrt(9))
3.0

&amp;gt;&amp;gt;&amp;gt; print(sqrt(121))
11.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Operator Precedence (BODMAS)&lt;br&gt;
B - brackets&lt;br&gt;
O - power off&lt;br&gt;
D - division&lt;br&gt;
M - multiplication&lt;br&gt;
A - addition&lt;br&gt;
S - subtraction&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(20 - 3 * 4)
8

&amp;gt;&amp;gt;&amp;gt; print((20 - 3) * 4)
68

&amp;gt;&amp;gt;&amp;gt; print((20 - 3) + 2 ** 2)
21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Working with strings&lt;/strong&gt;&lt;br&gt;
String Concatenation&lt;br&gt;
Concatenation is the action of linking things together in a series hence, string concatenation is joining multiple strings to one in series.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; first_name = "Abdi"
&amp;gt;&amp;gt;&amp;gt; second_name = "khafar"
&amp;gt;&amp;gt;&amp;gt; full_name = first_name + second_name
&amp;gt;&amp;gt;&amp;gt; print(full_name)
Abdikhafar

&amp;gt;&amp;gt;&amp;gt; first_name = "Abdi"
&amp;gt;&amp;gt;&amp;gt; second_name = "Khafar"
&amp;gt;&amp;gt;&amp;gt; full_name = first_name + ' ' + second_name
&amp;gt;&amp;gt;&amp;gt; print(full_name)
Abdi Khafar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Type Conversion&lt;/strong&gt;&lt;br&gt;
This is converting a value from one data type to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print(type(str(100)))
&amp;lt;class 'str'&amp;gt;

&amp;gt;&amp;gt;&amp;gt; a = str(100)
&amp;gt;&amp;gt;&amp;gt; b = int(a)
&amp;gt;&amp;gt;&amp;gt; a_type = type(a)
&amp;gt;&amp;gt;&amp;gt; b_type = type(b)
&amp;gt;&amp;gt;&amp;gt; print(a_type)
&amp;lt;class 'str'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; print(b_type)
&amp;lt;class 'int'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Escape Sequences&lt;/strong&gt;&lt;br&gt;
We use a backslash.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; weather = 'It\'s sunny'
&amp;gt;&amp;gt;&amp;gt; print(weather)
It's sunny

&amp;gt;&amp;gt;&amp;gt; weather = "It's \"kind of\" sunny"
&amp;gt;&amp;gt;&amp;gt; print(weather)
It's "kind of" sunny

&amp;gt;&amp;gt;&amp;gt; weather = 'It\\s sunny'
&amp;gt;&amp;gt;&amp;gt; print(weather)
It\s sunny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;\t is used to add a tab to the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; weather = '\t It\'s sunny'
&amp;gt;&amp;gt;&amp;gt; print(weather)
    It's sunny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;\n is used to take the part after it to a new line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; weather = "It's sunny \n hope you have a good day."
&amp;gt;&amp;gt;&amp;gt; print(weather)
It's sunny
hope you have a good day
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Formatted Strings (f-string)&lt;br&gt;
An 'f' is added at the start of the expected output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; name = "Johnny"
&amp;gt;&amp;gt;&amp;gt; age = 55
&amp;gt;&amp;gt;&amp;gt; print ("hi" + name + ". You are" + str(age) + "years old.")
hi Johnny. You are 55 years old.

(can also be written as)

&amp;gt;&amp;gt;&amp;gt; name = "Johnny"
&amp;gt;&amp;gt;&amp;gt; age = 55
&amp;gt;&amp;gt;&amp;gt; print (f"hi {name}. You are {age} years old.")
hi Johnny. You are 55 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;String Indexes&lt;br&gt;
A string is stored in a memory as ordered pieces of characters.&lt;/p&gt;

&lt;p&gt;my name is&lt;br&gt;
0123456789&lt;/p&gt;

&lt;p&gt;To access each character in a string, we use an index. Indexing starts from zero(0).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; sentence = "my name is Mark"
&amp;gt;&amp;gt;&amp;gt; print(sentence[3])
n

&amp;gt;&amp;gt;&amp;gt; sentence = "my name is Mark"
&amp;gt;&amp;gt;&amp;gt; print(sentence[8])
i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extra ways to access the values using the indexes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[1:])
1234567

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[:5])
01234

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[::2])
0246

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[-1])
7

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[-2])
6

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[-3])
5

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[::-1])
76543210

&amp;gt;&amp;gt;&amp;gt; number = '01234567'
&amp;gt;&amp;gt;&amp;gt; print(number[::-2])
7531
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Immutability&lt;br&gt;
Strings in Python are immutable (they cannot be changed).&lt;/p&gt;

&lt;p&gt;Built-in string Functions and methods&lt;br&gt;
len() - used to find the number of characters in a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; greet = "Hello"
&amp;gt;&amp;gt;&amp;gt; print(len(greet))
5

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

&lt;/div&gt;



&lt;p&gt;x.upper() - capitalizes or changes the entire string to uppercase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; greet = "Hello"
&amp;gt;&amp;gt;&amp;gt; print(greet.upper)
HELLO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.lower() - changes the entire string to lowercase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; greet = "hello"
&amp;gt;&amp;gt;&amp;gt; print(greet.capitalize)
Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.isupper() - returns either True or False on whether the string is in uppercase.&lt;/p&gt;

&lt;p&gt;x.islower() - returns either True or False on whether the string is in lowercase.&lt;/p&gt;

&lt;p&gt;Using functions in combination with each other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; phrase = "My name is Mark"
&amp;gt;&amp;gt;&amp;gt; print(phrase.upper().isupper())
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.find() - returns the index of the character(s) you're looking for in the string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; quote = "to be or not to be"
&amp;gt;&amp;gt;&amp;gt; print(quote.find("be"))
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.replace() - used to replace character(s) in a string with new character(s).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; quote = "to be or not to be"
&amp;gt;&amp;gt;&amp;gt; print(quote.replace("be", "me"))
to me or not to me

&amp;gt;&amp;gt;&amp;gt; quote = "to be or not to be"
&amp;gt;&amp;gt;&amp;gt; print(quote.replace("t", "y"))
yo be or noy yo be
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.index - returns the index of a specific character or the index where the characters start.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; greet = "hello"
&amp;gt;&amp;gt;&amp;gt; print(greet.index("e"))
1

&amp;gt;&amp;gt;&amp;gt; greet = "hello"
&amp;gt;&amp;gt;&amp;gt; print(greet.index("l"))
2

&amp;gt;&amp;gt;&amp;gt; greet = "hello"
&amp;gt;&amp;gt;&amp;gt; print(greet.index("lo"))
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d.) bool - booleans&lt;br&gt;
This data type consists of either 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;&amp;gt;&amp;gt;&amp;gt; is_cool = True
&amp;gt;&amp;gt;&amp;gt; print(is_cool)
True

&amp;gt;&amp;gt;&amp;gt; is_tall = False
&amp;gt;&amp;gt;&amp;gt; print(is_tall)
False

&amp;gt;&amp;gt;&amp;gt; print(bool(1))
True

&amp;gt;&amp;gt;&amp;gt; print(bool(0))
False

&amp;gt;&amp;gt;&amp;gt; print(bool('True'))
True

&amp;gt;&amp;gt;&amp;gt; print(bool('False'))
True

&amp;gt;&amp;gt;&amp;gt; print(bool())
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: A Boolean value is always True as far as there's a value. 0 or empty data will always return False as shown in the examples above.&lt;/p&gt;

&lt;p&gt;Let's kick-off off our next data type:&lt;/p&gt;

&lt;p&gt;e.) Lists&lt;br&gt;
A list is an ordered sequence of objects of any type. It is denoted by square brackets [].&lt;br&gt;
It can have a collection of items of different data types and can at times be referred to as an array though there's a slight difference between a list and an array. (Will cover this later in the course).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; li = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; li2 = ['a', 'b', 'c', 'f']
&amp;gt;&amp;gt;&amp;gt; li3 = [1, 2, 'r', 'u', True]
&amp;gt;&amp;gt;&amp;gt; print(li)
&amp;gt;&amp;gt;&amp;gt; print(li2)
&amp;gt;&amp;gt;&amp;gt; print(li3)
[1, 2, 3, 4, 5]
['a', 'b', 'c', 'f']
[1, 2, 'r', 'u', True]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lists are Data Structures.&lt;br&gt;
A Data Structure is a data organization, management, and storage format that enables efficient access and modification.&lt;/p&gt;

&lt;p&gt;Accessing individual items in a list (using index)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; li3 = [1, 2, 'r', 'u', True]
&amp;gt;&amp;gt;&amp;gt; print(li3[2])
&amp;gt;&amp;gt;&amp;gt; print(li3[4])
r
True

&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", "sunglasses", "earphones"]
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart[2])
earphones

&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", "sunglasses", "earphones"]
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart[3])
#Returns an error for the index is out range.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List Slicing&lt;br&gt;
As we did in strings, we can use the index [start:stop] to access a specific range of items in a list.&lt;br&gt;
Remember eg. [1:7] selects all items from index 1 to but not including the item in index 7 hence the last item is the item in index 6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", 
                   "sunglasses", 
                   "earphones",
                   "toys",
                   "grapes"]
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart[0:4])
['notebooks', 'sunglasses', 'earphones', 'toys']

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

&lt;/div&gt;



&lt;p&gt;Modifying elements in a list&lt;br&gt;
Lists, unlike strings, are mutable hence one can modify elements in a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", 
                   "sunglasses", 
                   "earphones",
                   "toys",
                   "grapes"]
&amp;gt;&amp;gt;&amp;gt; amazon_cart[0] = "Laptop"
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart)
['Laptop', 'sunglasses', 'earphones', 'toys', 'grapes']

&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", 
                   "sunglasses", 
                   "earphones",
                   "toys",
                   "grapes"]
&amp;gt;&amp;gt;&amp;gt; amazon_cart[0] = "Laptop"
&amp;gt;&amp;gt;&amp;gt; new_cart = amazon_cart[0:3]
&amp;gt;&amp;gt;&amp;gt; new_cart[1] = "gum"
&amp;gt;&amp;gt;&amp;gt; print(new_cart)
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart)
['Laptop', 'gum', 'earphones']
['Laptop', 'sunglasses', 'earphones', 'toys', 'grapes']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: When you assign a list to a different variable, it points to the memory location of the original list hence modification of the list in the new variable leads to modification of the original list in the previous variable.&lt;br&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;&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", 
                   "sunglasses", 
                   "earphones",
                   "toys",
                   "grapes"]
&amp;gt;&amp;gt;&amp;gt; amazon_cart[0] = "Laptop"
&amp;gt;&amp;gt;&amp;gt; new_cart = amazon_cart
&amp;gt;&amp;gt;&amp;gt; new_cart[0] = "gum"
&amp;gt;&amp;gt;&amp;gt; print(new_cart)
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart)
['gum', 'sunglasses', 'earphones', 'toys', 'grapes']
['gum', 'sunglasses', 'earphones', 'toys', 'grapes']

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

&lt;/div&gt;



&lt;p&gt;To avoid modification of the original list after one has modified the list assigned in the new variable, we use [:] after the list variable to copy the entire list and store it as a new list in a different variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; amazon_cart = ["notebooks", 
                   "sunglasses", 
                   "earphones",
                   "toys",
                   "grapes"]
&amp;gt;&amp;gt;&amp;gt; amazon_cart[0] = "Laptop"
&amp;gt;&amp;gt;&amp;gt; new_cart = amazon_cart[:]
&amp;gt;&amp;gt;&amp;gt; new_cart[0] = "gum"
&amp;gt;&amp;gt;&amp;gt; print(new_cart)
&amp;gt;&amp;gt;&amp;gt; print(amazon_cart)
['gum', 'sunglasses', 'earphones', 'toys', 'grapes']
['Laptop', 'sunglasses', 'earphones', 'toys', 'grapes']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Matrix (These are multi-dimensional lists/arrays)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; matrix = [
      [2, 4, 6],
      [9, 5, 7],
      [3, 8, 1]
    ]
&amp;gt;&amp;gt;&amp;gt; print(matrix)
[[2, 4, 6], [9, 5, 7], [3, 8, 1]]

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

&lt;/div&gt;



&lt;p&gt;Accessing elements in a multi-dimensional list/array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; matrix = [
      [2, 4, 6],
      [9, 5, 7],
      [3, 8, 1]
    ]
&amp;gt;&amp;gt;&amp;gt; print(matrix[1][2])
&amp;gt;&amp;gt;&amp;gt; print(matrix[0][1])
7
4

&amp;gt;&amp;gt;&amp;gt; matrix = [
      [2, 4, 6],
      [9, 5, 7],
      [3, 8, 1]
    ]
&amp;gt;&amp;gt;&amp;gt; print(matrix[2][3])
#Returns an error for the index is out of range.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List Functions and Methods/Actions&lt;br&gt;
len() - Find the length of a list (number of items in a list).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List Functions and Methods/Actions
len() - Find the length of a list (number of items in a list).

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

&lt;/div&gt;



&lt;p&gt;x.append() - Used to add a value to an original list.&lt;br&gt;
It modifies the list inplace hence does not create a copy of the original list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.append(100)
&amp;gt;&amp;gt;&amp;gt; print(basket)
[1, 2, 3, 4, 5, 100]

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; new_list = basket.append(100)
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 5, 100]
None

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.append(100)
&amp;gt;&amp;gt;&amp;gt; new_list = basket
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 5, 100]
[1, 2, 3, 4, 5, 100]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.insert() - Used to insert a value anywhere in the list on a specific index.&lt;br&gt;
It too modifies the list inplace hence does not create a copy of the original list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; new_list = basket.insert(4, 100)
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 100, 5]
None

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.insert(4, 100)
&amp;gt;&amp;gt;&amp;gt; new_list = basket
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 100, 5]
[1, 2, 3, 4, 100, 5]

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

&lt;/div&gt;



&lt;p&gt;x.extend() - Used to append another list to the original list.&lt;br&gt;
It too modifies the list inplace hence does not create a copy of the original list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; new_list = basket.extend([100, 101, 107])
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 5, 100, 101, 107]
None

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.extend([100, 101, 107])
&amp;gt;&amp;gt;&amp;gt; new_list = basket
&amp;gt;&amp;gt;&amp;gt; print(basket)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
[1, 2, 3, 4, 5, 100, 101, 107]
[1, 2, 3, 4, 5, 100, 101, 107]

numbers = [1, 2, 3, 4]
friends = ["Kelvin", "Karen", "Jim"]
friends.extend(numbers)
print(friends)
['Kelvin', 'Karen', 'Jim', 1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.pop() - Automatically removes (pops off) the last element from the list or from the given index. It returns the element that has been popped off.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.pop()
&amp;gt;&amp;gt;&amp;gt; print(basket)
[1, 2, 3, 4]

&amp;gt;&amp;gt;&amp;gt; friends = ["Kelvin", "Karen", "Jim"]
&amp;gt;&amp;gt;&amp;gt; friends.pop()
&amp;gt;&amp;gt;&amp;gt; print(friends)
['Kelvin', 'Karen']

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.pop(0)
&amp;gt;&amp;gt;&amp;gt; print(basket)
[2, 3, 4, 5]

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.pop(2)
&amp;gt;&amp;gt;&amp;gt; print(basket)
[1, 2, 4, 5]

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; new_list = basket.pop(4)
&amp;gt;&amp;gt;&amp;gt; print(new_list)
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.remove() - Removes an element/value from a list. Works 'inplace'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.remove(4)
&amp;gt;&amp;gt;&amp;gt; print(basket)
[1, 2, 3, 5]

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

&lt;/div&gt;



&lt;p&gt;x.clear() - Clears the entire list. Works 'inplace'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 5]
&amp;gt;&amp;gt;&amp;gt; basket.clear()
&amp;gt;&amp;gt;&amp;gt; print(basket)
[]

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

&lt;/div&gt;



&lt;p&gt;x.index() - Used to check the index of an element in the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = ['a', 'b', 'c', 'd', 'e']
&amp;gt;&amp;gt;&amp;gt; print(basket.index('d'))
3

Checking from a specific index in the list.

&amp;gt;&amp;gt;&amp;gt; basket = ['a', 'b', 'c', 'd', 'e']
&amp;gt;&amp;gt;&amp;gt; print(basket.index('d', 0, 3)) #Checking from index 0 to index 3 (but not including index 3).
#returns an error as 'd' is in index 3 yet index 3 is not included in the range.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finding whether an element is or is not in a list.&lt;br&gt;
We use the keyword 'in' which returns whether 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;&amp;gt;&amp;gt;&amp;gt; basket = ['a', 'b', 'c', 'd', 'e']
&amp;gt;&amp;gt;&amp;gt; print('d' in basket)
True

&amp;gt;&amp;gt;&amp;gt; basket = ['a', 'b', 'c', 'd', 'e']
&amp;gt;&amp;gt;&amp;gt; print('i' in basket)
False

&amp;gt;&amp;gt;&amp;gt; print('a' in 'My name is Mark')
True

&amp;gt;&amp;gt;&amp;gt; print('z' in 'What is the time?')
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.count() - Used to count the number of items an element appears in the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = ['a', 'b', 'c', 'd', 'e']
&amp;gt;&amp;gt;&amp;gt; print(basket.count('d'))
1

&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 3, 4, 2, 5, 2]
&amp;gt;&amp;gt;&amp;gt; print(basket.count(2))
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.sort() - Used to sort the list in ascending order. If the list contains names, they are sorted in alphabetical order. Works 'inplace'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [5, 2, 3, 4, 1, 3, 2]
&amp;gt;&amp;gt;&amp;gt; basket.sort()
&amp;gt;&amp;gt;&amp;gt; print(basket)
[1, 2, 2, 3, 3, 4, 5]

&amp;gt;&amp;gt;&amp;gt; friends = ["Karen", "Toby", "Elijah"]
&amp;gt;&amp;gt;&amp;gt; friends.sort()
&amp;gt;&amp;gt;&amp;gt; print(friends)
['Elijah', 'Karen', 'Toby']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;sorted() - Used to sort the list in ascending order. If the list contains names, they are sorted in alphabetical order. Unlike the method x.sort(), sorted() is a function that produces a new array and hence does not work in place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; friends = ["Karen", "Toby", "Elijah"]
&amp;gt;&amp;gt;&amp;gt; print(sorted(friends))
['Elijah', 'Karen', 'Toby']

&amp;gt;&amp;gt;&amp;gt; basket = [5, 2, 3, 4, 1, 3, 2]
&amp;gt;&amp;gt;&amp;gt; print(sorted(basket))
[1, 2, 2, 3, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.copy() - Works the same as [:] by copying the entire list and creating a new one exactly like the original list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; friends = ["Karen", "Toby", "Elijah"]
&amp;gt;&amp;gt;&amp;gt; new_friends = friends.copy()
&amp;gt;&amp;gt;&amp;gt; print(new_friends)
['Karen', 'Toby', 'Elijah']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.reverse() - Used to reverse the elements in the list from the element in the last index to the element in the first index. Works 'inplace'.&lt;br&gt;
(It does not follow the ascending or any order; It just swaps the elements).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; friends = ["Karen", "Toby", "Elijah"]
&amp;gt;&amp;gt;&amp;gt; friends.reverse()
&amp;gt;&amp;gt;&amp;gt; print(friends)
['Elijah', 'Toby', 'Karen']

&amp;gt;&amp;gt;&amp;gt; numbers = [1, 5, 3, 8, 7]
&amp;gt;&amp;gt;&amp;gt; numbers.reverse()
&amp;gt;&amp;gt;&amp;gt; print(numbers)
[7, 8, 3, 5, 1]

&amp;gt;&amp;gt;&amp;gt; numbers = [1, 5, 3, 8, 7]
&amp;gt;&amp;gt;&amp;gt; numbers.sort()
&amp;gt;&amp;gt;&amp;gt; numbers.reverse()
&amp;gt;&amp;gt;&amp;gt; print(numbers)
[8, 7, 5, 3, 1]

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

&lt;/div&gt;



&lt;p&gt;Common List Patterns&lt;br&gt;
Reversing a list with list slicing&lt;br&gt;
This creates a new list from the original, that is, it does not work in place.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;numbers = [1, 5, 3, 8, 7]&lt;br&gt;
numbers.sort()&lt;br&gt;
numbers.reverse()&lt;br&gt;
print(numbers)&lt;br&gt;
print(numbers[::-1])&lt;br&gt;
[8, 7, 5, 3, 1]&lt;br&gt;
[1, 3, 5, 7, 8]&lt;br&gt;
Note: You can reverse a list using list slicing (-1) or using the x.reverse() method as shown above.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;range() - Generates a list of numbers from up to but not including the last number stated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; print (list(range(1, 50)))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49]

&amp;gt;&amp;gt;&amp;gt; print (list(range(50)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49]

&amp;gt;&amp;gt;&amp;gt; print (list(range(51)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49,
50]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Getting the length of a list - Number of items in a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; basket = [1, 2, 6, 8, 4, 0]
&amp;gt;&amp;gt;&amp;gt; print(len(basket))
6

&amp;gt;&amp;gt;&amp;gt; names = ["Mark", "Enoch", "Vivian", "Yvonne", "Mercy"]
&amp;gt;&amp;gt;&amp;gt; print(len(names))
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.join&lt;br&gt;
This is a string method used to join items in a list with the given 'character'. It creates a new item and hence does not work inplace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; sentence = '!'
&amp;gt;&amp;gt;&amp;gt; new_sentence = sentence.join(['hi', 'my', 'name', 'is', 'JOJO'])
&amp;gt;&amp;gt;&amp;gt; print(new_sentence)
hi!my!name!is!JOJO

&amp;gt;&amp;gt;&amp;gt; sentence = '.'
&amp;gt;&amp;gt;&amp;gt; new_sentence = sentence.join(['hi', 'my', 'name', 'is', 'JOJO'])
&amp;gt;&amp;gt;&amp;gt; print(new_sentence)
hi.my.name.is.JOJO

&amp;gt;&amp;gt;&amp;gt; sentence = ' '
&amp;gt;&amp;gt;&amp;gt; sen2 = ['hello', 'welcome', 'to', 'the', 'city']
&amp;gt;&amp;gt;&amp;gt; new_sentence = sentence.join(sen2)
&amp;gt;&amp;gt;&amp;gt; print(new_sentence)
hello welcome to the city

&amp;gt;&amp;gt;&amp;gt; new_sentence = '!'.join(['hi', 'my', 'name', 'is', 'JOJO'])
&amp;gt;&amp;gt;&amp;gt; print(new_sentence)
hi!my!name!is!JOJO

&amp;gt;&amp;gt;&amp;gt; new_sentence = ' '.join(['hi', 'my', 'name', 'is', 'JOJO'])
&amp;gt;&amp;gt;&amp;gt; print(new_sentence)
hi my name is JOJO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List Unpacking&lt;br&gt;
This is assigning a variable to each item in a list. Works like multiple assigning of values in variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; a,b,c = [1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; print(a)
&amp;gt;&amp;gt;&amp;gt; print(b)
&amp;gt;&amp;gt;&amp;gt; print(c)
1
2

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

&lt;/div&gt;



&lt;p&gt;In list unpacking, you can add more values, unpack the values assigned in the variables then store the remaining items in their own variable. You just add the * sign and the name of the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; a,b,c *other = [1, 2, 3, 4, 5, 6, 7, 8, 9]
&amp;gt;&amp;gt;&amp;gt; print(a)
&amp;gt;&amp;gt;&amp;gt; print(b)
&amp;gt;&amp;gt;&amp;gt; print(c)
&amp;gt;&amp;gt;&amp;gt; print(other)
1
2
3
[4, 5, 6, 7, 8, 9]

&amp;gt;&amp;gt;&amp;gt; a,b,c, *other, d = [1, 2, 3, 4, 5, 6, 7, 8, 9]
&amp;gt;&amp;gt;&amp;gt; print(a)
&amp;gt;&amp;gt;&amp;gt; print(b)
&amp;gt;&amp;gt;&amp;gt; print(c)
&amp;gt;&amp;gt;&amp;gt; print(other)
&amp;gt;&amp;gt;&amp;gt; print(d)
1
2
3
[4, 5, 6, 7, 8]
9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;f.) None type&lt;br&gt;
This is a special data type that represents the absence of values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; weapons = None
&amp;gt;&amp;gt;&amp;gt; print(weapons)
None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;g.) Tuples&lt;br&gt;
These are like lists but immutable data types. Data stored in tuples can never be changed eg. coordinates.&lt;/p&gt;

&lt;p&gt;Can't add elements to it.&lt;/p&gt;

&lt;p&gt;Can't erase elements from it.&lt;/p&gt;

&lt;p&gt;Can't modify elements in it.&lt;/p&gt;

&lt;p&gt;Tuples are also data structures.&lt;br&gt;
They use the parenthesis '()' to store data and can store data of different data types in a single tuple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 4, 7, 5)
&amp;gt;&amp;gt;&amp;gt; print(my_tuple)
(1, 2, 4, 7, 5)

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 'a', True)
&amp;gt;&amp;gt;&amp;gt; print (my_tuple)
(1, 2, 'a', True)

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 4, 7, 5)
&amp;gt;&amp;gt;&amp;gt; print(my_tuple[3])
7

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 4, 7, 5)
&amp;gt;&amp;gt;&amp;gt; print(3 in my_tuple)
False

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 4, 7, 5)
&amp;gt;&amp;gt;&amp;gt; print(5 in my_tuple)
True

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 4, 7, 5)
&amp;gt;&amp;gt;&amp;gt; my_tuple[3] = 9
&amp;gt;&amp;gt;&amp;gt; print(my_tuple)
#returns an error as tuples cannot be modified
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tuples can be sliced (similar to list slicing)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; new_tuple = my_tuple[1:4]
&amp;gt;&amp;gt;&amp;gt; print(new_tuple)
(2, 3, 4)

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 2, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; new_tuple = my_tuple[1:2]
&amp;gt;&amp;gt;&amp;gt; print(new_tuple)
(2,)

&amp;gt;&amp;gt;&amp;gt; x, y, z, *other = (1, 2, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; print(x)
&amp;gt;&amp;gt;&amp;gt; print(y)
&amp;gt;&amp;gt;&amp;gt; print(z)
&amp;gt;&amp;gt;&amp;gt; print(other)
1
2
3
[4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tuples have two main methods:&lt;/p&gt;

&lt;p&gt;x.count()&lt;/p&gt;

&lt;p&gt;x.index()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 5, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; print(my_tuple.count(5))
2

&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 5, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; print(my_tuple.index(4))
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get the length of a tuple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_tuple = (1, 5, 3, 4, 5)
&amp;gt;&amp;gt;&amp;gt; print(len(my_tuple))
5

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

&lt;/div&gt;



&lt;p&gt;A list of tuples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; coordinates = [(4, 5), (6, 7), (80, 34)]
&amp;gt;&amp;gt;&amp;gt; print(coordinates)
[(4, 5), (6, 7), (80, 34)]

&amp;gt;&amp;gt;&amp;gt; coordinates = [(4, 5), (6, 7), (80, 34)]
&amp;gt;&amp;gt;&amp;gt; print(coordinates[1])
(6, 7)

&amp;gt;&amp;gt;&amp;gt; coordinates = [(4, 5), (6, 7), (80, 34)]
&amp;gt;&amp;gt;&amp;gt; print(coordinates[1][1])

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

&lt;/div&gt;



&lt;p&gt;h.) Dictionaries&lt;br&gt;
This is a special data structure that allows one to organize or store data in unordered key-value pairs. It uses curly braces '{}'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dictionary = {
   'key' : value,
   'key' : value
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key must always be unique (shouldn't be repeated).&lt;br&gt;
To access the value, we use the key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : 1,
      'b' : 2,
      'x' : 4
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict)
{'a': 1, 'b': 2, 'x': 3}

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : 1,
      'b' : 2,
      'x' : 4
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict['b'])
2

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : 1,
      'b' : 2
      'x' : 4
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict['c'])
#returns an error for the key is not defined.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Elements in a dictionary are stored in different memory locations which are not necessarily in order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : 1,
      'b' : 2,
      'x' : 4
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict)
{'a': 1, 'b': 2, 'x': 3}

At times the output may be as shown below.

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : 1,
      'b' : 2,
      'x' : 4
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict)
{'x': 4, 'a': 1, 'b': 2}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionary keys can store values of different data types (same as lists and tuples).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : [1, 2, 3],
      'b' : "hello",
      'x' : True,
      't' : 5
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict)
{'a': [1, 2, 3], 'b': 'hello', 'x': True, 't': 5}

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : [1, 2, 3],
      'b' : "hello",
      'x' : True,
      't' : 5
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict['a'])
[1, 2, 3]

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : [1, 2, 3],
      'b' : "hello",
      'x' : True,
      't' : 5
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict['a'][1])
2

&amp;gt;&amp;gt;&amp;gt; my_dict = {
      'a' : [1, 2, 3],
      'b' : "hello",
      'x' : True,
      't' : 5
      }
&amp;gt;&amp;gt;&amp;gt; print(my_dict['b'][4])
o
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A dictionary in a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_list = [
       {
        'a' : [1, 2, 3],
        'b' : "hello",
        'x' : True,
        't' : 5
        },

       {
        'a' : [4, 5, 6],
        'b' : "welcome",
        'x' : False,
        't' : 5
       }
    ]
&amp;gt;&amp;gt;&amp;gt; print(my_list[0]['a'][2])
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionary Keys&lt;br&gt;
Dictionary keys are immutable types and should be unique. This means that a string, a number, a tuple and a Boolean can be a key while a list cannot.&lt;br&gt;
Note: When one re-assigns a key to another value, the original value in the key is overwritten.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dictionary = {
         123 : [1, 2, 5, 6],
         True : 'hello',
         'a' : ('a', 't', 'u'),
         [100] : False
     }
&amp;gt;&amp;gt;&amp;gt; print (dictionary[100])
#returns an error as a list is mutable and hence cannot be used as a key.

&amp;gt;&amp;gt;&amp;gt; dictionary = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         '123' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(dictionary['123'])
('a', 't', 'u')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionary Methods&lt;br&gt;
x.get() - A method used to check whether a key is present in a dictionary. At times it returns a default value given if a key is missing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(user.get('age'))
None

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(user.get('age', 55))
55

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u'),
         'age' : 20
     }
&amp;gt;&amp;gt;&amp;gt; print(user.get('age', 55))
20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A second way of creating a dictionary:&lt;br&gt;
By using the keyword 'dict(key = value)'.&lt;br&gt;
The key cannot be an expression, that is, it should be a variable when using 'dict'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user2 = dict(name = 'John')
&amp;gt;&amp;gt;&amp;gt; print(user2)
{'name': 'John'}

&amp;gt;&amp;gt;&amp;gt; user2 = dict(name = 'John', name2 = 'Mark')
&amp;gt;&amp;gt;&amp;gt; print(user2)
{'name': 'John', 'name2': 'Mark'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'in' keyword can also be used in dictionaries.&lt;br&gt;
It returns either True or False on whether a key is present or absent in a dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print('size' in user)
False

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print('basket' in user)
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.keys() - Used to check whether a specific key is present in a dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print('123' in user.keys())
True

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print('age' in user.keys())
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.values() - Used to check whether a specific value is present in a dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print('hello' in user.values())
True

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(('a', 't', 'u') in user.values())
True

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print([1, 2, 6, 5] in user.values())
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.items() - Returns the entire items in a dictionary as tuples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(user.items())
dict_items([('123', [1, 2, 5, 6]), (True, 'hello'), ('basket', ('a', 't', 'u'))])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.clear() - clears the dictionary and returns an empty dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; print(user.clear())
None

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; user.clear()
&amp;gt;&amp;gt;&amp;gt; print(user)
{}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.copy() - creates a copy of a dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u')
     }
&amp;gt;&amp;gt;&amp;gt; user2 = user.copy()
&amp;gt;&amp;gt;&amp;gt; print(user2)
{'123': [1, 2, 5, 6], True: 'hello', 'basket': ('a', 't', 'u')}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.pop() - Removes key with its value from the dictionary and returns the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u'),
         'age' : 20
     }
&amp;gt;&amp;gt;&amp;gt; user.pop('age')
&amp;gt;&amp;gt;&amp;gt; print(user)
20
{'123': [1, 2, 5, 6], True: 'hello', 'basket': ('a', 't', 'u')}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.popitem() - Removes a random pair of key-value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u'),
         'age' : 20
     }
&amp;gt;&amp;gt;&amp;gt; user.popitem()
&amp;gt;&amp;gt;&amp;gt; print(user)
('age', 20)
{'123': [1, 2, 5, 6], True: 'hello', 'basket': ('a', 't', 'u')}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.update() - Used to update the keys in the dictionary or by adding a new key and value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u'),
         'age' : 20
     }
&amp;gt;&amp;gt;&amp;gt; user.update({'age' : 55})
&amp;gt;&amp;gt;&amp;gt; print(user)
{'123': [1, 2, 5, 6], True: 'hello', 'basket': ('a', 't', 'u'), 'age': 55}

&amp;gt;&amp;gt;&amp;gt; user = {
         '123' : [1, 2, 5, 6],
         True : 'hello',
         'basket' : ('a', 't', 'u'),
         'age' : 20
     }
&amp;gt;&amp;gt;&amp;gt; user.update({'age2' : 55})
&amp;gt;&amp;gt;&amp;gt; print(user)
{'123': [1, 2, 5, 6], True: 'hello', 'basket': ('a', 't', 'u'), 'age': 20, 'age2': 55}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;i.) Sets&lt;br&gt;
These are an unordered collection of unique objects. It uses curly brackets and returns only the unique objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5}
&amp;gt;&amp;gt;&amp;gt; print(my_set)
{1, 2, 3, 4, 5}

&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5}
&amp;gt;&amp;gt;&amp;gt; my_set.add(2)
&amp;gt;&amp;gt;&amp;gt; my_set.add(100)
&amp;gt;&amp;gt;&amp;gt; print(my_set)
{1, 2, 3, 4, 5, 100}

&amp;gt;&amp;gt;&amp;gt; my_list = [1, 2, 2, 3, 5, 5]
&amp;gt;&amp;gt;&amp;gt; print(set(my_list))
{1, 2, 3, 5}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objects in a set are not indexed and hence cannot be accessed using an index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5}
&amp;gt;&amp;gt;&amp;gt; print(my_set[0])
#returns an error as items cannot be accessed using indexes in sets

&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5}
&amp;gt;&amp;gt;&amp;gt; print(1 in my_set)
True

&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5, 7, 7}
&amp;gt;&amp;gt;&amp;gt; print(6 in my_set)
False

&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5, 7, 7}
&amp;gt;&amp;gt;&amp;gt; print(len(my_set))
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Converting a set to a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5, 7, 7}
&amp;gt;&amp;gt;&amp;gt; print(list(my_set))
[1, 2, 3, 4, 5, 7]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.copy - Copies a set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5, 5, 7, 7}
&amp;gt;&amp;gt;&amp;gt; new_set = my_set.copy()
&amp;gt;&amp;gt;&amp;gt; my_set.clear()
&amp;gt;&amp;gt;&amp;gt; print(new_set)
&amp;gt;&amp;gt;&amp;gt; print(my_set)
{1, 2, 3, 4, 5, 7}
set()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Methods in sets&lt;br&gt;
x.difference() - Finds the difference of two sets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5}
&amp;gt;&amp;gt;&amp;gt; your_set = {4, 5, 6, 7, 8, 9, 10}
&amp;gt;&amp;gt;&amp;gt; print(my_set.difference(your_set))
{1, 2, 3}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.discard() - Removes an element from a set if it is a member. Works inplace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x.discard() - Removes an element from a set if it is a member. Works inplace.

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

&lt;/div&gt;



&lt;p&gt;x.difference_update() - Removes all elements of another set from the previous set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x.difference_update() - Removes all elements of another set from the previous set.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;x.intersection() - Returns the common values in both sets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_set = {1, 2, 3, 4, 5}
&amp;gt;&amp;gt;&amp;gt; your_set = {4, 5, 6, 7, 8, 9, 10}
&amp;gt;&amp;gt;&amp;gt; print(my_set.intersection(your_set))
{4, 5}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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