30 days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days

Overview

🐍 30 Days Of Python

# Day Topics
01 Introduction
02 Variables, Built-in Functions
03 Operators
04 Strings
05 Lists
06 Tuples
07 Sets
08 Dictionaries
09 Conditionals
10 Loops
11 Functions
12 Modules
13 List Comprehension
14 Higher Order Functions
15 Python Type Errors
16 Python Date time
17 Exception Handling
18 Regular Expressions
19 File Handling
20 Python Package Manager
21 Classes and Objects
22 Web Scraping
23 Virtual Environment
24 Statistics
25 Pandas
26 Python web
27 Python with MongoDB
28 API
29 Building API
30 Conclusions

🧑 🧑 🧑 HAPPY CODING 🧑 🧑 🧑

Support the author to create more educational materials
Paypal Logo

30 Days Of Python: Day 1 - Introduction

Twitter Follow

Author: Asabeneh Yetayeh
Second Edition: July, 2021

Day 2 >>

30DaysOfPython

πŸ“˜ Day 1

Welcome

Congratulations for deciding to participate in a 30 days of Python programming challenge . In this challenge you will learn everything you need to be a python programmer and the whole concept of programming. In the end of the challenge you will get a 30DaysOfPython programming challenge certificate.

If you would like to actively engage in the challenge, you may join the 30DaysOfPython challenge telegram group.

Introduction

Python is a high-level programming language for general-purpose programming. It is an open source, interpreted, objected-oriented programming language. Python was created by a Dutch programmer, Guido van Rossum. The name of Python programming language was derived from a British sketch comedy series, Month Python's Flying Circus. The first version was released on February 20, 1991. This 30 days of Python challenge will help you learn the latest version of Python, Python 3 step by step. The topics are broken down into 30 days, where each day contains several topics with easy-to-understand explanations, real-world examples, many hands on exercises and projects.

This challenge is designed for beginners and professionals who want to learn python programming language. It may take 30 to 100 days to complete the challenge, people who actively participate on the telegram group have a high probability of completing the challenge. If you are a visual learner or in favor of videos, you may get started with this Python for Absolute Beginners video.

Why Python ?

It is a programming language which is very close to human language and because of that it is easy to learn and use. Python is used by various industries and companies (including Google). It has been used to develop web applications, desktop applications, system adminstration, and machine learning libraries. Python is highly embraced language in the data science and machine learning community. I hope this is enough to convince you to start learning Python. Python is eating the world and you are killing it before it eats you.

Environment Setup

Installing Python

To run a python script you need to install python. Let's download python. If your are a windows user. Click the button encircled in red.

installing on Windows

If you are a macOS user. Click the button encircled in red.

installing on Windows

To check if python is installed write the following command on your device terminal.

python --version

Python Version

As you can see from the terminal, I am using Python 3.7.5 version at the moment. Your version of Python might be different from mine by but it should be 3.6 or above. If you mange to see the python version, well done. Python has been installed on your machine. Continue to the next section.

Python Shell

Python is an interpreted scripting language, so it does not need to be compiled. It means it executes the code line by line. Python comes with a Python Shell (Python Interactive Shell). It is used to execute a single python command and get the result.

Python Shell waits for the Python code from the user. When you enter the code, it interprets the code and shows the result in the next line. Open your terminal or command prompt(cmd) and write:

python

Python Scripting Shell

The Python interactive shell is opened and it is waiting for you to write Python code(Python script). You will write your Python script next to this symbol >>> and then click Enter. Let us write our very first script on the Python scripting shell.

Python script on Python shell

Well done, you wrote your first Python script on Python interactive shell. How do we close the Python interactive shell ? To close the shell, next to this symbol >> write exit() command and press Enter.

Exit from python shell

Now, you know how to open the Python interactive shell and how to exit from it.

Python will give you results if you write scripts that Python understands, if not it returns errors. Let's make a deliberate mistake and see what Python will return.

