🐍 30 Days Of Python

简介: 《30天Python挑战》是一个为期30天的编程挑战,旨在帮助初学者和专业人士掌握Python编程语言。每天涵盖不同的主题,从变量、内置函数到高级主题如API构建等,通过易懂的解释、实例和练习逐步深入。作者Asabeneh Yetayeh还提供了视频教程和社区支持,确保学习者能够顺利完成挑战并获得证书。项目包括环境搭建、基础语法、数据类型、控制结构等内容,适合所有水平的学习者。

🐍 30 Days Of Python

🧡🧡🧡 HAPPY CODING 🧡🧡🧡


Support the author to create more educational materials

Paypal Logo


30 Days Of Python: Day 1 - Introduction




Author:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

📘 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, Monty 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.

This challenge is easy to read, written in conversational English, engaging, motivating and at the same time, it is very demanding. You need to allocate much time to finish this challenge. If you are a visual learner, you may get the video lesson on Washera YouTube channel. You may start from Python for Absolute Beginners video. Subscribe the channel, comment and ask questions on YouTube vidoes and be proactive, the author will eventually notice you.

The author likes to hear your opinion about the challenge, share the author by expressing your thoughts about the 30DaysOfPython challenge. You can leave your testimonial on this link

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 is 5
  • 3 - 2 is 1
  • 3 * 2 is 6
  • 3 / 2 is 1.5
  • 3 * 2 is the same as 3 3

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 ! 🎉

目录
相关文章
|
6月前
|
人工智能 Shell 开发工具
阿里云百炼Qwen3.7-Max全面解读 模型能力、核心优势与618优惠订阅指南
随着大模型技术持续迭代升级,通用大模型逐步朝着更高理解能力、更强逻辑推理、更长上下文、多模态融合的方向发展,广泛应用于内容创作、代码开发、智能对话、数据分析、企业知识库问答、方案撰写等全品类场景。阿里云百炼作为国内主流大模型服务平台,持续迭代通义千问系列模型,Qwen3.7-Max作为当前旗舰级主力模型之一,凭借综合性能、多模态能力、超长上下文窗口以及稳定的服务表现,成为个人创作者、研发人员、中小企业及大型政企单位的首选模型。
594 3
|
Shell
VBS控制鼠标移动和点击(附源代码下载)
森思:想用vbs来控制鼠标的移动和点击,虽然按键精灵可以做到,但做这么简单的事情不想启动那么大一个程序,所以自己用VC写了一个小程序,可以让VBS来控制鼠标移动和点击。 用法: 移动鼠标到桌面坐标200,50的vbs命令如下: CreateObject("WScript.
5095 0
|
3月前
|
人工智能 IDE API
阿里云Coding Plan和Token Plan有什么区别?百炼AI模型如何使用Token更省钱?
阿里云百炼Coding Plan是专为AI编程打造的订阅服务,仅剩200元/月的Pro版(每日限量抢购),提供9万次/月调用额度,支持Qwen、Kimi等多模型及主流编程工具;相比按量计费的Token Plan,它免Token焦虑、适合个人开发者。
638 7
|
4月前
|
缓存 运维 安全
阿里云ESA边缘安全加速免费领取:支持2个网站域名免费,通过宝塔面板快速领取指南
宝塔面板联合阿里云ESA推出免费CDN活动,可一键领取2个长期免费站点额度,支持中国大陆节点加速(需备案)、HTTPS加密、基础安全防护及面板内统一管理,降本增效,轻松上手。阿里云ESA官网:https://t.aliyun.com/U/AlRpfa
368 1
|
12月前
|
存储 人工智能 缓存
阿里云对象存储OSS按量使用达标返券活动,消费达标报名即返等额代金券,用50元返50元
阿里云对象存储OSS推出专属代金券了,开通按量付费,消费达标报名即返等额代金券,用多少返多少。按小时使用对象存储 OSS 达到门槛,返对应代金券,满10元返10元,满50元返50元,灵活省钱又高效。适合互联网多媒体、大数据分析、AI 应用、数据归档等场景。
|
4月前
|
JSON 自然语言处理 小程序
ISBN 开放 API 开发实践,如何快速获取书名、作者、封面信息?
阿里云ISBN图书查询API(cmapi030453)是面向开发者与企业的标准化图书元数据服务,支持通过ISBN号一键获取书名、作者、出版社、封面图等十余项结构化信息。响应快(均值29.67ms)、SLA达100%、按次计费透明,提供多语言示例与在线调试,适用于电商、图书馆、小程序等场景。
535 0
ISBN 开放 API 开发实践,如何快速获取书名、作者、封面信息?
|
12月前
|
人工智能 自然语言处理 搜索推荐
企业AI客服系统建设费用大揭秘:免费系统能用吗?如何控制预算?
面对AI客服升级需求,企业需平衡成本与服务。免费系统适合小微企轻量入门,但功能有限;瓴羊、Salesforce、Zendesk及探域等高性价比方案,分别在全链路智能、全球化服务、电商垂直场景具优势。不同规模企业应结合咨询量、行业特性与预算,选择匹配的AI客服解决方案,实现服务与增长双提升。(239字)
|
6月前
|
人工智能 前端开发 物联网
历史科普视频的AI自动化生产工作流:从全手动到半自动的工程演进
本文量化历史科普视频制作瓶颈,对比全手动(Stable Diffusion/GPT-SoVITS/Manim等开源栈)与半自动(花生AI为核心)方案。实测混合工作流将单期耗时从29–49小时压缩至10–15小时,效率提升60%+,兼顾质量、可控性与落地性。
|
5月前
|
人工智能 弹性计算 自然语言处理
零代码建站 + 全链路运营!阿里云万小智 AI 员工,10 分钟搞定品牌官网
万小智是阿里云推出的AI建站平台,基于通义大模型,集成AI建站、创意配图、智能客服、SEO内容四大能力,10分钟极速上线品牌官网;预置多行业模板,支持对话式编辑;深度整合阿里云安全与算力,备案发布一站式完成,小微企业建站更省时、省力、更安心。