Invalid Syntax Error

As you can see from the returned error, Python is so clever that it knows the mistake we made and which was Syntax Error: invalid syntax. Using x as multiplication in Python is a syntax error because (x) is not a valid syntax in Python. Instead of (x) we use asterisk (*) for multiplication. The returned error clearly shows what to fix.

The process of identifying and removing errors from a program is called debugging. Let us debug it by putting * in place of x.

Fixing Syntax Error

Our bug was fixed, the code ran and we got a result we were expecting. As a programmer you will see such kind of errors on daily basis. It is good to know how to debug. To be good at debugging you should understand what kind of errors you are facing. Some of the Python errors you may encounter are SyntaxError, IndexError, NameError, ModuleNotFoundError, KeyError, ImportError, AttributeError, TypeError, ValueError, ZeroDivisionError etc. We will see more about different Python error types in later sections.

Let us practice more how to use Python interactive shell. Go to your terminal or command prompt and write the word python.

Python Scripting Shell

The Python interactive shell is opened. Let us do some basic mathematical operations (addition, subtraction, multiplication, division, modulus, exponential).

Let us do some maths first before we write any Python code:

  • 2 + 3 = 5
  • 3 - 2 = 1
  • 3 * 2 = 6
  • 3 / 2 = 1.5
  • 3 ^ 2 = 3 x 3 = 9

In python we have the following additional operations:

  • 3 % 2 = 1 => which means finding the remainder
  • 3 // 2 = 1 => which means removing the remainder

Let us change the above mathematical expressions to Python code. The Python shell has been opened and let us write a comment at the very beginning of the shell.

A comment is a part of the code which is not executed by python. So we can leave some text in our code to make our code more readable. Python does not run the comment part. A comment in python starts with hash(#) symbol. This is how you write a comment in python

 # comment starts with hash
 # this is a python comment, because it starts with a (#) symbol

Maths on python shell

Before we move on to the next section, let us practice more on the Python interactive shell. Close the opened shell by writing exit() on the shell and open it again and let us practice how to write text on the Python shell.

Writing String on python shell

Installing Visual Studio Code

The Python interactive shell is good to try and test small script codes but it will not be for a big project. In real work environment, developers use different code editors to write codes. In this 30 days of Python programming challenge we will use visual studio code. Visual studio code is a very popular open source text editor. I am a fan of vscode and I would recommend to download visual studio code, but if you are in favor of other editors, feel free to follow with what you have.

Visual Studio Code

If you installed visual studio code, let us see how to use it. If you prefer a video, you can follow this Visual Studio Code for Python Video tutorial

How to use visual studio code

Open the visual studio code by double clicking the visual studio icon. When you open it you will get this kind of interface. Try to interact with the labeled icons.

Visual studio Code

Create a folder named 30DaysOfPython on your desktop. Then open it using visual studio code.

Opening Project on Visual studio

Opening a project

After opening it you will see shortcuts for creating files and folders inside of 30DaysOfPython project's directory. As you can see below, I have created the very first file, helloworld.py. You can do the same.

Creating a python file

After a long day of coding, you want to close your code editor, right? This is how you will close the opened project.

Closing project

Congratulations, you have finished setting up the development environment. Let us start coding.

Basic Python

Python Syntax

A Python script can be written in Python interactive shell or in the code editor. A Python file has an extension .py.

Python Indentation

An indentation is a white space in a text. Indentation in many languages is used to increase code readability, however Python uses indentation to create block of codes. In other programming languages curly brackets are used to create blocks of codes instead of indentation. One of the common bugs when writing python code is wrong indentation.

Indentation Error

Comments

Comments are very important to make the code more readable and to leave remarks in our code. Python does not run comment parts of our code. Any text starting with hash(#) in Python is a comment.

Example: Single Line Comment

    # This is the first comment
    # This is the second comment
    # Python is eating the world

Example: Multiline Comment

Triple quote can be used for multiline comment if it is not assigned to a variable

"""This is multiline comment
multiline comment takes multiple lines.
python is eating the world
"""

Data types

In Python there are several types of data types. Let us get started with the most common ones. Different data types will be covered in detail in other sections. For the time being, let us just go through the different data types and get familiar with them. You do not have to have a clear understanding now.

Number

  • Integer: Integer(negative, zero and positive) numbers Example: ... -3, -2, -1, 0, 1, 2, 3 ...
  • Float: Decimal number Example ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ...
  • Complex Example 1 + j, 2 + 4j

String

A collection of one or more characters under a single or double quote. If a string is more than one sentence then we use a triple quote.

Example:

'Asabeneh'
'Finland'
'Python'
'I love teaching'
'I hope you are enjoying the first day of 30DaysOfPython Challenge'

Booleans

A boolean data type is either a True or False value. T and F should be always uppercase.

Example:

    True  #  Is the light on? If it is on, then the value is True
    False # Is the light on? If it is off, then the value is False

List

Python list is an ordered collection which allows to store different data type items. A list is similar to an array in JavaScript.

Example:

[0, 1, 2, 3, 4, 5]  # all are the same data types - a list of numbers
['Banana', 'Orange', 'Mango', 'Avocado'] # all the same data types - a list of strings (fruits)
['Finland','Estonia', 'Sweden','Norway'] # all the same data types - a list of strings (countries)
['Banana', 10, False, 9.81] # different data types in the list - string, integer, boolean and float

Dictionary

A Python dictionary object is an unordered collection of data in a key value pair format.

Example:

{
'first_name':'Asabeneh',
'last_name':'Yetayeh',
'country':'Finland', 
'age':250, 
'is_married':True,
'skills':['JS', 'React', 'Node', 'Python']
}

Tuple

A tuple is an ordered collection of different data types like list but tuples can not be modified once they are created. They are immutable.

Example:

('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names
('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # planets

Set

A set is a collection of data types similar to list and tuple. Unlike list and tuple, set is not an ordered collection of items. Like in Mathematics, set in Python stores only unique items.

In later sections, we will go in detail about each and every Python data type.

Example:

{2, 4, 3, 5}
{3.14, 9.81, 2.7} # order is not important in set

Checking Data types

To check the data type of certain data/variable we use the type function. In the following terminal you will see different python data types:

Checking Data types

Python File

First open your project folder, 30DaysOfPython. If you don't have this folder, create a folder name called 30DaysOfPython. Inside this folder, create a file called helloworld.py. Now, let's do what we did on python interactive shell using visual studio code.

The Python interactive shell was printing without using print but on visual studio code to see our result we should use a built in function *print(). The print() built-in function takes one or more arguments as follows print('arument1', 'argument2', 'argument3'). See the examples below.

Example:

The file name is helloworld.py

# Day 1 - 30DaysOfPython Challenge

print(2 + 3)             # addition(+)
print(3 - 1)             # subtraction(-)
print(2 * 3)             # multiplication(*)
print(3 / 2)             # division(/)
print(3 ** 2)            # exponential(**)
print(3 % 2)             # modulus(%)
print(3 // 2)            # Floor division operator(//)

# Checking data types
print(type(10))          # Int
print(type(3.14))        # Float
print(type(1 + 3j))      # Complex number
print(type('Asabeneh'))  # String
print(type([1, 2, 3]))   # List
print(type({'name':'Asabeneh'})) # Dictionary
print(type({9.8, 3.14, 2.7}))    # Set
print(type((9.8, 3.14, 2.7)))    # Tuple

To run the python file check the image below. You can run the python file either by running the green button on Visual Studio Code or by typing python helloworld.py in the terminal .

Running python script

πŸŒ• You are amazing. You have just completed day 1 challenge and you are on your way to greatness. Now do some exercises for your brain and muscles.

πŸ’» Exercises - Day 1

Exercise: Level 1

  1. Check the python version you are using
  2. Open the python interactive shell and do the following operations. The operands are 3 and 4.
    • addition(+)
    • subtraction(-)
    • multiplication(*)
    • modulus(%)
    • division(/)
    • exponential(**)
    • floor division operator(//)
  3. Write strings on the python interactive shell. The strings are the following:
    • Your name
    • Your family name
    • Your country
    • I am enjoying 30 days of python
  4. Check the data types of the following data:
    • 10
    • 9.8
    • 3.14
    • 4 - 4j
    • ['Asabeneh', 'Python', 'Finland']
    • Your name
    • Your family name
    • Your country

Exercise: Level 2

  1. Create a folder named day_1 inside 30DaysOfPython folder. Inside day_1 folder, create a python file helloworld.py and repeat questions 1, 2, 3 and 4. Remember to use print() when you are working on a python file. Navigate to the directory where you have saved your file, and run it.

Exercise: Level 3

  1. Write an example for different Python data types such as Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set and Dictionary.
  2. Find an Euclidian distance between (2, 3) and (10, 8)

πŸŽ‰ CONGRATULATIONS ! πŸŽ‰

Day 2 >>

Comments
  • Day 7 wrong pop method description

    Day 7 wrong pop method description

    fruits.pop() # removes the last element from the set

    from the doc -->Remove and return an arbitrary element from the set. Raises KeyError if the set is empty.

    opened by Mar1usSo 2
  • Add 4files Korean translation

    Add 4files Korean translation

    What type of PR is this?

    -[]New features -[]Bug Fix -[o]Suggest -[]ETC (please write somethings..)

    Description

    Add

    • readme.md
    • 04_strings.md
    • 07_sets.md
    • 10_loops.md Korean translation
    opened by jshyun1 1
  • Bump jinja2 from 2.10.3 to 2.11.3 in /python_for_web

    Bump jinja2 from 2.10.3 to 2.11.3 in /python_for_web

    Bumps jinja2 from 2.10.3 to 2.11.3.

    Release notes

    Sourced from jinja2's releases.

    2.11.3

    This contains a fix for a speed issue with the urlize filter. urlize is likely to be called on untrusted user input. For certain inputs some of the regular expressions used to parse the text could take a very long time due to backtracking. As part of the fix, the email matching became slightly stricter. The various speedups apply to urlize in general, not just the specific input cases.

    2.11.2

    2.11.1

    This fixes an issue in async environment when indexing the result of an attribute lookup, like {{ data.items[1:] }}.

    2.11.0

    This is the last version to support Python 2.7 and 3.5. The next version will be Jinja 3.0 and will support Python 3.6 and newer.

    Changelog

    Sourced from jinja2's changelog.

    Version 2.11.3

    Released 2021-01-31

    • Improve the speed of the urlize filter by reducing regex backtracking. Email matching requires a word character at the start of the domain part, and only word characters in the TLD. :pr:1343

    Version 2.11.2

    Released 2020-04-13

    • Fix a bug that caused callable objects with __getattr__, like :class:~unittest.mock.Mock to be treated as a :func:contextfunction. :issue:1145
    • Update wordcount filter to trigger :class:Undefined methods by wrapping the input in :func:soft_str. :pr:1160
    • Fix a hang when displaying tracebacks on Python 32-bit. :issue:1162
    • Showing an undefined error for an object that raises AttributeError on access doesn't cause a recursion error. :issue:1177
    • Revert changes to :class:~loaders.PackageLoader from 2.10 which removed the dependency on setuptools and pkg_resources, and added limited support for namespace packages. The changes caused issues when using Pytest. Due to the difficulty in supporting Python 2 and :pep:451 simultaneously, the changes are reverted until 3.0. :pr:1182
    • Fix line numbers in error messages when newlines are stripped. :pr:1178
    • The special namespace() assignment object in templates works in async environments. :issue:1180
    • Fix whitespace being removed before tags in the middle of lines when lstrip_blocks is enabled. :issue:1138
    • :class:~nativetypes.NativeEnvironment doesn't evaluate intermediate strings during rendering. This prevents early evaluation which could change the value of an expression. :issue:1186

    Version 2.11.1

    Released 2020-01-30

    • Fix a bug that prevented looking up a key after an attribute ({{ data.items[1:] }}) in an async template. :issue:1141

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Day 19  - Line 199 and 202

    Day 19 - Line 199 and 202

    199 if os.path.exist('./files/example.txt'): -> if os.path.exists('./files/example.txt'):

    202 os.remove('The file does not exist') -> print('The file does not exist')

    I'm a new learner so if I'm wrong please forgive me.

    opened by FreezeRasis 1
  • Repeated print statement in 02_variables_builtin_functions.md

    Repeated print statement in 02_variables_builtin_functions.md

    Bug: In the 'casting' section of 'Checking Data types and Casting', first_name is printed twice.

    Documentation:

    # str to list
    first_name = 'Asabeneh'    
    print(first_name)    
    print(first_name)                    # 'Asabeneh'    
    

    Fix: Remove one print statement

    opened by dhruvp4u 1
  • Use ==/!= to compare str, bytes, and int literals

    Use ==/!= to compare str, bytes, and int literals

    Identity is not the same thing as equality in Python so use ==/!= to compare str, bytes, and int literals. In Python >= 3.8, these instances will raise SyntaxWarnings so it is best to fix them now. https://docs.python.org/3.8/whatsnew/3.8.html#porting-to-python-3-8

    opened by cclauss 1
  • Minor bug fix in string formatting | Day 4

    Minor bug fix in string formatting | Day 4

    Hi Asabeneh, this PR proposes the following minor change in Day 4

    • Minor bug fix in the example of string formatting. formatted_string is defined in the example but formatted is used in the print command which is not defined.
    opened by Rasbin 1
  • [#322] Add Korean Translation

    [#322] Add Korean Translation

    What type of PR is this?

    -[o]New features -[]Bug Fix -[]Suggest -[]ETC (please write somethigs..)

    Description

    I created a lang-ko folder and translated the readme.md file into Korean.

    opened by jshyun1 0
  • nested if issue

    nested if issue

    `I am a beginner who is still learning how to use python syntax.I tried to write codes using if conditions as exercising but I had an issue. the idea of the code is to write a program that allows the user to enter his country and the course he wants to apply for then the program will give him a discount regarding this information.

    issue: the issue is every time I write ksa as the input it gives me a discount for Canada and I don't know why. if1 if2

    opened by YouseefSaad 0
  • Incorrect use of brackets in Exercise 2

    Incorrect use of brackets in Exercise 2

    Corrected brackets in exercise 2: Flatten the following list of lists of lists to a one dimensional list.

    Incorrect brackets: list_of_lists =[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]] Correction: list_of_lists =[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    opened by AdityaDanturthi 0
Owner
Asabeneh
🌱 Educator πŸ’» Programmer 🌐 Developer πŸ”₯ Motivator πŸ“˜ Content creator πŸ“ˆ Data Analyst | I create jargon-free, easy to read and understand educational material
Asabeneh
Fully reproducible, Dockerized, step-by-step, tutorial on how to mock a "real-time" Kafka data stream from a timestamped csv file. Detailed blog post published on Towards Data Science.

time-series-kafka-demo Mock stream producer for time series data using Kafka. I walk through this tutorial and others here on GitHub and on my Medium

Maria Patterson 26 Nov 15, 2022
This is a repository for "100 days of code challenge" projects. You can reach all projects from beginner to professional which are written in Python.

100 Days of Code It's a challenge that aims to gain code practice and enhance programming knowledge. Day #1 Create a Band Name Generator It's actually

SelenNB 2 May 12, 2022
Python script to generate Vale linting rules from word usage guidance in the Red Hat Supplementary Style Guide

ssg-vale-rules-gen Python script to generate Vale linting rules from word usage guidance in the Red Hat Supplementary Style Guide. These rules are use

Vale at Red Hat 1 Jan 13, 2022
This tutorial will guide you through the process of self-hosting Polygon

Hosting guide This tutorial will guide you through the process of self-hosting Polygon Before starting Make sure you have the following tools installe

Polygon 2 Jan 31, 2022
Obmovies - A short guide on setting up the system and environment dependencies required for ob's Movies database

Obmovies - A short guide on setting up the system and environment dependencies required for ob's Movies database

null 1 Jan 4, 2022
This repo contains everything you'll ever need to learn/revise python basics

Python Notes/cheat sheet Simplified notes to get your Python basics right Just compare code and output side by side and feel the rush of enlightenment

Hem 5 Oct 6, 2022
PySpark Cheat Sheet - learn PySpark and develop apps faster

This cheat sheet will help you learn PySpark and write PySpark apps faster. Everything in here is fully functional PySpark code you can run or adapt to your programs.

Carter Shanklin 168 Jan 1, 2023
Coursera learning course Python the basics. Programming exercises and tasks

HSE_Python_the_basics Welcome to BAsics programming Python! You’re joining thousands of learners currently enrolled in the course. I'm excited to have

PavelRyzhkov 0 Jan 5, 2022
Python Programming (Practical) (1-25) Download πŸ‘‡πŸΌ

BCA-603 : Python Programming (Practical) (1-25) Download zip ?? ?? How to run programs : Clone or download this repo to your computer. Unzip (If you d

Milan Jadav 2 Jun 2, 2022
Python-samples - This project is to help someone need some practices when learning python language

Python-samples - This project is to help someone need some practices when learning python language

Gui Chen 0 Feb 14, 2022
JMESPath is a query language for JSON.

JMESPath JMESPath (pronounced "james path") allows you to declaratively specify how to extract elements from a JSON document. For example, given this

null 1.7k Dec 31, 2022
the project for the most brutal and effective language learning technique

- "The project for the most brutal and effective language learning technique" (c) Alex Kay The langflow project was created especially for language le

Alexander Kaigorodov 7 Dec 26, 2021
A collection of simple python mini projects to enhance your python skills

A collection of simple python mini projects to enhance your python skills

PYTHON WORLD 12.1k Jan 5, 2023
Python Eacc is a minimalist but flexible Lexer/Parser tool in Python.

Python Eacc is a parsing tool it implements a flexible lexer and a straightforward approach to analyze documents.

Iury de oliveira gomes figueiredo 60 Nov 16, 2022
Repository for learning Python (Python Tutorial)

Repository for learning Python (Python Tutorial) Languages and Tools ?? Overview ?? Repository for learning Python (Python Tutorial) Languages and Too

Swiftman 2 Aug 22, 2022
A python package to avoid writing and maintaining duplicated python docstrings.

docstring-inheritance is a python package to avoid writing and maintaining duplicated python docstrings.

Antoine Dechaume 15 Dec 7, 2022
advance python series: Data Classes, OOPs, python

Working With Pydantic - Built-in Data Process ========================== Normal way to process data (reading json file): the normal princiople, it's f

Phung HΖ°ng Binh 1 Nov 8, 2021
A simple USI Shogi Engine written in python using python-shogi.

Revengeshogi My attempt at creating a USI Shogi Engine in python using python-shogi. Current State of Engine Currently only generating random moves us

null 1 Jan 6, 2022
Python-slp - Side Ledger Protocol With Python

Side Ledger Protocol Run python-slp node First install Mongo DB and run the mong

Solar 3 Mar 2, 2022