Hi, my name is Mosh, and I'm going to be your instructor in this Python course. 嗨，我叫Mosh，我将作为您的Python课程讲师。
In this course, you're going to learn everything you need to get started programming in Python. 在本课程中，您将学习开始使用Python进行编程所需的一切。
Python is one of the most popular programming languages, and every day people use it to do Python是最流行的编程语言之一，人们每天都在使用它来做
cool things like automation, they use it in AI, as well as 诸如自动化之类的很酷的东西，他们在AI中使用它，以及
building applications and websites like Instagram and Dropbox. So if you're looking 构建应用程序和网站，例如Instagram和Dropbox。因此，如果您正在寻找
for a job, Python is for you. In this course I'm going to teach you everything 为了工作，Python适合您。在这门课程中，我将教你一切
you need to get started with Python. We're going to talk about all the core concepts 您需要开始使用Python。我们将讨论所有核心概念
in Python, and then we're going to build three Python projects together. 在Python中，然后我们将一起构建三个Python项目。
Here's the first project we're going to build. We're going to learn how to create this beautiful website 这是我们要构建的第一个项目。我们将学习如何创建这个漂亮的网站
for an imaginary grocery store. Here on the homepage we can see all 一家假想的杂货店。在首页上，我们可以看到所有
of the products in the shop, and we also have an admin area for managing the 商店中的产品，我们还有一个管理区域，用于管理
stock. We're going to build this using a popular Python framework called Django. 股票。我们将使用一个流行的Python框架Django来构建它。
Now if you have never built a website before, don't worry, I will teach you everything from scratch. 现在，如果您以前从未建立过网站，请不要担心，我将从头开始教您所有内容。
You're also going to learn how to use Python in machine learning, or artificial intelligence. 您还将学习如何在机器学习或人工智能中使用Python。
So you will learn how to write a Python programming that will predict 因此，您将学习如何编写可预测
the music that people like based on their profile. Just like how YouTube 人们根据个人资料喜欢的音乐。就像YouTube一样
recommends videos based on the videos you have watched before. I will also show you 根据您之前看过的视频推荐视频。我也会告诉你
python to automate boring repetitive tasks that waste your time. python自动执行无聊的重复性任务，从而浪费您的时间。
You will write a Python program that will process thousands of spreadsheets 您将编写一个Python程序，该程序将处理数千个电子表格
in under a second. I've designed this Python course for anyone who wants to learn 一秒钟之内。我为想要学习的任何人设计了此Python课程
Python. If you're a beginner, don't worry, I will hold your hand through this entire course. Python。如果您是初学者，请不要担心，我将在整个课程中全程为您服务。
You're not too old or too young, and Python is super easy to learn. You can write your first 您年龄不大或太小，Python非常易于学习。你可以写你的第一个
Python program in literally seconds. Plus I'm going to give you plenty Python程序只需几秒钟。另外我会给你很多
of exercises to help you build your confidence writing cool Python programs. 练习集，可帮助您建立起编写出色的Python程序的信心。
My name is Mosh, I'm a software engineer with two decades of experience 我叫Mosh，我是一位拥有两年经验的软件工程师
and I've taught over 3 million people how to code. I'm super excited to be teaching you 我已经教了超过300万人如何编码。我很高兴能教你
Python in this course. So I hope you stick around and learn this beautiful 本课程中的Python。所以我希望你能继续学习这个美丽的东西
powerful programming language. 强大的编程语言。
In this tutorial I'm going to show you how to download 在本教程中，我将向您展示如何下载
and install Python on your computer. So the first thing I want you to do, 并在您的计算机上安装Python。所以我要你做的第一件事，
is open up your browser and head over to Python 打开浏览器并转到Python
.org. On this page click on downloads, .org。在此页面上，点击下载，
here you can see the latest version of Python currently, at the time of recording this video 在录制此视频时，您可以在此处看到当前最新版本的Python
the latest version is python 3.7.2. 最新版本是python 3.7.2。
Chances are in the future, when you are watching this tutorial, there is a newer 将来有可能，当您观看本教程时，会有更新的
version of Python available, don't worry, all the materials you're going to learn in this course 可以使用Python版本，不用担心，您将在本课程中学习的所有材料
will apply to the latest version of Python as well. So let's go ahead 还将适用于最新版本的Python。所以我们继续吧
and download Python 3, alright now, 并立即下载Python 3，
look at your downloads folder, here, we should have Python 3 installer 查看您的downloads文件夹，在这里，我们应该有Python 3安装程序
simply double click that, if you're on Windows 只需双击即可（如果您使用的是Windows）
you're going to see this check box here, add Python to 您将在此处看到此复选框，将Python添加到
python, this is really important, make sure to tick this box, otherwise you're not going to be able to python，这真的很重要，请确保选中此框，否则您将无法
follow this tutorial. If you're on a Mac, 遵循本教程。如果您使用的是Mac，
you're going to see an installer like this, with this setup wizard we're going to install Python 3 您将看到这样的安装程序，通过此安装向导，我们将安装Python 3
on our computer. So simply click continue, and again, 在我们的计算机上。因此，只需单击“继续”，然后再次单击，
and again, and agree with the license agreement, and 并再次同意许可协议，并且
install it, this is going to take a few seconds so I'm going 安装它，这将需要几秒钟，所以我要
to pause the recording. 暂停录音。
Alright, we have successfully installed Python 3 on our computer. 好的，我们已经在计算机上成功安装了Python 3。
Let's close this. Alright, next we need to install 让我们关闭这个。好了，接下来我们需要安装
a code editor, we se a code editor to write our code, just like 一个代码编辑器，我们就像一个代码编辑器来编写我们的代码，就像
how we use Microsoft Word to write documents, we use a code editor to write 我们如何使用Microsoft Word编写文档，我们使用代码编辑器编写
code. Now there are so many code editors out there, the one that I'm going to show you in this 代码。现在有这么多的代码编辑器，我将在此向您展示
tutorial is PyCharm. That is one of the most popular code editors 教程是PyCharm。那是最受欢迎的代码编辑器之一
for writing Python code. You can get it from jetbrains.com 用于编写Python代码。您可以从jetbrains.com获得它
/pycharm. Now more accurately pycharm / pycharm。现在更准确地pycharm
is considered an IDE, which is short for integrated development 被认为是IDE，它是集成开发的缩写
environment. And that's basically a code editor on steroids, 环境。这基本上是类固醇的代码编辑器，
it has some additional features that makes it really easy to write code. So 它具有一些附加功能，使编写代码变得非常容易。所以
let's go ahead and download PyCharm. Now here on the 让我们继续下载PyCharm。现在在这里
download page, you can see two versions of PyCharm, one is the professional addition 下载页面，您可以看到PyCharm的两个版本，一个是专业版
which has additional features and you have to pay for them. The other is the 其中具有其他功能，您需要付费。另一个是
community edition, that is absolutely free, and that's what we're going to use in this tutorial. 社区版，它是完全免费的，这就是我们将在本教程中使用的版本。
So, go ahead and download this as well. 因此，请继续下载该文件。
Now, once again look at your downloads folder, once again you should have pycharm 现在，再次查看您的下载文件夹，您应该再次拥有pycharm
so double click this, now if you're 因此，如果您正在
in Windows you're going to see an installation wizard, simply click next, next, next 在Windows中，您将看到一个安装向导，只需单击“下一步”，“下一步”，“下一步”
until you install pycharm. If you're on Mac you need to drag and drop this icon 直到您安装pycharm。如果您使用的是Mac，则需要拖放此图标
onto the applications folder, so drag and drop, 放到应用程序文件夹中，然后进行拖放，
alright, now let's double click this to run it, 好吧，现在让我们双击运行它，
the first time we run pycharm we're going to get this warning, because this is an application 第一次运行pycharm时，我们会收到此警告，因为这是一个应用程序
that we download from the internet. So let's go ahead and open it, 我们从互联网上下载的。因此，让我们继续打开它，
next you're going to see this dialogue box for importing some settings, leave this to 接下来，您将看到此对话框，用于导入一些设置，将其保留为
do not import settings, it doesn't really matter. Okay, 不导入设置，这并不重要。好的，
On this page, select I've never used PyCharm you can see some keyword 在此页面上，选择“我从未使用过PyCharm”，您会看到一些关键字
shortcuts that might be useful in the future, just accept this, and down at the bottom, 将来可能会有用的快捷方式，只需接受它，然后在底部，
click the next button. And then next again, 单击下一步按钮。然后再次
one more time, and then finally start using pycharm. 再过一遍，然后终于开始使用pycharm了。
So here's the main page of PyCharm every time you open 所以这是每次打开PyCharm的主页
it, click on create new project, 单击创建新项目，
this is the location for our project, let's call our project Hello 这是我们项目的位置，我们称这个项目为Hello
World. Now before click and create, expand 世界。现在，在单击并创建之前，展开
this item here, make sure that base interpreter is set to Python 此项目，请确保将基本解释器设置为Python
3. Python interpreter is basically a program 3. Python解释器基本上是一个程序
that knows how to execute Python code, it will know how to interpret 知道如何执行Python代码，它将知道如何解释
or translate Python instructions into instructions a computer can understand. 或将Python指令翻译成计算机可以理解的指令。
Now, Mac computers, by default come with an older 现在，默认情况下，Mac电脑随附旧版本
installation of Python, that's Python 2, it's considered legacy 安装的Python，即Python 2，被认为是旧版
which means it's no longer maintained or supported. So earlier we downloaded 这意味着它不再受到维护或支持。所以我们早先下载了
Python 3, make sure that this is set to Python 3, if not Python 3，请确保将其设置为Python 3（如果未设置）
from this list, select Python 3.7. 从此列表中，选择Python 3.7。
Alright, now let's go ahead and create this project, 好吧，现在让我们继续创建这个项目，
Now here right click on 现在在这里右键单击
Hello World folder and go to new Hello World文件夹，然后转到新文件夹
Python file, call this file app.py. Python文件，将此文件称为app.py。
So by convention, all Python files should have this 因此，按照惯例，所有Python文件都应具有
py extension. Alright, let's go ahead, py扩展名。好吧，让我们继续吧，
now let's collapse this project panel by clicking here and write our 现在，让我们通过单击此处折叠此项目面板并编写我们的
first python program. Simply type print, pr 第一个python程序。只需键入打印，PR
int, all in lowercase, open and close parenthesis, int，全部用小写，用圆括号括起来，
and inside these parenthesis, add quotations we 在这些括号内，添加引号
can either use single quotes or double quotes, now 现在可以使用单引号或双引号
in between the codes write your name. I am Mosh Hamedani, so 在代码之间输入您的名字。我是Mosh Hamedani，所以
here, so this is your first Python programming. With these piece of code 在这里，这是您的第一个Python编程。有了这些代码
you can print your name on the screen. Now to run this, go 您可以在屏幕上打印您的名字。现在运行这个，去
on the top, under the run menu, click run, 在顶部的“运行”菜单下，单击“运行”，
also note that there is a shortcut associated with this command, when 还请注意，当
I program I always use shortcuts because that increases my productivity. 我编程时总是使用快捷方式，因为这可以提高生产率。
So here on a Mac computer, the shortcut is control, option, and 因此，在Mac计算机上，快捷方式是control，option和
R. On Windows it's different. So let's do that, now R.在Windows上有所不同。所以现在就开始吧
it's asking where you want to run this, click on app, 询问您要在哪里运行它，单击应用程序，
down below, you should see this little terminal window, this 在下面，您应该看到这个小的终端窗口，
is a little window into our program, so here you can see our results for 是进入我们程序的一个小窗口，因此您可以在此处看到我们的结果
output for our program. In the future as you learn more Python, you'll be 我们程序的输出。将来，当您学习更多Python时，您将
able to build applications that have a graphical user interface, or gooey. 能够构建具有图形用户界面或粘性的应用程序。
That is a little bit complicated, so for now we're going to use this little 这有点复杂，所以现在我们将使用这一点
terminal window to see the results of our program. So as you can see my name is 在终端窗口中查看我们程序的结果。因此，您可以看到我的名字是
printed here, now as you print code, this window might get in the way so 打印在这里，现在当您打印代码时，此窗口可能会妨碍您
always resize it or minimize itty putting this 总是调整它的大小或将其最小化
icon here, so this was our first python program. Now 图标，所以这是我们的第一个python程序。现在
if you didn't see the result I showed you in this video, use the comment box below and 如果您没有在此视频中看到我向您显示的结果，请使用下面的评论框，然后
tell me what error you encountered, I'll do my best to help you move forward. 告诉我您遇到什么错误，我会尽力帮助您前进。
In this Python tutorial, we're gong to take this program to the next level and make it more interesting. 在本Python教程中，我们将把该程序带到一个新的水平，并使之更加有趣。
So I'm going to show you how to draw a dog hair. Now as part of 因此，我将向您展示如何绘制狗毛。现在作为
this tutorial you will learn how Python code gets executed and you will also learn 在本教程中，您将学习如何执行Python代码，并且还将学习
about a few programming terms. So press enter, and 关于一些编程术语。所以按回车，然后
on line 2 write another print statement, so print, open and close 在第2行上，编写另一个打印语句，以便打印，打开和关闭
parenthesis, add a quotation, now here you want to draw a dog. 圆括号，添加引号，现在在这里您要画一条狗。
So, add an o, that is the head of our dog, followed by 因此，添加一个o，即我们狗的头，然后是
4 hyphens. So this is the body. 4个连字符。所以这就是身体。
alright, now one more time another print statement with 好了，现在再来一次
quotations, now we need to draw the legs. So add a space. 报价，现在我们需要画腿。因此，添加一个空间。
Follow it by 4 vertical bars. So, like this, 跟着它的4竖线。所以像这样
so here's a little imaginary dot. Now let's 所以这是一个假想的点。现在让我们
run this program and see what we get. So on the top right corner you should see this play button, 运行该程序，看看我们得到了什么。因此，您应该在右上角看到此播放按钮，
click that, there you go, so we have our name and 单击该按钮，您就可以到达了，所以我们有我们的名字和
right below that we have our imaginary dog. Now what you need to understand 在下面，我们有一个假想的狗。现在您需要了解的内容
here, is that our python code gets executed line by line 在这里，是我们的python代码逐行执行
from the top. So earlier I told you about Python interpreter 从一开始。所以之前我告诉过您有关Python解释器的信息
that is the program that knows how to translate or interpret 那是知道如何翻译或解释的程序
our Python code into instructions that a computer can understand. 将我们的Python代码转换成计算机可以理解的指令。
So when we run this program by clicking this program here, 因此，当我们通过单击此处的程序来运行该程序时，
python interpreter starts executing or running our program python解释器开始执行或运行我们的程序
line by line from the top. So first it executes line 1, 从顶部逐行。首先执行第1行
then, moves onto line 2, and so on. So this is how python 然后，移至第2行，依此类推。所以这就是python
programs get executed. Now let me show you something cool. Let's add 程序被执行。现在，让我向您展示一些很棒的东西。让我们添加
another print statement, with quotations now 另一个印刷声明，现在带有引号
in between the quotations, add a star or an asterisk, like 在引号之间，添加星号或星号，例如
this. Now after the quotation and before the parenthesis, 这。现在在引号之后和括号之前，
add a space, once again, add an asterisk, 再加上一个空格，再加上一个星号，
space, 10. What is going on here? Well, 空间，10.这是怎么回事？出色地，
anywhere we have quotations like here or here 任何我们在这里或这里都有报价的地方
we're defining a string, a string is a programming term which means 我们正在定义一个字符串，字符串是一个编程术语，这意味着
a series of characters so here we have a string, we also have 一系列字符，所以在这里我们有一个字符串，我们也有
a string on line 3, as well as line 2 and line 1. 第3行，第2行和第1行的字符串。
Now here, we're multiplying the string by 现在在这里，我们将字符串乘以
number 10. So this is the multiplication operator, just like the multiplication 10。所以这是乘法运算符，就像乘法一样
operator we have in math. So with this piece of code we can 数学运算符。因此，通过这段代码，我们可以
draw 10 asterisks on the terminal, let me show you. So let's run this 在终端上画10个星号，让我告诉你。所以让我们运行
program one more time, there you go. So we have 10 再编程一次，就可以了。所以我们有10
asterisks. Now what we have here, this piece of code here, 星号。现在我们在这里，这段代码在这里，
is called an expression. An expression is a piece of 被称为表达式。表达是
code that produces a value. So when Python interpreter 产生值的代码。所以当Python解释器
tries to execute line 4, first it will evaluate 尝试执行第4行，首先它将评估
the code that we put in between parenthesis, so we could evaluate our expressions 我们在括号之间插入的代码，因此我们可以评估表达式
Our expression will produce 10 asterisks and then 我们的表达式将产生10个星号，然后
those asterisks will be printed on the terminal. Now as an exercise 这些星号将被打印在终端上。现在作为练习
you can use these print statements to draw another shape, you can draw a heart, a 您可以使用这些打印语句绘制其他形状，可以绘制心形，
ball, whatever you like. I will see you in the next tutorial. 球，随便你。我将在下一个教程中与您见面。
One of the questions I get a lot on my channel is 我在频道上遇到的很多问题之一是
how long does it take to learn Python and become job ready? Well there is no single 学习Python并准备工作需要多长时间？好吧，没有一个
answer. It really depends on you and how much effort and commitment you want to put 回答。这确实取决于您以及您要付出多少努力和投入
into this. But I would say if you spend 2 hours every day 到这个。但是我想说，如果您每天花费2个小时
consistently, after about 3 months you should be able to write 一致地，大约3个月后，您应该能够写
basic python programs, but quite honestly, that doesn't get you a job. 基本的python程序，但老实说，那并没有给您带来一份工作。
In order to get a job, you need to specialize in one area, 为了找到工作，您需要专注于一个领域，
what do you want to use python for? Do you want to build web applications or 您想使用python做什么？您要构建Web应用程序还是
desktop applications? Or do you want to use it in machine learning and artificial intelligence? 桌面应用程序？还是要在机器学习和人工智能中使用它？
So whatever you want to do you need to take additional courses. 因此，无论您想做什么，都需要参加其他课程。
For example if you want to become a web developer in addition to learning 例如，除了学习之外，您还想成为一名Web开发人员
Python, you should also learn about html, some css, some Python，您还应该了解html，一些CSS，一些
JavaScript and Django which is a popular Python framework JavaScript和Django，这是一个受欢迎的Python框架
for building web applications. Learning all these things would take you another 用于构建Web应用程序。学习所有这些东西会带你另一个
6 months, so in total you need 9-12 months to become 6个月，因此总共需要9-12个月
job ready. At that point you can get a junior developer job with a 准备工作。届时，您可以通过
salary of about 50-60 thousand dollars a year. Now as you work more 年薪约50-60千美元。现在，随着您的工作量增加
as you do more Python projects, your resume starts to build and 随着您执行更多的Python项目，您的简历开始建立并
you can ask for $100,000 a year, or 120,000 dollars 您可以每年索要100,000美元或120,000美元
a year, depending on where you are, what company, what geographical area, 一年，具体取决于您所在的位置，所从事的公司，所处的地理位置，
it really depends, there is no single answer. So are you excited to 这真的取决于，没有一个答案。所以你很高兴
learn Python and get started on this career path? If you are, I would encourage you 学习Python并开始这一职业道路？如果你是，我会鼓励你
to make a commitment and spend 2 hours every day practicing 做出承诺，每天花2个小时练习
python. And use the comment box below and let me know why you are learning Python。并使用下面的评论框，让我知道您为什么要学习
Python, what do you want to do with it? What's your dream job? I would love to hear your story. Python，您想使用它做什么？你理想的工作是什么？我很想听听你的故事。
In this Python tutorial, you're going to learn about variables, which are one of the most fundamental 在此Python教程中，您将学习变量，变量是最基本的变量之一
concepts in programming, they're not specific to Python, they exist 编程中的概念，它们不特定于Python，它们存在
in pretty much every programming language out there. We use variables 几乎所有的编程语言都可以。我们使用变量
to temporarily store data in a computer's memory. Here's an example, 将数据临时存储在计算机的内存中。这是一个例子
let's type price = 10, when Python 让我们键入价格= 10，当Python
interpreter executes this code, it will allocate some memory, then it will store 解释器执行此代码，它将分配一些内存，然后将其存储
the number 10 in that memory, and finally it will attach this 该内存中的数字10，最后它将附加此内容
price label in that memory location. As a metahor 该存储位置中的价格标签。作为元神
imagine we have a box. In that box, we have number 10 想象我们有一个盒子。在那个盒子里，我们有10
and price is the label that we put on the box. Now we can use this label 价格是我们在包装盒上贴的标签。现在我们可以使用这个标签
anywhere in our program to access the value that we have in that box. 程序中的任何位置以访问该框中具有的值。
This is a very simplified explanation. So now, let's 这是一个非常简化的解释。所以现在，让我们
print price on the terminal. Print, now this time we're not going to 在终端上打印价格。打印，现在这一次我们不打算
add quotations, because if we put quotations here, we will see the text 添加引号，因为如果我们在此处放置引号，我们将看到文本
price on the terminal. Now the value of the price variable. 终端上的价格。现在，价格变量的值。
So, put it in quotations, and type price, 因此，在报价中输入价格，
now, let's run this program one more time, there you go. So we see 10, 现在，让我们再运行一次该程序，然后运行。所以我们看到10
on the terminal. So this is how we define variables, we 在终端上。这就是我们定义变量的方式，我们
start with an identifier which is the name of our variable, then, 从标识符开始，它是我们变量的名称，然后，
an equal sign and finally a value. Now more accurately, when 一个等号，最后是一个值。现在更准确地说，何时
this number 10 is about to be stored in the memory, first it will 这个数字10将要存储在内存中，首先
get converted to this binary for presentation. So this number 10, 转换为该二进制文件以进行演示。所以这个数字10
is in the decimal system which has all the digits from 0 to 9. 在十进制系统中，该系统的所有数字都从0到9。
Computers don't understand all these digits, they only understand 电脑不了解所有这些数字，他们只了解
0s and 1s. So when we store the number 10 in the computer's memory 0和1。因此，当我们将数字10存储在计算机的内存中时
first it will get converted to it's binary representation which will be 首先将其转换为二进制表示形式，即
a bunch of 0's and 1's, like 001, 001, whatever 一堆0和1，例如001、001，无论
I don't know. Then it will get stored in the computer's memory. So, 我不知道。然后它将被存储在计算机的内存中。所以，
let's take this program to the next level. On the second line we can 让我们将此程序提升到一个新的水平。在第二行，我们可以
update the value of this price variable, so we can reset it 更新此价格变量的值，因此我们可以将其重置
to a new value like 20, now when we run our program, 设置为20之类的新值，现在当我们运行程序时，
we should see 20, because as I told you before Python interpreter executes our 我们应该看到20，因为正如我在Python解释器执行我们之前告诉您的那样
code line by line from the top. So first we set 代码从顶部一行一行。所以首先我们开始
the price to 10, then we reset it to 20, and finally we 价格设为10，然后将其重置为20，最后我们
print it on the terminal, let's run the terminal, there you go, so, 在终端上打印它，让我们运行终端，然后就可以了，所以，
we see 20 here, okay? Now these 我们在这里看到20，好吗？现在这些
numbers that we have here are whole numbers without a decimal point. 我们这里的数字是没有小数点的整数。
In programming, we refer to these numbers as integers. 在编程中，我们将这些数字称为整数。
But integer is a number without a decimal point. We can also use 但是整数是没有小数点的数字。我们也可以使用
numbers with a decimal point for example on line 2, we can define 在第2行，例如带小数点的数字，我们可以定义
another variable called rating and set it to number 另一个变量称为等级，并将其设置为数字
4.9. Now in programming, we refer to this kind of number as 4.9。现在在编程中，我们将这种数字称为
a floating point number of float for short. So we have integers 缩写为float的浮点数。所以我们有整数
and floats. We can also define a variable and set 并漂浮。我们还可以定义一个变量并设置
it to a string, for example, name equals 将其转换为字符串，例如，名称等于
Mosh, we also have another kind of value which is called boolean, 莫什（Mosh），我们还有另一种值，称为布尔值（boolean），
which can be true or false. They are line yes and no in English. 可以是对也可以是错。他们是英文的“是”和“否”。
Here is an example, I'm going to define a variable, is underline 这是一个例子，我要定义一个变量，下划线
published so we use an underscore to separate 已发布，因此我们使用下划线来分隔
multiple words in our variables name. We set this to 我们的变量名称中有多个单词。我们将其设置为
true, or false. These are 对或错。这些都是
boolean values. now note that Python is a case 布尔值。现在请注意，Python是一种情况
sensitive language, which means it's sensitive to lower case and upper case letters. 敏感语言，这意味着它对小写和大写字母敏感。
So when defining variables we should always use 因此，在定义变量时，我们应始终使用
lowercase letters, but here false and true are special keywords in the 小写字母，但此处的false和true是关键字中的特殊关键字
language, so if we spell it with a lowercase f, Python doesn't 语言，所以如果我们用小写的f拼写，Python不会
understand it. You can see we have a red underline here, which indicates an error. 明白它。您可以在此处看到红色下划线，表示有错误。
Make sure to spell this with a capital F, or if you want to set this to true, 请务必使用大写字母F进行拼写，或者如果要将其设置为true，
make sure the T is capital, so in this 确保T是大写字母，所以在此
program, you're storing simple values in our computer's memory. Simple 程序，您正在将简单值存储在我们的计算机内存中。简单的
values can be numbers, which can be integers or floats 值可以是数字，可以是整数或浮点数
or they can be strings or booleans. But in Python 或者它们可以是字符串或布尔值。但是在Python中
we can also store complex values like lists and values. And that's what I'm going to show you 我们还可以存储列表和值之类的复杂值。这就是我要告诉你的
in the future. So before going any further, I want you 将来。所以在继续之前，我要你
to do a little exercise. Imagine we're going to write a program for a hospital. 做一点运动。想象一下，我们要为医院编写一个程序。
So we check on a patient named John Smith. He's 因此，我们检查了一个名为约翰·史密斯的患者。他是
20 years old and is a new patient. I want you to define 3 variables here, 20岁，是一名新患者。我希望您在这里定义3个变量，
for his name, his age, and another variable 他的名字，他的年龄和另一个变量
for if this is a new or an existing patient. So pause the video and spend one 因为这是新患者还是现有患者。因此，暂停视频并花费一个
minute on this exercise. When you're done, come back, continue and see my solution. 此练习的分钟。完成后，请返回，继续查看我的解决方案。
Alright, so here we need 好了，所以在这里我们需要
three variables, the first one is the patient's name, 三个变量，第一个是患者的姓名，
we set that to John Smith. We can also 我们将其设置为约翰·史密斯。我们也可以
call this full name, these are both valid names for our variables. 叫这个全名，它们都是我们变量的有效名称。
The second variable is for the age of our patient. So age 第二个变量是针对我们患者的年龄。所以年龄
is 20, and finally we need a variable to tell if this is a new 是20，最后我们需要一个变量来判断这是否是新变量
or existing patient. That's where we can use a boolean value. 或现有患者。那是我们可以使用布尔值的地方。
So, we define a variable, is new and 因此，我们定义一个变量，它是新的，
we set it to true. 我们将其设置为true。
So, you have learned how to print 因此，您已经学会了如何打印
messages on the terminal window. In this tutorial, I'm going to show you how to 终端窗口上显示消息。在本教程中，我将向您展示如何
receive input from the user. So we're going to write a small program that asks 接收用户的输入。因此，我们将编写一个小程序，询问
the user's name and then we'll print a greeting message customized 用户名，然后我们将打印自定义的问候语
for that user. So instead of print we're going to use 对于该用户。因此，我们将使用印刷代替印刷
input. Now both these input and print 输入。现在，这些输入和打印
are functions that are built into Python. As a metaphor think 是Python内置的函数。隐喻地认为
of the remote control of the TV. On this remote control we have a bunch of 电视遥控器的功能。在这个遥控器上，我们有一堆
buttons, these are the functions built into your tv, you can turn it on, 按钮，这些是电视内置的功能，您可以将其打开，
turn it off, change the volume and so on. In Python we also have 将其关闭，更改音量等。在Python中，我们还有
functions for common tasks such as printing messages, receiving input, 常见任务的功能，例如打印消息，接收输入，
and so on. So we're going to use the input function, now whenever we 等等。所以我们现在要使用输入功能
have these parenthesis, we're going to say we're calling or executing 有这些括号，我们要说我们正在调用或执行
that function, it's like pressing a button on a remote control. So we're 该功能，就像按遥控器上的按钮一样。所以我们
going to call the input function and in between parenthesis 将在括号之间调用输入函数
we want to add a string to print something on the terminal, 我们想要添加一个字符串以在终端上打印一些内容，
what is your name? With a question mark followed by 你叫什么名字？后面跟一个问号
a space. You will see why in a second. So this input function 空间。一秒钟您会明白为什么。所以这个输入功能
will print this message on the terminal, and then it will wait for the user to 将在终端上打印此消息，然后它将等待用户
enter a value. Whatever the user enters this input function will 输入一个值。无论用户输入什么输入功能
return. So now we can get that value and store it in the memory using a variable. 返回。因此，现在我们可以获取该值，并使用一个变量将其存储在内存中。
So we get the result and put it in a variable called 所以我们得到结果并将其放在一个名为
name. Okay? Now on the second line 名称。好的？现在在第二行
we want to print a message like Hi John or Hi Mosh or whatever, so, 我们想打印一条消息，例如“ Hi John”或“ Hi Mosh”等
print, quotations Hi with a space, 打印，引号Hi带有空格，
now after the quotation we want to dynamically print 现在报价后，我们要动态打印
what we have in the name variable. So we had 我们在name变量中拥有什么。所以我们有
a plus sign and then name. So here we have 加号，然后命名。所以我们有
Hi which is a string, we're concatenating or 您好，这是一个字符串，我们正在串联或
combining the string with another string, that is what we have 将字符串与另一个字符串结合在一起，这就是我们所拥有的
in the name variable. So here's another example of 在名称变量中。所以这是另一个例子
an expression. Remember what is an expression? It's a piece of code that 一种表达。记住什么是表达？这是一段代码
uses a value. So this expression concatenates or combines 使用一个值。因此，此表达式串联或组合
2 strings. Let's run this program and see what happens. So run 2弦。让我们运行该程序，看看会发生什么。快跑
okay, here is a question, what is your name? Mosh, 好吧，这是一个问题，你叫什么名字？莫什
now note that earlier we added a space after the question mark, we 现在请注意，之前我们在问号后面添加了一个空格，
did this, so here in the terminal window the cursor is 这样做，所以在终端窗口中，光标是
separated from the question mark, otherwise it would be so close. So let's type 与问号分开，否则会非常接近。所以我们输入
whatever here, plus enter, now we get this message, Hi, Mosh. 无论在这里，再输入，现在我们都会收到此消息，嗨，莫什。
Now here's a little exercise for you. I want you to extend this program 现在，这里有个小练习。我要你扩展这个程序
and ask two questions. First all the person's name and then 并问两个问题。首先是所有人的名字，然后是
their favorite color. And then print a message like Mosh likes 他们最喜欢的颜色。然后像Mosh一样打印一条消息
blue. So pause the video, do this exercise and then come back and continue watching. 蓝色的。因此，暂停视频，进行此练习，然后再返回并继续观看。
Alright, so here's the first question right after that, 好吧，这是紧随其后的第一个问题，
all the input functions one more time, this time we're going to ask a different question. 所有输入功能又一次，这次我们要问一个不同的问题。
What is your favorite color? 什么是你最喜欢的颜色？
Now, we get the new value and store it in the variable 现在，我们获取新值并将其存储在变量中
called color, or you could call it favorite underline. 称为颜色，也可以将其称为“喜欢的下划线”。
color. Either works. And finally we're going to change 颜色。无论哪种。最后我们要改变
what we pass to the print function, so first we print the name 我们传递给打印功能的内容，所以首先我们打印名称
then we concatenate this with a string, here we're going to 然后我们用一个字符串将其连接起来，在这里我们要
type likes, we also put one space before and 类型喜欢，我们也将一个空格放在
after likes, and once again we concatenate this. 在点赞之后，我们再次将其连接起来。
With the favorite color. So, favorite color, 具有最喜欢的颜色。所以，最喜欢的颜色
now let's run this program, so what is your name 现在让我们运行该程序，那么你叫什么名字
Mosh enter, favorite color, blue, enter, 莫什（Mosh）输入，喜欢的颜色，蓝色，输入，
we get this message, Mosh likes blue. 我们收到此消息，Mosh喜欢蓝色。
Hey guys Mosh here, I just wanted to let you know that 嗨，Mosh，我只是想让你知道
you really don't have to memorize anything in this course because I've put together a cheat sheet 您在本课程中确实不需要记住任何内容，因为我整理了备忘单
with summary notes. So you can quickly review the materials in this course. 带有摘要注释。因此，您可以在本课程中快速查看材料。
The link is below this video. So I have done my best to create 链接在此视频下方。所以我尽力创造
the best possible Python course on Youtube. And I really appreciate YouTube上最好的Python课程。我真的很感激
it if you support my hard work by liking this video and sharing it with 如果您喜欢这部影片并与他人分享，以支持我的辛勤工作
others, so they can learn as well. And be sure to subscribe to my channel, for more 其他的，所以他们也可以学习。并且一定要订阅我的频道，以了解更多
tutorials like this. Alright, now, let's move onto the next tutorial. 这样的教程。好了，现在，让我们进入下一个教程。
In this Python tutorial, we're going to write a program that will ask the year that we were born 在此Python教程中，我们将编写一个程序来询问我们出生的年份
in, and then it will calculate our age and print it on the terminal. 输入，然后它将计算我们的年龄并将其打印在终端上。
So, let's start with our input function, input 因此，让我们从输入功能开始
let's print birth here, followed by a colon, 让我们在这里打印出生，然后是冒号，
and a space. Now let's get the return value and store it in a variable, 和一个空间。现在，让我们获取返回值并将其存储在变量中，
called birth_year. 称为birth_year。
So as I told you before, we use an underscore to separate multiple words 因此，正如我之前告诉您的，我们使用下划线分隔多个单词
Next, we need to calculate the age, so we define another 接下来，我们需要计算年龄，因此我们定义了另一个
variable called age, and here we do some basic math, 这个变量叫做age，在这里我们做一些基本的数学运算，
currently we are in 2019, so let's write an expression 目前我们在2019年，所以让我们写一个表达式
like this. 2019 - birth 像这样。 2019年-出生
year. Now finally let's print 年。现在终于让我们打印
age on the terminal. Let's run our program and see what happens. 终端上的年龄。让我们运行我们的程序，看看会发生什么。
So, my birth year is 1982, enter, 因此，我的出生年份是1982年，
oops, we got an error, what is going on here? So 糟糕，我们遇到了错误，这是怎么回事？所以
whenever you see this message, that means there is something wrong with your program. With the information 每当您看到此消息时，表明程序有问题。随着信息
here, we can find exactly where the error occurred. So, 在这里，我们可以找到错误发生的确切位置。所以，
next to the file you can see the file that generated this error, in this case 在文件旁边，您可以看到生成此错误的文件，在这种情况下
that is app.py. So 那是app.py。所以
currently our program only has a single file, but real complex programs often 当前我们的程序只有一个文件，但是实际的复杂程序经常
have hundreds or even thousands of files. So in this file, 拥有数百甚至数千个文件。所以在这个档案中
on line 2, this is where we got this error, and right 在第2行，这是我们收到此错误的地方，对
below that we can see the piece of code that generated this error. 在下面，我们可以看到生成此错误的代码段。
So that is where we're calculating the age, and right below 这就是我们计算年龄的地方，就在下面
that you can see the type of error. In this case, we have a type error, and here's the 您可以看到错误的类型。在这种情况下，我们遇到类型错误，这是
message. Unsupported operand types for 信息。不支持的操作数类型
subtraction. Int and str. 减法。 Int和str。
So int is short for integer and that represents a whole number 所以int是整数的缩写，代表整数
and str is short for string, so here we're subtracting 并且str是字符串的缩写，所以这里我们减去
a string from an integer, and Python doesn't know what to do with it. 一个来自整数的字符串，Python不知道如何处理它。
Let me explain. So I'm going to close the terminal window. So after 让我解释。所以我要关闭终端窗口。所以之后
the first line we executed we have this birth year variable set 我们执行的第一行有这个出生年份变量集
to a string, so whatever we type in the terminal is always 到一个字符串，所以我们在终端中键入的内容始终是
treated as a string, even if you type the number, in other words, 即使您输入数字，也将其视为字符串，
when we run this program, this birth year variable will be set 当我们运行该程序时，将设置该出生年份变量
to a string, with four characters. 到一个包含四个字符的字符串。
1982. This string is different from the actual number 1982年。此字符串与实际数字不同
1982. One is an integer and the other is a string. 1982。一个是整数，另一个是字符串。
Right? So, back to line 2, where this 正确的？所以，回到第二行
error occurred. At run time, which means when we run our program 错误发生。在运行时，这意味着我们在运行程序时
this expression on the right side of the assignment operator 此表达式位于赋值运算符的右侧
is going to look like this. 2019 - 看起来像这样。 2019-
string 1982. Python doesn't know how to 字符串1982。Python不知道如何
interpret or how to evaluate this expression. To fix this problem 解释或如何评估此表达式。解决此问题
we need to convert this 1982 into an integer 我们需要将此1982转换为整数
and then we'll be able to subtract it from 2019 and that 然后我们就可以从2019年减去它
is easy. So far you have learned about two built in functions 简单。到目前为止，您已经了解了两个内置函数
one is print the other is input. We have a few other functions 一个是打印，另一个是输入。我们还有其他一些功能
for converting values into different types. So we have 用于将值转换为不同的类型。所以我们有
int for converting a string into an integer, we also have 用于将字符串转换为整数的int，我们也有
float for converting a string into a float, or a number 浮点数，用于将字符串转换为浮点数或数字
with a decimal point. And we also have bool for converting a string 带小数点而且我们还有bool用于转换字符串
into a boolean value. So to fix this problem, 转换为布尔值。因此，要解决此问题，
we need to go back on line 2, 我们需要回到第2行
and pass this birth year variable to the int function like this. 并像这样将这个出生年份变量传递给int函数。
int parenthesis, like this 像这样的int括号
so we pass this string to the int function, int will convert it into an itneger 因此我们将此字符串传递给int函数，int会将其转换为itneger
and then Python interpreter will be able to evaluate this expression. 然后Python解释器将可以评估此表达式。
Now let's run this program one more time, so birth 现在让我们再运行一次该程序，这样诞生
year is 1982 enter so I am 1982年，所以我进入
37 years old. In Python we have a useful function 37岁。在Python中，我们有一个有用的功能
for getting the type of variables, for example, let's print the type 获取变量的类型，例如，让我们打印类型
of birth year, so right after line 1, 出生年份，所以在第1行之后
let's print, now here we're going to call another built in function, 让我们打印，现在在这里我们要调用另一个内置函数，
called type, and now let's pass birth 叫类型，现在让我们出生
year, okay, now similarly after line 年，好的，现在下线后也一样
3, let's also print the type of age, so 3，让我们也打印年龄的类型，这样
print type of age. 打印年龄类型。
Okay? So let's run our program, so birth year one more 好的？因此，让我们运行我们的程序，再过一个出生年
time, 1982, okay, here's the result 时间，1982年，好的，这是结果
so the type of birth year as you can see is a class 所以您可以看到出生年份的类型是一类
of str or strings, we look at classes in the future so 关于str或字符串，我们将来会研究类
for now don't worry about them, and also below them you cans ee the type of 现在不要担心它们，而且在它们下面，您可以查看
the age variable is int or integer. So 年龄变量是int或整数。所以
here's what you need to take away. Whenever you use the input function, 这是您需要带走的东西。每当您使用输入功能时，
you always get a string, so if you're expecting a numerical value 您总是会得到一个字符串，所以如果您期望一个数字值
you should always convert that string into an integer or 您应该始终将该字符串转换为整数或
a float. So here's a little exercise for you. I want you to write a program 浮动。因此，这是适合您的一些练习。我要你写一个程序
ask the user their weight and then convert it to kilograms and print it 向用户询问其重量，然后将其转换为千克并打印
on a terminal. So pause the video, do the exercise and when you're ready come back 在终端上。因此，暂停视频，进行练习，当您准备好后再回来
to watch it. 观看它。
Alright so let's use our input function and ask 好了，让我们使用输入功能并询问
for the weight in pounds 以磅为单位的重量
here we get the weight in lbs or pounds 在这里，我们得到的重量以磅或磅为单位
now we need to convert this into kilograms, it's very easy so 现在我们需要将其转换为公斤，这很容易
we defined another variable weight_kg 我们定义了另一个变量weight_kg
we set this to weight_lbs 我们将其设置为weight_lbs
times 0.45. 乘以0.45。
And finally let's print weight underline 最后让我们打印下划线
kg. Let's run this Python program and see what happens. So 公斤。让我们运行这个Python程序，看看会发生什么。所以
my weight is 160, alright once again we got an error, 我的体重是160，好吧，我们再次遇到错误，
can't multiply sequence by non int of type 无法将序列乘以非int类型
float. So as I told you before, this input function returns 漂浮。因此，正如我之前告诉您的那样，此输入函数将返回
a string, so we cannot multiply a string by a float. 字符串，因此我们不能将字符串乘以浮点数。
Python doesn't know what to do with it. So in this case, we should convert this number Python不知道如何处理它。所以在这种情况下，我们应该转换这个数字
by an integer or float and then multiply by 0.45. 乘以整数或浮点数，然后乘以0.45。
So let's call the int function. 因此，我们将其称为int函数。
And pass weight underline lbs. 并通过重量下划线磅。
And run our program one more time, 160 并再次运行我们的程序160
okay, so I am 72 kg's. 好吧，所以我是72公斤重。
In this tutorial, you're going to learn more about Python strings. 在本教程中，您将学习有关Python字符串的更多信息。
So I've defined this course variable and set it to Python for beginners 因此，我已经定义了此课程变量，并将其设置为适用于初学者的Python
now earlier I told you you could use both single and double quotes 现在早些时候，我告诉过您您可以同时使用单引号和双引号
to define a string, but there are times you have to use a specific form, 定义一个字符串，但是有时您必须使用特定的形式，
otherwise you're going to run into issues. Here's an example. Imagine you wanted to 否则，您将遇到问题。这是一个例子。想象一下你想
change this string into Pythons course for Beginners. 将此字符串更改为Python入门课程。
So we want to add an apostrophe, like this, 所以我们想要添加一个单引号，像这样，
Course for Beginners. You can immediately say this is going 初学者课程。您可以立即说这是要去的
crazy, because our string starts here and then terminates here, 疯狂，因为我们的字符串从此处开始，然后在此处终止，
all these characters that we have here after the second apostrophe 在第二个撇号之后，我们在这里拥有的所有这些字符
Python interpreter doesn't know what they are. So to solve this problem Python解释器不知道它们是什么。所以要解决这个问题
we need to use double quotes to define our string so we can have 我们需要使用双引号定义我们的字符串，以便我们可以
a single quote in the middle of the string. So let's change this 字符串中间的单引号。所以我们改变一下
to double quotes, now you can see it adds another double quote to close it, 双引号，现在您可以看到它添加了另一个双引号以将其关闭，
you have to manually remove this, and also one more time 您必须手动删除它，并且还要再删除一次
at the beginning of the string, we need to add another double quote. Now 在字符串的开头，我们需要添加另一个双引号。现在
you can see error is gone, so if you print course 您可以看到错误消失了，所以如果您打印课程
we see Python course for beginners. 我们看到了面向初学者的Python课程。
Beautiful. Now let's say we don't want this apostrophe here, so we have 美丽的。现在说我们不想在这里撇号，所以我们有
Python for Beginners, but we want to put Beginners in 适用于初学者的Python，但我们希望将初学者放在
double quotes. Once again, if you add a double quote here Python interpreter gets 双引号。再一次，如果您在此处添加双引号，Python解释器将
confused because it assumes the second double quote indicates that 感到困惑，因为它假定第二个双引号表示
end of the string, so it doesn't know what these characters are, so to solve this 字符串的末尾，所以它不知道这些字符是什么，所以要解决这个问题
we need to change our double quotes to single quotes 我们需要将双引号更改为单引号
like this. And then we can add double quotes in the middle 像这样。然后我们可以在中间添加双引号
of the string. Now let's run this program, there you go. 的字符串。现在，让我们运行此程序，就可以了。
So we get Python for Beginners. So these are the cases 因此，我们获得了适用于初学者的Python。所以这些情况
for using single or double quotes. Now in all the examples 用于使用单引号或双引号。现在在所有示例中
I've shown you so far we only deal with short strings, but what if you wanted to define 到目前为止，我已经向您展示了我们仅处理短字符串，但是如果您想定义
a string that is multiple lengths? For example, what if you wanted to define a string 多个长度的字符串？例如，如果您想定义一个字符串怎么办
for the message that we send in an email. In that case we need to use 用于我们通过电子邮件发送的消息。在这种情况下，我们需要使用
triple quotes. So. We delete this. 三重引号。所以。我们删除它。
Now we add three quotes, so 1, 2, 3, there you go, 现在我们加上三个引号，所以1、2、3就可以了，
So, we have three quotes to start our string and three 因此，我们有三个引号来开始我们的字符串和三个
to terminate it. Again these quotes can be single or double quotes. 终止它。同样，这些引号可以是单引号或双引号。
Okay? Now, with this we can define a string that spans 好的？现在，我们可以定义一个跨越
multiple lines. For example, we can say Hi Jon 多行。例如，我们可以说嗨乔恩
here is our first email to you. Thank you, 这是我们给您的第一封电子邮件。谢谢，
The Support Team. Like that. 支持团队。像那样。
Now, let's run this program and here's the 现在，让我们运行该程序，这是
result. So, we get this beautiful multi line 结果。因此，我们得到了一条漂亮的多线
string. Now let's change this back to something simple 细绳。现在让我们将其更改回简单的内容
so, we can look at other characteristics of strings and Python. 因此，我们可以看看字符串和Python的其他特征。
So I'm going to use single quotes and set the course name to Python 所以我将使用单引号并将课程名称设置为Python
for Beginners. Now here we're going to use square 对新手而言。现在在这里我们将使用正方形
brackets to get a character and a given index in this string. 括号以获取字符和该字符串中的给定索引。
Let me show you. So to get the first character we use square brackets 让我演示给你看。因此，要获取第一个字符，请使用方括号
and type 0. So the index of the first character 并输入0。因此第一个字符的索引
in the string is 0. In other words, this is how Python 在字符串中是0。换句话说，这就是Python
strings are indexed. 0, 1, 2, 3, 4, etc. 字符串被索引。 0、1、2、3、4等。
So the index of the first character is 0, the second character is 所以第一个字符的索引是0，第二个字符的索引是
1, and so on. So let me delete this and run this program 1，依此类推。所以让我删除它并运行该程序
we get p. We can also use a negative 我们得到p。我们也可以使用负数
index here. And this is one of the features that we don't have in other programming languages 在这里索引。这是我们其他编程语言所没有的功能之一
as far as I know. So we have negative index we can get the characters 我所知道的。所以我们有负索引我们可以得到字符
started from the end. So if I pass negative 1 here, 从头开始。因此，如果我在此处传递负数1，
Assuming that 0 is the index of the first character 假设0是第一个字符的索引
negative 1 is the index of the last character. So when we run 负1是最后一个字符的索引。所以当我们跑步
this program we should see s. Let's run it, there you go, 这个程序我们应该看到s。让我们运行它，到那里，
we get s, if we pass negative 2, this will return 我们得到s，如果我们传递负数2，则将返回
the second character from the end. Let's run it one more time, 从结尾开始的第二个字符。让我们再运行一次，
now we get R because that is the second character from the end. 现在我们得到R，因为那是末尾的第二个字符。
Okay? So place close attention to this square brackets syntax 好的？因此，请密切注意此方括号语法
because quite often it's the topic for online Python tests 因为它经常是在线Python测试的主题
or university exams, so if you're preparing for a python test, 或大学考试，因此，如果您准备进行python测试，
make sure to watch this tutorial one more time and understand exactly how 确保再看一遍本教程，并确切地了解如何
this square brackets syntax works, we can also use a similar 这个方括号的语法有效，我们也可以使用类似的
syntax to extract a few characters instead of 1 character. 语法提取几个字符而不是1个字符。
For example, if we type 0, 例如，如果我们输入0，
colon 3, Python interpreter will return all the characters 冒号3，Python解释器将返回所有字符
starting with this index all the way to this 从这个索引一直到这个
second index, but it does not return the character at this index. 第二个索引，但它不返回该索引处的字符。
In other words, back to these indexes 换句话说，回到这些索引
so you have 0, 1, 2, 3, and so on. When you run this program. 所以您有0、1、2、3，依此类推。当您运行此程序时。
Python interpreter will return the characters starting from the Python解释器将返回从
index 0 all the way to index 3, 从索引0一直到索引3，
but excludes the character and index 3, 但不包括字符和索引3，
so when we run this Python program we're going to see pint (?). Let me show you, so we're going to 因此，当我们运行此Python程序时，我们将看到品脱（？）。让我告诉你，所以我们要
delete this line, run this program, there you go. 删除此行，运行此程序，就可以了。
We get pint. Now here we also have default values for 我们品脱。现在我们在这里也有默认值
the start and end index. So if we don't supply 开始和结束索引。所以如果我们不供应
the end index, Python will return all the characters to the end of the string. 结束索引，Python会将所有字符返回到字符串的末尾。
Let's take a look. So run this program, there you go, 让我们来看看。因此，运行此程序，就可以了，
Python for Beginners. But if you change the start index to 1, 适用于初学者的Python。但是，如果您将开始索引更改为1，
this will exclude the first character so when we 这将排除第一个字符，所以当我们
run this program, we see ython so p is removed. 运行该程序，我们看到ython，所以p被删除了。
Okay? Now similarly we have a default value for the 好的？现在类似地，我们为
start index, so if we don't supply the start index 起始索引，所以如果我们不提供起始索引
but add an end index like 5. Python interpreter will assume 但要添加一个结束索引（如5）。Python解释器将假定
0 as the start index, so, let's run 0作为开始索引，所以让我们运行
this program, there you go, we get pytho. 这个程序，你去了，我们得到了pytho。
Now what if we leave both the start and end 现在，如果我们同时离开起点和终点
index? Well, I told you? Now in this case 0 will be assumed 指数？好吧，我告诉过你？现在，在这种情况下，将假定为0
as the start index, and the length of the string will assume 作为起始索引，字符串的长度将采用
as the end index. So with this syntax, you can basically copy 作为结束索引。因此，使用这种语法，您基本上可以复制
or clone a string. In other words, if I define 或克隆一个字符串。换句话说，如果我定义
another variable here, let's call it another and set it to course 这里有另一个变量，让我们将其称为“另外一个”并将其设置为“ course”
square brackets with just a colon, now this expression will 方括号只有一个冒号，现在此表达式将
return all the characters in the course variable so 返回课程变量中的所有字符，因此
variable will be copy of our first variable. Let's take a look, so, 变量将是我们第一个变量的副本。让我们看一下，
let's print another, and load our 让我们打印另一个，然后加载我们的
program there you go, we get Python for beginners. So once again 程序，您可以使用Python，适合初学者使用。所以再说一次
the square bracket syntax is pretty important if you're preparing for online 如果您正在准备在线，则方括号语法非常重要
python tests, or college exams, make sure to watch this tutorial again. python测试或大学考试，请确保再次观看本教程。
Now here's a little exercise for you. I'm going to delete all this code 现在，这里有个小练习。我要删除所有这些代码
define a variable, called name, and set it to Jennifer. 定义一个名为name的变量，并将其设置为Jennifer。
Now when we print name 现在当我们打印名称时
of 1: negative 1 之1：负数1
what do you think we're going to see on the terminal? I want you to use your knowledge 您认为我们将在终端上看到什么？我要你用你的知识
to tell what we're going to see on the terminal, we're now running this program. So 为了告诉我们要在终端上看到的内容，我们现在正在运行此程序。所以
pause the video, think about it for a few seconds, then come back and continue watching. 暂停视频，考虑几秒钟，然后再返回并继续观看。
So this expression will return the characters starting from 因此，此表达式将返回从
index 1 which is the second character 索引1，它是第二个字符
all the way to the first character from the end, but excluding 从头到尾一直到第一个字符，但不包括
the character at this index. In this case, the first character from the 此索引处的字符。在这种情况下，
in is r, so r will be excluded, in other words we're going to see in是r，因此r将被排除，换句话说，我们将看到
all the characters starting from e all the way 所有从e开始的字符
to the second e. Let's take a look. So I'm going to run this program 到第二个e。让我们来看看。所以我要运行这个程序
there you go. This is what we get, 你去。这就是我们得到的，
I hope you guessed it right. 我希望你猜对了。
In this tutorial, we're going to look at 在本教程中，我们将研究
formatted strings in Python programming language. Formatted strings are 用Python编程语言格式化的字符串。格式化的字符串是
particularly useful in situations where you dynamically generate some 在您动态生成一些内容的情况下特别有用
text with your variables. Let me show you. Let's say we have two variables 文本与您的变量。让我演示给你看。假设我们有两个变量
first name and last name. So first we set this to 名和姓。所以首先我们将其设置为
John, and last we set this to Smith. Now it's better 约翰，最后我们将其设置为史密斯。现在更好了
to call these variables first name and last name, because they're more 称这些变量的名字和姓氏，因为它们更多
descriptive. But here I'm using shorter names because I want you to see the entire code on display 描述性的。但是这里我使用的是较短的名称，因为我希望您看到显示的整个代码
screen. So let's say with these two variables, we want to generate 屏幕。因此，假设我们要使用这两个变量来生成
some text like this. Jon, in square brackets 一些这样的文字。乔恩，放在方括号中
Smith is a coder. Let's say we want to print this on 史密斯是一位编码员。假设我们要在上面打印
the terminal. How do we do this? Well, we define another variable 终点站。我们如何做到这一点？好吧，我们定义另一个变量
like message, now here we add the first name, 像消息一样，现在我们在这里添加名字，
now we need to concatenate this, with a string that contains a space 现在我们需要用一个包含空格的字符串将其连接起来
and a square bracket next we need to add a last name, 接下来是方括号，我们需要添加一个姓氏，
then we need to add a string that contains 那么我们需要添加一个包含以下内容的字符串
the closing square brackets followed by is a coder 右方括号后跟是编码器
okay? So, then, 好的？所以呢
if you print message and run this program 如果您打印消息并运行该程序
to see John Smith is a coder, right? Now, 看到约翰·史密斯（John Smith）是一名编码员，对吗？现在，
while this approach perfectly works, it's not ideal 尽管此方法可以完美工作，但并不理想
because as our text gets more complicated it becomes harder to 因为随着我们的文字变得越来越复杂，它变得越来越难
visualize the output. So someone else reading this code, they have to 可视化输出。所以其他人在阅读这段代码时，他们必须
visualize all the string concatenations in their head. This is where we use 可视化其头部中的所有字符串连接。这是我们使用的地方
formatted strings, they make it easier for us to visualize the output. So, 格式化的字符串，它们使我们更容易可视化输出。所以，
I'm going to define another variable, let's say 我要定义另一个变量，假设
msg short for message, and set this to a formatted string. A formatted msg消息的简称，并将其设置为格式化的字符串。格式化的
string is one that is prefixed with an f. So f, 字符串是一个以f开头的字符串。所以，
quotes. Now in between the quotes, first we want to add 引号。现在在引号之间，首先我们要添加
the value of the first name variable, so, 名字变量的值，所以，
we add curly braces and here we type first. 我们添加花括号，然后在这里首先键入。
Next we add a space, we add our square brackets, in between the square 接下来，我们在正方形之间添加一个空格，并添加方括号
brackets, we want to display the last name so once again we add curly 方括号，我们要显示姓氏，所以我们再次添加大写
braces, and type last, and finally here we type 花括号，最后键入，最后在这里键入
is a coder. So this is what we call the formatted 是一个编码器。这就是我们所说的格式化
string. With these curly braces, we're defining place holders 细绳。通过这些花括号，我们可以定义占位符
or holes in our string, and when we run our program these holes 或字符串中的孔，当我们运行程序时，这些孔
will be filled with the value of our variables. So here we have two place holders 将充满我们的变量的值。所以这里有两个占位符
or two holes in our string. One is for the value of our first name 或我们弦上的两个孔。一个是为了我们名字的价值
variable and the other is for the value of the last name variable. 变量，另一个用于姓氏变量的值。
But compare this formatted string with string 但是将此格式化的字符串与字符串进行比较
concatenation. With this formatted string we can easily visualize 级联。使用此格式化的字符串，我们可以轻松地可视化
what the output looks like, right? Now let's print this other 输出是什么样的，对不对？现在让我们将其打印出来
terminal to make sure we get the same exact output. So, let's print message 终端，以确保我们得到相同的确切输出。所以，让我们打印消息
there you go. So Jon 你去。所以乔恩
Smith is a coder. So to define formatted strings, 史密斯是一位编码员。因此，要定义格式化的字符串，
prefix your strings with an F and then use curly braces 给字符串加上F前缀，然后使用花括号
to dynamically insert values into your strings. 在字符串中动态插入值。
In this Python tutorial, I'm going to show you some really cool things you can do with Python 在本Python教程中，我将向您展示可以使用Python进行的一些非常酷的操作
strings. So let's start by defining a variable, 字符串。因此，让我们开始定义一个变量，
course and we set that to Python for 当然，我们将其设置为Python
beginners. Now to calculate the number 初学者。现在计算数字
of characters in this string, you can use a built in function called len. 对于此字符串中的字符，您可以使用一个称为len的内置函数。
So len we give it this course variable, and then, 因此，len给我们提供了此课程变量，然后，
we can print the result. Let's run this program, 我们可以打印结果。让我们运行这个程序，
so as you can see we have 20 characters in this string, this is 如您所见，该字符串中有20个字符，这是
particularly useful when you receive input from the user. For example you have 当您从用户那里收到输入时特别有用。例如你有
noticed that when you fill out a form online, each input field 注意到当您在线填写表格时，每个输入字段
often has a limit. For example, you might have 50 characters for your name, 通常有一个限制。例如，您的名字可能有50个字符，
so using this len function we can enforce a limit on the number of characters 因此，使用此len函数，我们可以限制字符数
in an input field. If the user types in more characters than we allow, 在输入字段中。如果用户输入的字符超出了我们的允许范围，
we can display an error, now, this, 我们现在可以显示一个错误，
len function is another function built into Python, it's len函数是Python内置的另一个函数，它是
a general purpose function, so it's not limited to counting the number of characters in a 通用函数，因此它不限于计算字符中的字符数
string, in the future when we look at lists, I want to show you that we can use this 字符串，将来我们查看列表时，我想向您展示我们可以使用此字符串
function to count the number of items in a list. So it's a general purpose 函数计算列表中的项目数。所以这是通用的
function. Now we also have functions specifically for strings 功能。现在我们还有专门针对字符串的功能
for example we have functions for converting all these characters to upper case 例如，我们具有将所有这些字符转换为大写字母的功能
or lower case. To access these functions we use the dot operator. 或小写。要访问这些功能，我们使用点运算符。
let me show you. So first we type course, 让我演示给你看。所以首先我们输入课程
then dot look these are all the functions 然后点一下，这些都是功能
that are specific to strings. Now in more accurate terms, 特定于字符串。现在更准确地说，
you refer to these function as methods, this is a term 您将这些功能称为方法，这是一个术语
in object oriented programming that we want to look at in the future, but for now, what I want you to take away, 在将来我们要研究的面向对象编程中，但就目前而言，我希望您能从中受益，
is that when a function belongs to something else, or is specific 是当一个函数属于别的东西或者是特定的
to some kind of object, we refer to that function as a method. 对于某种对象，我们将该函数称为方法。
For example, here we have this function, upper, for converting the string 例如，这里我们有一个函数upper，用于转换字符串
into upper case, now more accurately because this function 转换为大写字母，现在更准确了，因为此功能
is specific to a string, we refer to this as a method. In contrast 是特定于字符串的，我们将其称为方法。相比之下
len and print are general purpose functions, they don't belong len和print是通用函数，它们不属于
to strings or numbers or other kinds of objects. 字符串，数字或其他类型的对象。
So this is the difference between functions and methods. Now let's take look at this 这就是函数和方法之间的区别。现在让我们来看一下
upper method. So, let's print the results 上层方法。所以，让我们打印结果
and we run our program, there you go, 然后我们运行我们的程序，就可以了，
you get all these characters displayed in uppercase. Now note this method 您将所有这些字符显示为大写。现在注意这种方法
does not change or modify our original string, in fact 实际上不会更改或修改我们的原始字符串
it creates a new string and returns it. So, 它创建一个新字符串并返回它。所以，
if we print our course variable right after we 如果我们在完成后立即打印课程变量
call the upper method, we can see that our course variable still 调用上层方法，我们可以看到我们的课程变量仍然
has it's original form, so let's run this program one more time, there you 具有原始格式，因此让我们再运行一次该程序，在那里
go. Look, here is our original course variable, it's not modified. 去。看，这是我们原来的课程变量，它没有被修改。
Now similar to the upper method we have another method 现在类似于上层方法，我们有另一种方法
for converting a string into lower case. So let me show you. 用于将字符串转换为小写。所以让我告诉你。
Print, course.lower. 印刷，当然。
Now, let's run the program, so on the second line you can see, 现在，让我们运行程序，在第二行，您可以看到，
all characters are in lower case. Now there are times 所有字符均小写。现在有些时候
that you want to find a character or a sequence of characters in a string. 您想要在字符串中查找一个字符或一系列字符。
In those situations you can use the find method. So let me delete 在这种情况下，您可以使用find方法。所以我删除
these few lines. Call course. 这几行。通话过程。
find here we pass a character, let's say 在这里找到一个字符，让我们说
p, and this will return the index of the first occurrence p，这将返回第一个匹配项的索引
of that character, let me show you. So let's print the result 那个角色，让我告诉你。因此，让我们打印结果
we get 0, because the 我们得到0，因为
index of the first capital p in the string is 0. 字符串中第一个大写字母p的索引为0。
As another example, if we pass a lower case o here, 再举一个例子，如果我们在此处传递小写字母o，
let's see what we get, we get 4 because 让我们看看我们得到什么，我们得到4，因为
the index of this o here is 4. Now note that the 这个o的索引在这里是4。现在请注意，
find method is case sensitive, so it's sensitive to find方法区分大小写，因此对
lower case and and upper case characters. As an example if you pass an upper case 小写和大写字符。例如，如果您通过大写
here and run this program, we get negative 1 because 在这里运行该程序，我们得到负1，因为
we don't have an upper case o anywhere in this string, okay? 我们在此字符串的任何地方都没有大写字母o，好吗？
We can also pass a sequence of characters, for example, we can pass 我们还可以传递一系列字符，例如，我们可以传递
beginners with a capital B 初学者用大写字母B
let's run this program, we get 11 because 让我们运行该程序，我们得到11，因为
beginners starts with index 11, now we 初学者从索引11开始，现在我们
also have method for replacing a character or a sequence of characters 也有替换字符或字符序列的方法
and that is called replace. So let's change find 这就是所谓的替换。所以我们换找
to replace let's say we want to replace beginners with 替换，假设我们要替换为初学者
absolute beginners, so we add a comma to pass a second value 绝对的初学者，所以我们添加一个逗号以传递第二个值
to this function, or more accurately this method. We add a string, 此功能，或更准确地说是此方法。我们添加一个字符串，
here I'm going to pass absolute beginners. 在这里，我将通过绝对的初学者。
Okay, now let's run this program, 好的，现在让我们运行该程序，
so, we get python for absolute beginners. 因此，我们为绝对的初学者准备了python。
Again, this method like the find method is case sensitive so 同样，此方法（如find方法）区分大小写，因此
if you pass beginners all in lowercase, this method is 如果您全部以小写形式通过初学者，则此方法为
not going to find this exact word in our string, so it's not going to 不会在我们的字符串中找到这个确切的单词，所以它不会
place it with absolute beginners. Let's take a look. So I'm going to run the program 将其与绝对初学者一起使用。让我们来看看。所以我要运行程序
One more time, look, we still get python for beginners. 再看一次，我们仍然为初学者提供python。
We can also replace a single character, for example we can replace 我们还可以替换单个字符，例如，我们可以替换
capital p with let's say capital 大写p与假设大写
j. Now when we run this program we get j。现在，当我们运行该程序时，我们得到
jython for beginners. So these are the find and replace methods jython，适合初学者。这些是查找和替换方法
and one last things I want to show you in this tutorial. There are 最后，我想在本教程中向您展示。有
times that you want to check the existence of a character or sequence of characters in your 您想检查一个字符或字符序列是否存在的次数
string. In those situations you use the in operator, 细绳。在这种情况下，您可以使用in运算符，
so let's say you want to know if this string contains the word python. 因此，假设您想知道此字符串是否包含单词python。
We can write an expression like this. String 我们可以这样写一个表达式。细绳
python space in space course. 太空课程中的python space。
So we're checking to see if python is in 因此，我们正在检查python是否在其中
course variable. And this is an expression that produces a boolean 课程变量。这是一个产生布尔值的表达式
value, and I get true or false, so we refer to this expression 值，我会得到对或错，所以我们引用此表达式
as a boolean expression, now if we print this on the terminal, 作为布尔表达式，现在，如果我们在终端上打印它，
we should get true, and by the way 我们应该做到正确，顺便说一句
I'm going to delete the second line, we don't need it anymore, so run the program 我将删除第二行，我们不再需要它，因此运行程序
we get true, but if I change this capitol p to a lower case 我们是正确的，但是如果我将国会大厦p更改为小写
p and run the program we get false because we don't have p并运行该程序，因为我们没有
is exact sequence of characters in our strings. 是我们字符串中字符的确切顺序。
Now note that the difference between the in operator and the find method 现在注意in运算符和find方法之间的区别
is that our find method returns the index of 是我们的find方法返回的索引
character or sequence of characters but the in operator 字符或字符序列，但使用in运算符
produces a boolean value. Do we have this or not? 产生一个布尔值。我们有这个吗？
So that's the difference. Now let's recap all the cool things you learned 这就是区别。现在，让我们回顾一下您学到的所有很棒的东西
to do with strings in this tutorial. We can use the len function 与本教程中的字符串有关。我们可以使用len函数
to count the number of characters in a string, this is the general 计算字符串中的字符数，这是常规的
purpose function built into python, we also have specific functions python中内置的用途函数，我们还具有特定的功能
for strings which we refer to as methods, these include 对于我们称为方法的字符串，包括
upper for converting a string into uppercase 用于将字符串转换为大写的上
you also have lower and title methods, 你也有较低的和标题的方法，
you learn about the find method which returns the index 您将了解返回索引的find方法
of a character or sequence of characters, we have 一个字符或一个字符序列，我们有
the replace method for replacing characters and words in a string and finally 最后替换字符串中的字符和单词的替换方法
you learned about the in operator. So some characters 您了解了in运算符。所以有些字符
in a string. 在一个字符串中。
So, you have learned that in Python programming language you have 2 因此，您已经了解到，在Python编程语言中，您有2
types of numbers, integers which are whole numbers like 10, they don't have 数字类型，整数是整数，例如10，它们没有
a decimal point, and floating point numbers or floats. 小数点和浮点数或浮点数。
Which are numbers with a decimal point. Now in this tutorial you're going to look 是带小数点的数字。现在，在本教程中，您将要看
at the arithmetic operations supported in python language these are the 在python语言支持的算术运算中，这些是
same arithmetic operations that we have in math, we can add numbers, 我们在数学中有相同的算术运算，我们可以加数字，
multiply them and so on. So let's look at a few examples, 将它们相乘，依此类推。因此，让我们看几个例子，
we can print, 10 plus 3, so 我们可以打印10加3，所以
this is the addition operator, we also have subtraction, we 这是加法运算符，我们也有减法，我们
have multiplication, we have two kinds of division, 有乘法，我们有两种除法，
here's one with a forward slash, let's run this program and see what we get. 这是一个正斜杠，让我们运行该程序，看看会得到什么。
we get a floating point number. But we also have 我们得到一个浮点数。但是我们也有
another division operator for getting an integer. So 另一个除法运算符，用于获取整数。所以
if we add another slash here and run this program 如果我们在此处添加另一个斜杠并运行该程序
we get an integer. We have 我们得到一个整数。我们有
another operator called modulis (?) which is a percent sign. 另一个名为modulis（？）的运算符，它是一个百分号。
And this returns the remainder of the division. So when we run this program 这将返回除法的其余部分。所以当我们运行这个程序
we should get 1, there you go. And 我们应该得到1，到那里去。和
one last operator we have here is exponent which is the power. 我们在这里拥有的最后一个运算符是幂。
So, that is indicated with 2 asterisks and this will return 因此，用2个星号表示，它将返回
10 to the power of 3. So let's run this program 10乘以3的幂。因此，让我们运行该程序
we get 1000 so these are the arithmetic operators 我们得到1000，所以这些是算术运算符
in python programming language. Now for all these operators that you learned 用python编程语言编写。现在，对于您了解的所有这些运算符
we have an augmented assignment operator. That is 我们有一个增强的赋值运算符。那是
very useful, let me show you. So let's say we have a variable 非常有用，让我告诉你。假设我们有一个变量
called x we set it to 10, now we want to increment this by 称为x，我们将其设置为10，现在我们想将其增加
3, we'll have to write code like this. X we set this to 3，我们必须编写这样的代码。 X我们将其设置为
x plus 3. So Python interpreter will add x plus3。因此Python解释器将添加
10 to 3, the result is 13, and then it gets stored 10到3，结果是13，然后将其存储
into x again. So when we print x we should see 再次变成x。因此，当我们打印x时，我们应该看到
13, there you go. So this is how you can increment 13，你去。所以这就是你可以增加的方式
a number, right? Now augmented assignment operator is 一个数字，对不对？现在，扩充的赋值运算符是
a way to write the same code but in a shorter form. This 一种写相同代码但形式更短的方法。这
is how it works. We type x plus 它是如何工作的。我们输入x加号
equals 3. What we have on line 3 is exactly 等于3。我们在第3行上的内容恰好是
like what we have on line 2. So this is what we call 就像我们第2行上的内容一样。这就是我们所说的
the augmented assignment operator we have augmented or 我们已经扩充的扩充后的赋值运算符，或者
enhanced the assignment operator. Now in this particular 增强了赋值运算符。现在特别
case we are incremented a number using the augmented assignment operator, 如果我们使用扩展赋值运算符将数字递增，
but we can also subtract or multiply a number by a given value 但我们也可以将数字减去或乘以给定值
for example, let's delete what we have on line 2, 例如，让我们删除第2行上的内容
we can type subtract equals 3. So here we 我们可以输入等于3的减法。
subtracted 3 from x. When we run this program we should see 7, 从x减去3。当我们运行该程序时，我们应该看到7，
there you go. 你去。
Now let me ask you a question, I'm going to clear all this code here to 现在让我问一个问题，我将在这里清除所有这些代码
define x and set it to 10 plus 3 定义x并将其设置为10加3
times 2. What do you think is the result of this expression? 时代2.你认为这个表达的结果是什么？
this is a very basic math question that unfortunately a lot of people fail to answer. 不幸的是，这是一个非常基本的数学问题，很多人未能回答。
The answer is 16. Because in math we have this 答案是16。因为在数学中我们有这个
concept called operator precedence which means the order of 称为运算符优先级的概念，它表示
operations. So the multiplication operator has 操作。所以乘法运算符有
a higher precendence which means it's applied first which means 3 x 更高的优先级，这意味着它首先被应用，这意味着3 x
2 is executed first, the result is 6 and then 首先执行2，结果为6，然后执行
its added to 10, that's why x showed up as 16 after 它加到10，这就是为什么x在之后显示为16的原因
we run this code, let's verify that. So, print x 我们运行此代码，让我们验证一下。因此，打印x
run the program, x is 16. So this is what we call 运行该程序，x为16。这就是我们所说的
operator precedence, it's just a basic math concept. 运算符优先级，这只是一个基本的数学概念。
It's not about python programming language. So all the other programming languages 它与python编程语言无关。所以所有其他编程语言
behave the same way, so here's the order, first we have 行为相同，所以这是顺序，首先我们有
the exponentiation which is the power, like 2 to the power of 3, 幂就是幂，例如2乘以3的幂，
then we have multiplication or division 然后我们有乘法或除法
and finally we have addition or subtraction. 最后我们有加法或减法。
This is the order of operations. Let me show you another example. 这是操作顺序。让我向您展示另一个示例。
Here I'm going to add the exponentiation operator, so, 在这里，我要添加指数运算符，因此，
2 to the power of 2. Once again, what do you 2乘以2的幂。
think is the result of this expression? Pause the video and think about it for a few seconds. 认为这是表达的结果吗？暂停视频，然后考虑几分钟。
The answer is 22. 答案是22。
Because the exponentiation operator takes precedence, so first 因为幂运算符优先，所以首先
2 to the power of 2 is executed, the result is 4, 2以2的幂执行，结果为4，
then 4 is multiplied by 3, that is 12, 然后4乘以3，即12
and finally 12 is added to 10. So x should be 22. 最后将12加到10。所以x应该是22。
So let's run this program and verify this. So I'm going to 因此，让我们运行该程序并进行验证。所以我要
delete these lines here. Run the program, there you go. X 在此处删除这些行。运行程序，就可以了。 X
is 22. Now let me bring back these rules here. 是22岁。现在让我在这里回顾这些规则。
We can also use parenthesis to change the order of operations 我们还可以使用括号来更改操作顺序
so if we have parenthesis we always 所以如果我们有括号，我们总是
takes priority. In this case we can add parenthesis 优先。在这种情况下，我们可以添加括号
around 10 + 3, so this piece of 3 will be 大约10 + 3，所以这3个
executed first, the result is 13, then the exponentiation 首先执行，结果为13，然后取幂
operator will be executed, so 2 to the power of 2 is 4, 运算符将被执行，因此2的2的幂等于4，
and finally 4 is multiplied by 13. 最后4乘以13
Now here is a little exercise for you. I'm going to set x to 现在，这里是您的一些练习。我将把x设置为
parenthesis 2 + 3 x 10 minus 括号2 + 3 x 10减
3. What is the result of this? Pause the video and think about it for a few seconds. 3.结果是什么？暂停视频，然后考虑几分钟。
So you learned that parenthesis always 所以你知道括号总是
overrides the order, so this piece of code is executed first. The result 覆盖顺序，因此首先执行这段代码。结果
of these 5. Then, between the multiplication and 在这5个中。然后，在乘法和
subtraction, you know that multiplication takes precedence. 减法，您知道乘法优先。
So next, 5 will be multiplied by 10, the result is 接下来，将5乘以10，结果是
50 and finally we have subtraction. So 50 minus 50，最后我们减去。所以50减
3 will be 47. Let's verify this, print 3将是47。让我们验证一下，打印
x, run the program there you go, I hope you guessed it right. x，在那里运行程序，希望您猜对了。
So this is all bout operator precedence, it's a very important topic 这就是所有回合运算符的优先级，这是一个非常重要的主题
and I see it quite often in Python tests. So if you're preparing for a Python test 我在Python测试中经常看到它。因此，如果您正在准备进行Python测试
make sure to watch his tutorial one more time. 确保再看一次他的教程。
In this tutorial, we're going to look at a few useful functions for working with numbers 在本教程中，我们将介绍一些用于处理数字的有用函数
let's start by defining a variable like x and set it to 2 让我们开始定义一个像x这样的变量并将其设置为2
.9. Now to round this number we can use the built in .9。现在要舍入这个数字，我们可以使用内置的
round function, so we call the round function, give it x, 圆形函数，因此我们将圆形函数命名为x，
and then print the result. Let's run this program 然后打印结果。让我们运行这个程序
so, we get 3, we have another useful built in function called 因此，我们得到3，我们有另一个有用的内置函数称为
abs which is short for absolute, and this is the absolute function abs代表绝对值的缩写，这是绝对函数
we have in math, we give it a value and it always returns 我们有数学，我们给它一个值，它总是返回
the positive representation of this value, even if the value is negative. 即使该值为负，该值的正表示。
Here's an example. Let's call the abs function 这是一个例子。我们叫abs函数
and give it negative 2.9 When we run this program 并给它负数2.9当我们运行该程序时
we're gong to see 2.9 on the terminal. So let's go ahead 我们很高兴在终端上看到2.9。所以我们继续吧
there you go. So absolute always returns a positive number. 你去。因此，绝对值始终会返回一个正数。
But technically in Python we have a handful of built in functions for performing 但是从技术上讲，在Python中，我们有一些内置函数可以执行
mathematical operations, if you want to write a program that involves complex 数学运算，如果要编写涉及复杂的程序
mathematical calculations, you need to import the math module. 数学计算，您需要导入数学模块。
A module in Python is a separate file with some reusable Python中的模块是一个单独的文件，具有一些可重用的
code. We use these modules to organize our code into different 代码。我们使用这些模块将我们的代码组织成不同的
files. As a metaphor think of a super market. When you go to a super market 文件。作为一个比喻，可以考虑一个超级市场。当你去超级市场时
you see different sections for fruits and vegetables, cleaning products, 您会看到水果和蔬菜，清洁产品的不同部分，
junk food and so on. Each section in the super market is like a module 垃圾食品等。超级市场的每个部分都像一个模块
in Python. So in Python we have this math module which contains a bunch 在Python中。因此，在Python中，我们有一个数学模块，其中包含一堆
of rustable functions for performing mathematical calculations. 用于执行数学计算的生锈函数。
So, let me show you how to use this module. On the top 因此，让我向您展示如何使用此模块。在顶端
we type import, math, all in lowercase 我们用小写形式输入import，math
with this we can import the math module. now math is 这样我们就可以导入数学模块了。现在数学是
an object like a string, so we can access it's functions or more accurately 像字符串这样的对象，因此我们可以更准确地访问它的功能
it's methods using the dot operator. So if you type 它是使用点运算符的方法。所以如果你输入
math. look these are all the mathematical 数学。看起来这些都是数学上的
functions available in this module. For example you can call the 该模块中可用的功能。例如，您可以致电
seal method to get the sealing of a number. So if you pass 2.9 here 密封方法可以得到一个密封数。因此，如果您在此处通过2.9
and then print the result we should see 3. 然后打印结果，我们应该看到3。
Let me delete all this other code here. Alright, let's run this program 让我在这里删除所有其他代码。好吧，让我们运行这个程序
there you go. So we get 3. Another useful method is the 你去。这样我们得到3。另一种有用的方法是
floor method, so let's give that a try, floor of 2. 下限方法，因此让我们尝试一下，下限为2。
9. What do you think we're going to get? We get 9.您认为我们会得到什么？我们得到
2. Now there are so many functions built in this module and we don't really have time 2.现在，此模块中内置了许多功能，我们真的没有时间
to go through all of them. But let me show you how we can learn about them on your own. 去经历所有这些。但是，让我向您展示如何独自学习它们。
Open up your browser and search for Python 3 打开浏览器并搜索Python 3
math module. Make sure to add the version python 3. 数学模块。确保添加版本python 3。
Because the math module in python 2 is slightly different from the math module in 因为python 2中的math模块与python 2中的math模块略有不同
python 3. So python 3 math module, python3。所以python 3 math模块，
now here you can see the documentation of this kind of module 现在在这里您可以看到这种模块的文档
let's go let's have a look, if you scroll down, 让我们来看一下，如果您向下滚动，
we can see the list of all the functions and their explanation. 我们可以看到所有功能的列表及其说明。
So as an exercise I encourage you to have a quick look at this 因此，作为一项练习，我鼓励您快速浏览一下
documentation. See what functions are there for you in case you need them. 文档。看看有什么功能可以满足您的需要。
In this tutorial, I'm going to talk to you about if statements in Python 在本教程中，我将与您讨论Python中的if语句
if statements are extremely important in programming and they if语句在编程中非常重要，并且它们
allow us to build programs that can make decisions based on some condition. 使我们能够构建可以根据某些条件做出决策的程序。
So if some conditions are true we're going to do certain things, otherwise we're going to do other 因此，如果某些条件成立，我们将做某些事情，否则我们将做其他事情
things. Here's an example. Over here I've got this text file with 事物。这是一个例子。在这里，我有这个文本文件
a bunch of rules for our program. If it's a hot day, perhaps we want to 我们程序的一堆规则。如果天气炎热，也许我们想
tell the user it's a hot day, so make sure to drink plenty of water. 告诉用户天气炎热，因此请确保喝大量水。
Otherwise, if it's cold, so here's another condition 否则，如果很冷，那么这是另一种情况
if this condition is true we're going to tell the user it's a cold day 如果此条件为真，我们将告诉用户这是一个寒冷的日子
so where warm clothes. And otherwise if it's 所以在哪里保暖的衣服。否则，如果
either hot or cold, we want to tell the user it's a lovely day. 无论是冷还是热，我们都想告诉用户这是美好的一天。
So let me show you how to write a program that simulates these rules. So, 因此，让我向您展示如何编写模拟这些规则的程序。所以，
back to our program here, we start by defining a boolean variable 回到我们的程序，我们首先定义一个布尔变量
is underline hot. We set this to true. 下划线很热。我们将其设置为true。
Next, we add an if statement, so if, here 接下来，我们添加一个if语句，所以在这里，如果
we need to add a condition, in this case we're going to use our boolean variable. So, 我们需要添加一个条件，在这种情况下，我们将使用我们的布尔变量。所以，
is underline hot. So if this values to true. 下划线很热。因此，如果此值为true。
Then we're going to do certain things. In this case, we want to tell the user 然后，我们将做某些事情。在这种情况下，我们想告诉用户
hey it's a hot day, drink plenty of water. So, back to our program 嘿，天气很热，多喝水。所以，回到我们的程序
after our condition we add a colon, now, 在我们的条件之后，我们添加一个冒号，现在，
note that when I press enter pycharm automatically indents 请注意，当我按Enter键时，pycharm会自动缩进
our cursor. Now any code that we write here will be executed 我们的光标。现在，我们在此处编写的任何代码都将执行
if this condition is true, otherwise it will be ignored. Here 如果此条件为真，否则将被忽略。这里
is an example. Let's write a print statement, here I'm going to use 是一个例子。让我们写一个打印语句，在这里我要使用
double quotes because I want to use an apostrophe in our string. So, 双引号，因为我想在字符串中使用撇号。所以，
it's a hot day. Now let's press enter 天气很热。现在让我们按Enter
you can see the cursor is still indented, that means we can write more code 您可以看到光标仍在缩进，这意味着我们可以编写更多代码
that we executed if this condition is true, in this case let's say we don't want to 如果此条件为真，我们执行该操作，在这种情况下，我们不想
write any extra code, so to terminate this block 编写任何额外的代码，以便终止此块
we need to press shift and tab, now the cursor is at the beginning of the line 我们需要按Shift和Tab，现在光标在该行的开头
so lets write a print statement with a message like 因此，让我们编写一条打印声明，并附上如下信息：
enjoy your day. Now when we run this program, because 祝您愉快。现在，当我们运行该程序时，因为
this condition is true, you're doing to say this message followed by 此条件为真，您要说的是此消息，然后是
this second message, take a look, so run, there you go, it's a hot day 第二条消息，看一看，所以运行，你去了，这是炎热的一天
enjoy your day. But if I go over here and 祝您愉快。但是如果我去这里
change this boolean value to false and run the program again, our 将此布尔值更改为false并再次运行程序，我们的
first message disappears and we only see the second message, enjoy 第一条消息消失了，我们只看到第二条消息，享受
your day. So this is how if statements work. Now back 你的一天。因此，这就是if语句如何工作的方式。现在回来
here we can add another print statement let's say 在这里我们可以添加另一个打印语句，假设
drink plenty of water. 喝很多的水。
Now because this spirant statement is also indented it will be 现在，因为这个精妙的陈述也被缩进了，所以它将是
executed if this condition is true. So I'm going to revert is hot to true 如果此条件为真，则执行。所以我要还原为真
and run the program one more time. There you go, so 并再次运行该程序。你去那里，所以
it's a hot day, drink plenty of water, and enjoy your 天热，喝大量的水，并享受您的
day. Alright now let's add a second rule here, if 日。好了，现在让我们在这里添加第二条规则
it's hot we're going to execute these two lines, otherwise if it's not hot 很热，我们将执行这两行，否则，如果不很热
we want to print a different message. So here 我们要打印其他信息。所以在这里
we are moving an indentation and typing els 我们正在移动缩进并输入els
colon. Now when we press enter once again our cursor 冒号。现在，当我们再次按下Enter键时，我们的光标
indented so the code that we write here will be executed if this 缩进，以便我们在此处编写的代码将在以下情况下执行
condition is not true. So here we can print 条件不正确。所以我们可以在这里打印
it's a cold day, print, 今天很冷，打印，
where warm clothes. 那里暖和的衣服。
Now let's run our program one more time. So we get the message 现在，让我们再运行一次程序。这样我们得到消息
about a hot day followed by enjoy your day. You don't see any message 大约炎热的一天，然后享受您的一天。您没有看到任何讯息
about a cold day. Now if we go back here on the top. 大约很冷的一天。现在，如果我们回到顶部。
And change this boolean value to false and run our program 并将此布尔值更改为false并运行我们的程序
we see different set of messages. It's a cold day 我们会看到不同的消息集。天很冷
wear warm clothes and enjoy your day. But there's a problem with 穿暖和的衣服，享受美好的一天。但是有一个问题
our program. If it's not hot it doesn't necessarily mean that it's cold, it means 我们的程序。如果不热，则不一定表示它很冷，这意味着
it's a lovely day. So the absence of heat doesn't mean its cold. 这真是美妙的一天。因此，没有热量并不意味着它很冷。
Back to our conditions, here on line 4 we have this rule that says 回到我们的条件，在第4行，我们有一条规则说
if it's a cold day, then print these messages 如果天气冷，则打印这些消息
otherwise if it's neither hot or cold say it's a lovely day. 否则，无论天气不冷不热，都说这是美好的一天。
So, to implement this rule we need to go back and put 因此，要实施此规则，我们需要回过头来
py and define another variable. So let' say py并定义另一个变量。所以说
is underline cold we set this to 下划线很冷，我们将其设置为
true. Now here we need to add a second condition. So after 真的。现在在这里，我们需要添加第二个条件。所以之后
our first if statement, we can use an el if statement 我们的第一个if语句，我们可以使用el if语句
to define a second condition. So here's how it works. So, 定义第二个条件。这就是它的工作原理。所以，
el if which is short for els if or el如果是els的缩写，则为
otherwise if, now here we add another condition, so, 否则，如果现在我们在这里添加另一个条件，那么，
is cold So if t's cold you want to 很冷所以如果你想冷
execute these few lines. So let's cut these 执行这几行。所以让我们削减这些
from here, and move them under our second condition 从这里开始，并在第二个条件下移动它们
and finally if none of these conditions are true, 最后，如果这些条件都不成立，
you want to print a different message. It's a lovely 您要打印其他信息。真可爱
day. So, right now, 日。所以，现在，
is hot is false, is cold is true, 热是假，冷是真，
so when we run this program, python interpreter is going to execute the first 因此，当我们运行该程序时，python解释器将执行第一个
if statement, in this case because our condition is false, these two if语句，在这种情况下因为我们的条件为假，所以这两个
lines will be ignored, then Python interpreter will look at 行将被忽略，然后Python解释器将查看
line 7, it will evaluate this condition, in this case is 第7行，它将评估这种情况，在这种情况下是
cold is true so we're going to see these two messages on the terminal. cold是正确的，因此我们将在终端上看到这两个消息。
Now, in this case, because one of these conditions was true, this els statement 现在，在这种情况下，因为这些条件之一成立，所以此els语句
will be ignored, so we are not going to see this message, and finally 将被忽略，因此我们将不会看到此消息，最后
as before, we are always going too see this message. So let's run our 和以前一样，我们总是会看到此消息。因此，让我们运行我们的
program, there you go. it's a cold day, 程序，您去了。天气很冷，
where warm clothes and and enjoy your day. Now, 那里暖和的衣服，并享受您的一天。现在，
back to the top, if we change is cold 回到顶部，如果我们改变是冷的
to false it's neither hot nor cold so it's going to be a lovely day. 虚假的话，它既不热也不冷，所以这将是美好的一天。
Let's run the program, and here you go, it's a lovely day 让我们运行程序，然后开始，这是美好的一天
enjoy your day. So these are the basics of using if 祝您愉快。这些是使用if的基础
statements. As you can see they are very useful in programming and with these 陈述。如您所见，它们在编程以及这些方面非常有用
we can build all kinds of rules into our programs. Okay here's an 我们可以在程序中建立各种规则。好吧，这是一个
exercise or you. Imagine the price of a house is 1 million dollars. 运动还是你。想象一所房子的价格是一百万美元。
Now if the buyer has good credit, they will need to put down 10 percent 现在，如果买家信誉良好，则需要放下10％
of the price of this property otherwise they need to put down 20 percent 的价格，否则他们需要放下20％
write a program with these rules an display the down payment 使用这些规则编写程序并显示预付款
card for a buyer with good credit. You will see my solution 信誉良好的买家的信用卡。您会看到我的解决方案
next. 下一个。
Alright let's define a variable for the price of this house so price 好吧，让我们为这所房子的价格定义一个变量
we set this to 1 million so 1 with 6 0s. 我们将其设置为100万，所以1与6 0对应。
Next we need a variable to tell if this buyer has good credit 接下来，我们需要一个变量来判断该买家是否信誉良好
so has good credit, 所以有良好的信誉，
and we set this to true, now we need an if statement 并将其设置为true，现在我们需要一个if语句
so if has good credit has true 所以如果有良好的信誉就可以
colon, here we need to calculate a down payment so 冒号，在这里我们需要计算预付款，所以
the down_payment should be equal to 首付应等于
0.1 x the price. That is 10 percent of the price of this 价格的0.1倍。那是这个价格的百分之十
property. Otherwise colon 财产。否则冒号
the down payment should be 0.2 首付应为0.2
times price. Now finally we remove the 乘以价格。现在终于我们删除了
indentation and print here we can use a form 缩进并打印在这里，我们可以使用表格
of valid string, first we add a label, down payment 的有效字符串，首先我们添加标签，预付定金
colon and right after that we add a placeholder 冒号，然后我们添加一个占位符
or a hole for our down payment variable. So curly braces 或预付定金变量的漏洞。大括号
down payment. Let's run this 首付。让我们运行这个
program, so down payment for a buyer with good credit 计划，因此对于信誉良好的购买者而言，预付定金
is 100,000 dollars. Now let's improve this by adding a 是100,000美元。现在，通过添加一个
dollar sign before this number. So back to our formatted string, 该数字前的美元符号。回到我们的格式化字符串，
just before the curly brace I'm going to add a dollar sign let's 在花括号之前，我要添加一个美元符号，让我们
run this one more time, that is better. 再运行一次，那更好。
In this tutorial I'm going to talk to you about the logical operators within Python. 在本教程中，我将与您讨论Python中的逻辑运算符。
We use these operators in situations where we have multiple 我们在有多个操作员的情况下使用这些运算符
conditions. Here is an example. Let' say we're building an application for 使适应。这是一个例子。假设我们正在为
processing loans. If an applicant has high income 处理贷款。如果申请人的收入很高
and good credit, then they're eligible 和良好的信誉，那么他们就有资格
for a loan. So in this example we have two conditions, one is having 贷款。因此，在此示例中，我们有两个条件，一个条件是
high income and the other is having good credit. So if both 高收入，另一方信誉良好。所以如果两者
these conditions are true, then the applicant is eligible for a loan. 这些条件成立，那么申请人就有资格获得贷款。
So this is where we use the logical and operator. 这就是我们使用逻辑和运算符的地方。
We use this operator to combine two conditions, and by the way 顺便说一下，我们使用该运算符来组合两个条件
this is not specific to python programming language, pretty much any programming language 这不是特定于python编程语言，几乎任何编程语言
that supports if statements also supports the logical operators. 支持if语句也支持逻辑运算符。
So, back to our program, let's define two variables, 所以，回到我们的程序，让我们定义两个变量，
has high income, we set this to true. 有高收入，我们将其设置为true。
And another one has good 还有一个很好
credit, we also set this to true, now our if statement 信用，我们也将其设置为true，现在我们的if语句
if has high income has true, 如果高收入是真的，
and has good credit is also true, 拥有良好的信誉也是如此，
then we're going to print eligible 然后我们将打印符合条件的
for null. So this is where 为空。所以这是
we're using the and operator. So if both these conditions are true 我们正在使用and运算符。所以如果这两个条件都成立
then this message will be printed. If one of them is false, we're not going to see 然后将打印此消息。如果其中之一是假的，我们将不会看到
this message. Let's try this out. So I'm going to run this program 这条信息。让我们尝试一下。所以我要运行这个程序
so we see it eligible for loan, but if we change 因此我们认为它有资格获得贷款，但如果我们进行更改，
either of these conditions to false, and run the program again 这些条件之一为false，然后再次运行程序
look, the message disappears. 看，消息消失了。
So this is the logical and operator. We also have the 因此，这是合乎逻辑的运算符。我们也有
logical or, and we want to use that in situations where we want to do certain things 逻辑或，我们想在需要做某些事情的情况下使用它
at least one of the conditions is true, for example let's change 至少其中一个条件为真，例如让我们进行更改
the rule for this program, such that if the applicant has high income, 该计划的规则，例如，如果申请人的收入很高，
or good credit, then they're eligible for a loan, 或信誉良好，那么他们就有资格获得贷款，
so if either or both these conditions are true then the candidate is 因此，如果这两个条件中的一个或两个都成立，则候选人为
eligible. Now back to our program we can 有资格的。现在回到我们的程序，我们可以
implement this rule by using the logical or operator. So we simply replace 通过使用逻辑或运算符来实现此规则。所以我们只需替换
and with or, now when we run this program we're going to 使用or，现在，当我们运行该程序时，我们将
see this message because at least one of our conditions is true, 看到此消息是因为我们至少有一个条件为真，
let's take a look. So the applicant is eligible for a loan 让我们来看看。因此，申请人有资格获得贷款
for a loan because they have good credit. If you change this to false 借贷，因为他们有良好的信誉。如果您将其更改为false
but set the other condition to true, we still 但将其他条件设置为true，我们仍然
see the same result, but if both these conditions are false 看到相同的结果，但是如果这两个条件都为假
then we're not going to see this message anymore. So this is the difference 那么我们就不会再看到此消息了。所以这是区别
between these operators. With the logical and operator 这些运营商之间。与逻辑和运算符
both conditions should be true, with the logical 两个条件都应为真，符合逻辑
or operator at least one condition should be true 或操作员至少有一个条件为真
we also have another logical operator called not 我们还有另一个逻辑运算符not
and that basically inverses any boolean value we give it, if we give it, 基本上就颠倒了我们给它的任何布尔值，如果我们给它，
we give it a true boolean value it converts it to false. For example 我们给它一个真实的布尔值，它将其转换为false。例如
let's make up a new room, if applicant 如果有申请人的话，我们来补个新房间
has good credit and doesn't have 有良好的信誉，没有
a criminal record then 然后是犯罪记录
they're eligible for a loan. Let me show you how to implement this. So, 他们有资格获得贷款。让我向您展示如何实现此目标。所以，
we go back to our program, in this example we don't need a 我们回到程序，在此示例中，我们不需要
first variable for let's delete that. Let's set this variable to true 让我们删除它的第一个变量。让我们将此变量设置为true
we also define another variable like has criminal 我们还定义了另一个变量，例如具有刑事犯罪
record. We set this to false. 记录。我们将其设置为false。
Now, we want to check to see if this applicant has good credit and not 现在，我们要检查此申请人是否信誉良好，
a criminal record. This is where we use the not operator. 犯罪记录。这是我们使用not运算符的地方。
So, if they have good credit, 因此，如果他们有良好的信誉，
and not criminal 而不是犯罪
record. So, in this example, has criminal 记录。因此，在此示例中，
record is set to false, when we use the not operator this 当我们使用not运算符this时，record设置为false
basically gets changed to true, so we have two conditions that are true. 基本上变成了true，所以我们有两个条件成立。
Here's ones and here's another one. So our applicant is 这是一个，这是另一个。所以我们的申请人是
eligible for a loan. And when we run this program we see 有资格获得贷款。当我们运行该程序时，我们看到
this familiar message. However 这个熟悉的消息。然而
if an applicant has a criminal record, so let's change this to 如果申请人有犯罪记录，那么我们将其更改为
true, now when we run this program we can see our applicant is 是的，现在当我们运行此程序时，我们可以看到我们的申请人是
not eligible because when we apply then operator on this 不符合条件，因为当我们在此应用操作符时
variable, we'll get false. So true changes to false. 变量，我们将得到假。因此，将真实更改为错误。
And we'll end up with two conditions, one that's true 最后我们有两个条件，一个是正确的
and the other is false. And that's why this message is 另一个是假的。这就是为什么这个消息是
not printed. So this is all about the logical operators in 不打印。这就是关于逻辑运算符的全部内容
python. Python。
In this tutorial I'm going to talk to you guys about 在本教程中，我将与大家讨论
comparison operators in Python. We use comparison operators Python中的比较运算符。我们使用比较运算符
in situations where we want to compare a variable with a value, 在我们想要将变量与值进行比较的情况下，
for example, if temperature is greater than 30, then 例如，如果温度大于30，则
we want to print it's a hot day. Otherwise, if it's less 我们要打印这是一个炎热的日子。否则，如果少于
then 10, it's a cold day, otherwise it it's neither hot 然后十，这是一个寒冷的日子，否则它既不热
nor cold. And by the way I'm taking about celsius, not farenheit. 也不冷。顺便说一句，我要摄氏，而不是摄氏温度。
So, to build these rules into our program, we need to use comparison 因此，要将这些规则构建到我们的程序中，我们需要使用比较
operators. Back to app.py, I define this 运营商。回到app.py，我定义了这个
temperature value, let's write an if statement, if temperature 温度值，让我们写一个if语句，如果温度
now we want to check to see if this is greater than 30, so we use 现在我们要检查它是否大于30，所以我们使用
the greater than operator. If this is greater than 30, 大于运算符。如果大于30，
we want to print it's a hot day 我们要打印这是一个炎热的日子
otherwise, let's just print 否则，我们只打印
it's not a hot day. Now, 这不是一个炎热的日子。现在，
when we run this program, we're going to see this second message because 30 当我们运行该程序时，我们将看到第二条消息，因为30
is not greater than 30. So our first condition a value 不大于30。所以我们的第一个条件是一个值
is to false. let's verify that. So run, 是假的。让我们验证一下。快跑
it's not a hot day. Now if you change 这不是一个炎热的日子。现在，如果你改变
the temperature to 35 and run this again, 温度升至35，然后再次运行
we're going to see a different message, it's a hot day, so this is where we use 我们将看到不同的消息，这是一个炎热的日子，所以这是我们使用的地方
comparison operators. Now what we have here as you know is an expression 比较运算符。现在我们所知道的是一种表达
because it's a piece of code that produces a value. So more accurately this is 因为这是一段产生价值的代码。所以更准确地说是
a boolean expression. So this is the greater than operator, 布尔表达式。因此，这大于运算符，
we also have greater than or equal to, we have 我们也有大于或等于
less then, less then or equal to, 小于，小于或等于
here's the equality operator, so if the temperature equals to 30, 这是相等运算符，所以如果温度等于30，
then you can say it's a hot day. Note that this is different from the assignment operator 那么您可以说今天很热。请注意，这与赋值运算符不同
that has only one equals sign. You can see that if we use only one equal sign 只有一个等号。您可以看到如果我们仅使用一个等号
here we immediately get this red underline because this is simply 在这里，我们立即得到红色下划线，因为这仅仅是
an assignment statement. We're changing the value of the temperature. 作业说明。我们正在更改温度值。
you are setting the value of 您正在设置的值
something else. So we don't have a boolean expression, you are not producing a 其他的东西。因此，我们没有布尔表达式，您不是在生成
boolean value. Okay? So, our equality operator 布尔值。好的？所以，我们的平等算子
has two equal signs and finally we have not 有两个相等的符号，最后我们没有
equal which is an exclamation followed by an equal sign. 等于，是一个惊叹号，后跟一个等号。
Now here's an exercise for you. You have probably seen that when you fill out a 现在，这是一个适合您的练习。您可能已经看到，当您填写
form online, sometimes the input fields have validation messages, 在线表单，有时输入字段中包含验证消息，
for example, let's say we have an input field for the user to enter their name. 例如，假设我们有一个输入字段供用户输入其名称。
Now if the name is less then 3 characters wrong we want to display a validation 现在，如果名称少于3个字符，我们要显示一个验证
error, like name must be at least three characters, 错误，例如名称必须至少包含三个字符，
otherwise, if the name is more then 50 characters long then we want 否则，如果名称长度超过50个字符，则我们需要
to display a different validation error like name can be a maximum 显示一个不同的验证错误，例如name可以是最大的
of 50 characters. Otherwise if the name is between 3 and 50 characters 50个字符。否则，如果名称介于3到50个字符之间
then we just want to tell the user that name looks good. 那么我们只想告诉用户该名称看起来不错。
So go ahead, and write a plan to implement these rules. 因此，继续并编写实施这些规则的计划。
Alright let's define a variable called name and set it to 好吧，让我们定义一个名为name的变量并将其设置为
let's say j. So we're assuming this is what the user types into an input field. 假设j。因此，我们假设这是用户在输入字段中键入的内容。
Now, we want to get the number of characters in this string. 现在，我们要获取此字符串中的字符数。
So we use the len function, right? Len of name. 所以我们使用len函数，对吗？伦的名字。
When we print this we get 1, right 当我们打印这个时，我们得到1，对
you have seen this before. Now here we want to use an if statement so 你以前看过这个。现在在这里我们要使用if语句
if len of name is less then 如果名字len小于
3, then we want to print 3，那我们要打印
name must be at least 3 characters 名称必须至少包含3个字符
now here we need a second condition 现在这里我们需要第二个条件
to check the upper limit. So el if 检查上限。所以，如果
len of name is greater than 50, 名称len大于50，
then we want to print a different message, name, 那么我们要打印不同的消息，名称，
must be a maximum 不得超过最大值
of 50 characters. 50个字符。
Okay? And otherwise if else 好的？否则的话
none of these conditions are true that means the name looks good. So, 这些条件都不成立，这意味着名称看起来不错。所以，
print, name looks good. Let's 打印，名字看起来不错。让我们
run our program. So in this case we get this message 运行我们的程序。因此，在这种情况下，我们会收到此消息
because our name is too short. Now if you go back here and 因为我们的名字太短了。现在，如果您回到这里，
type something really really long. And then 输入真的很长的东西。然后
we run our program we're going to see a different message name must be a 我们运行我们的程序，我们将看到一个不同的消息名称必须是
maximum of 50 characters and finally if 最多50个字符，最后如果
we type a proper name here like John Smith 我们在这里输入一个合适的名字，例如John Smith
and run our program we get name 并运行我们的程序，我们得到名称
looks good. 看起来不错。
Here's another good exercise that combines 这是另一个结合了好的练习
many of the materials you have learned so far, so earlier you built a program to 到目前为止，您已经学到了许多材料，所以早些时候您建立了一个程序来
convert someone's weight from pounds to kilograms. Now we want to extend this program 将某人的体重从磅转换为公斤。现在我们要扩展这个程序
and allow the user to enter their weight in either kilograms or 并允许用户以公斤或千克输入他们的体重
pounds and then we will convert it to the other unit. Here's how our program 磅，然后将其转换为其他单位。这是我们的程序
is going to work. So I enter my weight in pounds so 要上班了。所以我以磅为单位输入体重
100 and 60 now it's telling me if it's in pounds or 现在是100和60告诉我是磅还是磅
kilograms. So here I'm adding l to lbs or k for kilograms. 公斤。所以在这里，我将l加至lbs或k表示千克。
And by the way, this program is not case sensitive so 顺便说一句，该程序不区分大小写，因此
when I enter a capital l or lowercase l it takes 当我输入大写字母l或小写字母l时
it as pounds. Now it tells me ur set it to 它以磅为单位。现在它告诉我您将其设置为
kilos. Let's run this program one more time, 公斤。让我们再运行一次该程序，
this time I'm going to enter my weight in kilo's, so send it to 这次我要输入以公斤为单位的体重，所以将其发送到
is the weight and the unit is kilograms so k, 是重量，单位是千克，所以k，
and it says you are 160 pounds. 它说你160磅。
So go ahead and spend a few minutes on this exercise, you will see my solution next. 因此，继续并花几分钟进行此练习，接下来您将看到我的解决方案。
Alright first let's ask the user their weight. So we use the input 好吧，首先让我们问一下使用者的体重。所以我们使用输入
function, weight colon we get the return value 函数，权重冒号我们得到返回值
and store it in the variable called weight. 并将其存储在名为weight的变量中。
Now the second question, so one more time we use the input function 现在是第二个问题，因此我们再一次使用输入功能
el for pounds. 埃尔英镑。
Or k for kilograms. So, 或k表示千克。所以，
let's get that too and store it in a variable called unit 让我们也将其存储在一个名为unit的变量中
now we need an if statement. So if unit 现在我们需要一个if语句。所以如果单位
equals l then we need to convert this weight 等于l，那么我们需要转换这个权重
into kilograms. However, with this implementation we are only allowing 公斤但是，通过此实现，我们仅允许
the user to enter a capitol l, if they enter a lowercase l 用户输入大写字母l，如果他们输入小写字母l
this code is not going to work. So this is where we use the upper 此代码将无法正常工作。所以这是我们使用鞋帮的地方
method of string objects so this unit is a string because as I told you 字符串对象的方法，所以这个单位是一个字符串，因为正如我告诉你的
before, the input function always returns a string. 之前，输入函数总是返回一个字符串。
So, we can use the dot operator to access all it's methods or 因此，我们可以使用点运算符来访问其所有方法，或者
functions, here we call the upper method, this 函数，在这里我们称为上层方法
will convert whatever the user enters to upper case and then we'll convert it 将用户输入的内容全部转换为大写，然后将其转换为大写
to a capital l. Now, if this condition is true, 到首都现在，如果这个条件成立，
then we need to get the weight and multiply it by 0, 那么我们需要获得权重并将其乘以0，
.45 However, as you know this .45但是，如您所知
weight is a string object, and we cannot multiply a string weight是一个字符串对象，我们不能将一个字符串相乘
by a floating point number, we talked about this earlier in this course. 通过一个浮点数，我们在本课程的前面讨论了这一点。
So first we need to convert this weight to a numerical value. So 因此，首先我们需要将此权重转换为数值。所以
right here, when we call the input function, we can get the return 就在这里，当我们调用输入函数时，我们可以获得返回值
value and pass it to the int function. So, 值并将其传递给int函数。所以，
we call the int function and give it 我们调用int函数并给它
the return value of the input function. Now, the 输入函数的返回值。现在
in function will return an integer so we can store it in this weight in函数将返回一个整数，因此我们可以将其存储在此权重中
variable. So here's the converted weight, let's store it in 多变的。这是转换后的重量，我们将其存储在
a variable called converted, 称为转换的变量，
then we print here we can use a formatted string, so 然后我们在这里打印，我们可以使用格式化的字符串，所以
we prefix this string with f ur 我们用f ur前缀这个字符串
we add curly braces to dynamically insert the value of 我们添加花括号以动态插入的值
converted variable. And finally we add kilo. 转换后的变量。最后我们加公斤。
Otherwise, if the unit is kilograms. 否则，如果单位是千克。
We need to divide the weight by 0.45. q 我们需要将权重除以0.45。 q
So, weight divided by 0.45 and 因此，重量除以0.45和
just to refresh your memory, this division operator returns a floating point number 只是为了刷新您的内存，该除法运算符返回一个浮点数
but if we use double slashes we'll get an integer. 但是如果我们使用双斜杠，我们将得到一个整数。
In this case, we want to get a floating point number, 在这种情况下，我们想要一个浮点数，
finally let's print a formatted string, ur 最后让我们打印一个格式化的字符串
curly braces, converted 花括号，转换
pounds. Okay? Now 磅。好的？现在
let's run this program and see what happens. So weight is 让我们运行该程序，看看会发生什么。所以重量是
160 and lbs in 160和lbs
and that equals to 72 kilos, perfect, if we run it one more time, 等于72公斤，很完美，如果我们再跑一次，
and enter 72 kilos 然后输入72公斤
we get 160 pounds. 我们得到160磅。
In this tutorial I'm going to show you how to use y loops in python. We 在本教程中，我将向您展示如何在python中使用y循环。我们
use y loops to execute a block of code multiple times and there are often 使用y循环多次执行代码块，通常
useful in building interactive programs and games. In a future tutorial 在构建交互式程序和游戏时很有用。在以后的教程中
I'm going to show you how to build a simple game using a y loop. 我将向您展示如何使用ay循环构建简单的游戏。
So, let's get started with the basics, we write a y statement 所以，让我们开始做基础，我们写一个y语句
and right after that, we type a condition followed by a colon 然后紧接着，我们输入一个条件，后跟一个冒号
as long as this condition is true the quote that we write 只要该条件为真，我们所写的报价
in this block will be repeatedly executed. Here is an example. 在此块中将被重复执行。这是一个例子。
We can define a variable like i, as in short for 我们可以定义一个像i这样的变量，简而言之
index and set it to 1. Now we set our condition to 索引并将其设置为1。现在我们将条件设置为
i less than or equal to 5, so as long as I 我小于或等于5，只要我
is less then or equal to 5, we can print i, 小于或等于5，我们可以打印i，
on the terminal. And then we need to increment i, 在终端上。然后我们需要增加i
by 1. So we set i to i plus 1. The reason 乘以1。所以我们将i设置为i加1。原因
we do this is that if we don't do this I will be 1 forever 我们这样做是，如果我们不这样做，我将永远是1
so we'll end up with an infinite loop. Because this condition will 所以我们最终会陷入无限循环。因为这种情况会
always be true. One is always less then 5, so in every iteration of this 永远是真实的。一个总是小于5，因此在每次迭代中
loop, we increment i by 1, so at some point, i is gonna be 循环，我们将i加1，所以在某个时候，我会
six and then that is when this condition will be false and then 六，然后当此条件为假，然后
we'll jump out of this loop, okay? Now to demonstrate how everything works 我们会跳出这个循环，好吗？现在演示一切如何
after this loop I'm going to add a print statement 在此循环之后，我将添加一个打印语句
say done. So note that these two lines 说完成。所以请注意这两行
are indented so they are part of the y block. 缩进，因此它们是y块的一部分。
Okay, now let's go ahead and run this program and see what happens. So, 好的，现在让我们继续运行该程序，看看会发生什么。所以，
take a look, we get the numbers 1-5 followed by 看一下，我们得到数字1-5，然后是
done. So heres how this program gets executed 完毕。所以这是如何执行该程序的
first we set i to 1 now python interpreter executes line 首先我们将我设置为1现在python解释器执行行
2, this condition is true because i is less then 5, 2，此条件成立，因为我小于5，
so i is printed on the terminal and then incremented by 所以我印在终端上，然后增加
1. Then the control moves back to the beginning of the y loop. 1.然后，控件返回到y循环的开头。
So it doesn't go to the next statement. So, 因此，它不会转到下一条语句。所以，
we come back here and now we are in the second iteration. In the second iteration 我们回到这里，现在我们处于第二次迭代中。在第二次迭代中
i is 2, and because 2 is less then 5, our condition is still 我是2，并且因为2小于5，所以我们的条件仍然是
true, so i will be printed on the terminal, and once again it will be 是的，所以我将被打印在终端上，再一次
incremented by 1, so at some point i is going to be 6, 加1，所以在某个时候我会变成6
and that's when this condition will be false so our look will 那时这个条件将是假的，所以我们的外观会
be terminated and this done message will be printed on the terminal. 终止，此完成的消息将打印在终端上。
So this is the basics of y loops. Now let's make this program a little 因此，这是y循环的基础。现在让我们稍微做一下这个程序
bit more interesting. Here we can write an expression like this. We 更有意思。在这里，我们可以编写一个这样的表达式。我们
add a string, and in this string we add an asterisk 添加一个字符串，并在此字符串中添加一个星号
and then we multiply this string by i. So 然后我们将这个字符串乘以i。所以
with this expression, we can repeat a string, when we multiply a string 用这个表达式，当我们将一个字符串乘以一个字符串时，我们可以重复一个字符串
by a number, that string will be repeated. For example, if 一个数字，该字符串将被重复。例如，如果
i is two, this expression will produce a 我是两个，这个表达式会产生一个
string with two asterisks. Now let's run the program 带有两个星号的字符串。现在让我们运行程序
and see what we get. So we see this little triangle 看看我们得到了什么。所以我们看到这个小三角形
shape here. Because in the first iteration i is 1, so, 形状在这里。因为在第一次迭代中，我是1，所以，
1 times an asterisk produces 1 asterisk. 星号1次产生1个星号。
In the second iteration i is 2, so when we multiply 2 在第二次迭代中，我是2，所以当我们乘以2
by 1 asterisks, we'll get 2 asterisks. 按1个星号，我们将得到2个星号。
In this tutorial I'm going to show you how to use a y loop to build 在本教程中，我将向您展示如何使用y循环进行构建
a guessing game like this. So we have this secret number which is currently set to 像这样的猜谜游戏。所以我们有这个秘密号码，目前设定为
9. Now the computer is asking me to make a guess. So, 9.现在，计算机要我猜测一下。所以，
let's say 1 is not right because the secret number is 9, okay, 假设1不正确，因为密码是9，好吧，
try again, 2, no it's not right, let's try again, so I 再试一次，2，不，这不对，让我们再试一次，所以我
only have three chances to make a guess. If I can't guess the number the program 只有三个机会来猜测。如果我猜不到程序的编号
tells me that I failed. let's run the program one more time, this time 告诉我我失败了。我们这次再运行一次程序
I'm going to guess the number, it's 9, there you go, it says you in. 我猜数字是9，你去了，说你进去了。
So let's go ahead and build this program using a y loop. 因此，让我们继续使用ay循环来构建此程序。
Alright, let's start by defining a variable to store our secret number 好吧，让我们开始定义一个变量来存储我们的秘密号码
so, we call the secret underline number and set it to 9. 因此，我们称其为秘密下划线，并将其设置为9。
Now we need a while loop to repeatedly ask a user to 现在我们需要一个while循环来反复要求用户
make a guess. So while condition colon 做一个猜想。因此，当条件结肠
What is our condition here? Well we want to give our user a 我们这里的状况如何？好吧，我们想给我们的用户一个
maximum of three guesses. So similar to the last tutorial, we can define 最多三个猜测。与上一教程类似，我们可以定义
a variable like I, set it to 0, and assume this represents 像我这样的变量，将其设置为0，并假设它代表
the number of guesses the user has made. And then we write our condition 用户做出的猜测数量。然后我们写我们的条件
as i less then 3. Note that here I'm not 因为我不到3。请注意，这里我不是
using less then or equal to operator, because with this condition 使用小于或等于运算符，因为在这种情况下
our loop will be executed 4 times, while i is 0, 我们的循环将执行4次，而当我为0时，
one, two, and three, so here we should use 一，二和三，所以在这里我们应该使用
the less then operator. Now if we give this code to someone else it's unclear 少则运算符。现在，如果我们将此代码提供给其他人，目前尚不清楚
what does i represent here, it's only in our head that 我在这里代表什么，只是在我们脑海中
i represents the number of guesses the user has made. So as 我代表用户的猜测次数。这样
a best practice, always use meaningful and descriptive names for your variables. 最佳做法是，对变量始终使用有意义的描述性名称。
So it's better to rename this variable to guess, count. 因此，最好重命名此变量以进行猜测和计数。
Let me show you how to rename. So right click on i variable, 让我告诉您如何重命名。因此，右键单击i变量，
and then go to refactor and 然后去重构
rename it. Look at the shortcut. On a Mac computer it's shift and 重命名它。查看快捷方式。在Mac电脑上，它正在转移，
f 6. Now in this dialogue box we can easily f 6.现在，在此对话框中，我们可以轻松地
rename your variable and pycharm will update all the references to that 重命名您的变量，pycharm将更新对该变量的所有引用
variable so we don't have to manually update each instance, okay? Let's 变量，因此我们不必手动更新每个实例，好吗？让我们
change this to guess_count 将此更改为guess_count
enter, there you go, now that is better, 进入，你去那里，现在更好了，
also it's better to store 3 in a separate variable to make our code 另外最好将3存储在一个单独的变量中以使我们的代码
more readable, because it's not quite clear what does 3 represent here. 更具可读性，因为目前尚不清楚3在这里代表什么。
So, let's define a variable called guess limit 因此，让我们定义一个称为猜测极限的变量
say to 3, and then we can change 3 to guess 说3，然后我们可以改变3来猜测
underline limit, now our code is more readable 下划线限制，现在我们的代码更具可读性
while guess count is less then guess limit, see it reads like a story 虽然猜数少于猜想极限，但看起来像个故事
this is how you should write code. Okay, so 这就是您应该编写代码的方式。可以，然后呢
while this condition is true, we want toast the user to make a guess. So here 当此条件成立时，我们希望敬酒用户做出猜测。所以在这里
we use our input function, guess 我们使用输入函数，猜
Now whatever the user enters comes out as a string so we need to convert it to an integer. 现在，用户输入的任何内容都以字符串形式出现，因此我们需要将其转换为整数。
So right here, we pass the result to the end function 所以在这里，我们将结果传递给end函数
and then get it and store it in a separate variable called guess. 然后获取它并将其存储在一个名为guess的单独变量中。
So at this point the user made a guess, now we need to 因此，在这一点上，用户做出了一个猜测，现在我们需要
increment guess count so guess count 增加猜测数，所以猜测数
we set it to plus equal 1 or 我们将其设置为正等于1或
okay, now we need to check to see if the user will make the right guess. 好的，现在我们需要检查用户是否做出正确的猜测。
So here we need an if statement. If what the user guessed 因此，在这里我们需要一个if语句。如果用户猜到了
equals our secret number, 等于我们的秘密号码，
again see our code is so readable. It's like a story you can read it like plain 再次看到我们的代码是如此可读。这就像一个故事，您可以像平常一样阅读它
English. So if this condition is true we want to 英语。因此，如果此条件为真，我们想
tell the user they won. So print you won 告诉用户他们赢了。所以打印你赢了
now lets go ahead and run our program up to this point. 现在让我们继续运行程序。
So okay it's asking me to make a guess, I'm going to make 好吧，这是要我猜测，我要做出
the wrong guess so one it asked me again, 2 one more time, 猜错了，于是又问了我一次，再问了2次，
3, okay, what is missing in this implementation is the 3，好的，此实现中缺少的是
message that tells me that I failed. We're going to take care of it momentarily, but 消息告诉我我失败了。我们将暂时解决它，但是
let's run the program one more time and make the right guess. So, 9 让我们再运行一次程序并做出正确的猜测。所以9
okay it says you won, but it's still asking me to make 好吧，它说你赢了，但它仍然要我做
a guess, because our while loop is going to get executed 3 times. Look 一个猜测，因为我们的while循环将被执行3次。看
1 and 2. So we need to change our program 1和2。所以我们需要更改程序
such that if the user makes the right guess, we need to terminate our 这样，如果用户做出正确的猜测，我们需要终止我们的
while loop, we need to jump out of it. How do we do that? while循环，我们需要跳出它。我们该怎么做？
So, over here if the user makes the right guess, after 因此，在此之后，如果用户做出正确的猜测，
we print this message we can use the brick statement to terminate 我们打印此消息，我们可以使用砖语句终止
terminate a loop, when python interpreter sees this, it's going to 终止循环，当python解释器看到这一点时，它将
immediately terminate our loop, it's not going to evaluate this condition again. 立即终止我们的循环，因此不会再次评估这种情况。
Now let's run our program and see what happens. So, I'm going to 现在，让我们运行我们的程序，看看会发生什么。所以，我要
guess the right number, you won and look, you are 猜对了数字，你赢了，看看，你是
now asked to make two more guesses, beautiful. Now the last thing we need 现在要求再做两个猜测，很漂亮。现在我们需要的最后一件事
to add here is the message that tells the user that they failed if they could not guess 要在此处添加的消息是告诉用户，如果他们无法猜到他们失败了
the right number. How do we do that? Well in Python 正确的号码。我们该怎么做？在Python中很好
our while loops can optionally have an else part. 我们的while循环可以选择包含else部分。
similar to the if statements. So earlier you learned that our if statements 类似于if语句。因此，您较早地了解到我们的if语句
can optionally happen else part. Here, so 可以有选择地发生在其他部分。在这里，所以
if this condition is true, do this, 如果满足此条件，请执行此操作，
otherwise do something else. In this case our if statement doesn't have 否则做其他事情。在这种情况下，我们的if语句没有
an else part. Now, similar to the if statements 另一个部分。现在，类似于if语句
Our while loops, our while statements can also have an else part. 我们的while循环，我们的while语句也可以包含else部分。
So, right at this level we can add 因此，在这个级别上，我们可以添加
an else block, so else colon. 一个else块，另一个冒号。
And the code that we write here will get executed if this while loop 如果执行while循环，我们在此处编写的代码将被执行
completes successfully without an immediate 无需立即完成即可成功完成
break. In other words. If the user guesses the 休息。换句话说。如果用户猜测
right number, you break this loop, you jump out of it so the code that 正确的数字，您打破了这个循环，您跳出了循环，所以代码
we write in the else block will not get executed. 我们在else块中写入将不会执行。
But if the user cannot guess this number, you're never going to break out of 但是，如果用户无法猜到这个数字，那么您将永远不会崩溃
this loop, so this loop will be executed to completion untill 这个循环，所以这个循环将执行到完成为止
this condition become false. In that case, the code that we write 这种情况变为假。在这种情况下，我们编写的代码
in the else block will get executed, and this is the perfect opportunity for us 在else块中将被执行，这对我们来说是绝佳的机会
to tell the user hey, you made three guesses but none of them were right. 告诉用户嘿，您做出了三个猜测，但没有一个是正确的。
So, print, sorry you 所以，打印，对不起
failed. Now, let's test the program one more time. 失败的。现在，让我们再测试一次该程序。
So, guess 1, 2, 3, 所以，猜1,2,3，
sorry you failed, let's run it one more time. This time I'm going to make 抱歉，您失败了，让我们再运行一次。这次我要做
a wrong guess, and then the right guess, 一个错误的猜测，然后是正确的猜测，
we won and our loop terminated immediately. 我们赢了，我们的循环立即终止。
Alright, now it's time for you to practice what you have learned so far. 好了，现在是时候练习您到目前为止所学的知识了。
So once again we're going to build a game this game is a simulation 因此，我们再次要构建一个游戏，该游戏是模拟游戏
card game. Now our game doesn't have a graphical user interface or gooey 纸牌游戏。现在我们的游戏没有图形用户界面或粘性
and it doesn't really matter for now, our focus is entirely on building the 目前，这并不重要，我们的重点完全放在构建
engine for this game. So let's see how this works. 游戏的引擎。因此，让我们看看它是如何工作的。
When we run this, we get this little symbol here, and our program 当我们运行它时，我们在这里得到这个小符号，然后我们的程序
is waiting for us to enter a command. If you type help 正在等待我们输入命令。如果您输入帮助
either a lower case or upper case we get the list of commands 小写或大写我们都会得到命令列表
that our program or our game currently supports. So we can type the 我们的程序或游戏当前支持的功能。所以我们可以输入
start command to start our car, we can type 启动命令来启动我们的车，我们可以输入
stop command to stop our car, and quit to terminate the game. 停止命令以停止我们的汽车，并退出以终止游戏。
Any other commands that we type our program is going to tell us hey I don't understand that. 我们键入程序的任何其他命令都会告诉我们，嘿，我不明白。
For example, if I type asd here, it's going to say I don't understand 例如，如果我在此处输入asd，则表示我听不懂
that.If you type start, we get this message, 如果您输入开始，我们会收到此消息，
car started, ready to go, if you type stop it 汽车开动了，准备出发了，如果您键入“停止”
says car stopped, and finally if we hit quit 说车停了，最后如果我们撞到了戒烟口
our program terminates, this is a fantastic exercise for you to practice 我们的程序终止，这是您练习的绝妙练习
wha you have learned, so pause the video and spend 5-10 minutes 学到了什么，所以暂停视频并花5到10分钟
to build this program. 建立这个程序。
Alright, we're going to start with a while loop with a condition 好了，我们将从带有条件的while循环开始
What is our condition here? We want to run this loop 我们这里的状况如何？我们要运行此循环
until the user types quit. So we can define a variable 直到用户键入退出。所以我们可以定义一个变量
or a story to command what the user enters, and then we can run this 或一个故事来命令用户输入什么，然后我们就可以运行它
loop as long as the command does not equal to quit. So right before 只要命令不等于退出就循环。所以就在之前
the loop, we define a variable, command, and initially we set it 在循环中，我们定义一个变量，命令，并首先设置它
to an empty string. An empty string is a string that has no characters 到一个空字符串。空字符串是没有字符的字符串
in it. We only have the quotes. So then 在里面。我们只有报价。所以呢
we type out our condition as while command 我们输入条件为while命令
does not equal to quit then do something. 不等于退出然后做点什么。
Now immediately we have a problem here because we're assuming that the user 现在我们在这里遇到了一个问题，因为我们假设用户
types the command in lower case, so if they type this in upper case they 以小写形式键入命令，因此，如果以大写形式键入命令，则它们
our program is not going to behave properly, so to fix this problem, you need to 我们的程序无法正常运行，因此要解决此问题，您需要
call the lower method of the string object and then compare the results. 调用字符串对象的下部方法，然后比较结果。
With this quit. You could also call this upper 有了这个戒烟。你也可以称这上衣
and then type quit in upper case. It's about our personal preference 然后以大写形式键入quit。这是关于我们的个人喜好
in this demo I'm going to use lower case characters. 在此演示中，我将使用小写字符。
So, okay, now in this loop we need to ask the user to enter 好吧，现在，在这个循环中，我们需要让用户输入
a command. So once again we're going to use our input function, we're going to add 一个命令。因此，我们将再次使用输入函数，我们将添加
a greater then symbol followed by a space, 更大的符号后跟一个空格，
whatever the user enters, we get it and store it in our 无论用户输入什么，我们都将其存储在我们的
command variable. Now apart from 命令变量。现在除了
quit command, there are three other commands that we need to support. Start, quit命令，我们还需要支持其他三个命令。开始，
stop, and help. So here we need an if statement to compare 停下来，帮忙。所以在这里我们需要一个if语句进行比较
what the user enters with one of the supported commands. 用户使用受支持的命令之一输入的内容。
So, if command.lower 因此，如果使用command.lower
equals start then you want to print the message 等于开始，然后您要打印消息
like the car started. So print the car started. 就像汽车起步一样。于是打印车开始了。
Ready to go, it doesn't matter, 准备出发，没关系，
now the second condition. What if its not start, maybe it's stop? So, 现在第二个条件。如果它没有开始，也许它停止了怎么办？所以，
el if command.lower el if command.lower
equals stop, there you go, then we print a 等于停下来，你去了，然后我们打印一个
different message car stopped. Now look at our code. 不同的消息车停了下来。现在看一下我们的代码。
We have repeated this lower lower lower multiple times. 我们已经多次重复了这个更低的更低的更低的价格。
This is bad, in programming we have a term called dry, which is short for 这很不好，在编程中我们有一个叫做干的术语，它的简称
don't repeat yourself. So whenever you have duplicate 不要重复自己。所以只要你有重复
your code that means you're doing something wrong. So how can we solve this problem. 您的代码意味着您做错了什么。那么我们如何解决这个问题。
Well, instead of calling the lower method in each condition, 好吧，与其在每种情况下都不调用下层方法，
we can call it right here when we get the input from the user, so 当我们从用户那里获得输入时，我们可以在这里调用它，因此
this input function as you know returns a string, we can 如您所知，此输入函数返回一个字符串，我们可以
immediately call the lower method on this string, and with this command 立即使用此命令在该字符串上调用下层方法
will always be in lowercase, so we don't need to 总是小写，所以我们不需要
call this method in every condition. Look, 在每种情况下都调用此方法。看，
we remove the duplication and also our conditions 我们删除了重复项以及我们的条件
are shorter and easier to read. There is also one more place 较短且更易于阅读。还有一个地方
we need to modify so, it's right here. That is better. 我们需要进行修改，就在这里。那比较好。
Now, the third command. We need one more el if. 现在，第三个命令。如果还需要另外一位。
If the command equals help, then, 如果命令等于帮助，那么，
we want to show the commands that we support. So, 我们想显示我们支持的命令。所以，
here we're going to print a multi line string. So we 在这里，我们将打印多行字符串。所以我们
use triple quotes like this, and 使用这样的三引号，并且
give the user a guideline like this. So start 给用户这样的指导。所以开始
to start the car stop 开始停车
to stop the car, and 停下来的车，以及
quit to quit. Now finally we need 戒烟戒烟。现在最后我们需要
an else part, so if what the user enters is none of these commands, 其他部分，因此，如果用户输入的命令都不是这些命令，
we're going to tell them, hey we don't understand these, 我们要告诉他们，嘿，我们不了解这些，
else, colon print 否则，冒号打印
sorry I don't understand that. 对不起，我不明白。
And by the way note that here becomes I'm using double 顺便说一句，这里变成了我在使用double
quotes, I can easily use a single quote as an apostrophe, okay? 引号，我可以轻松地将单引号用作撇号，好吗？
So let's run our program up to this point and see what happens. 因此，让我们运行程序到现在为止，看看会发生什么。
Alright, let's type start car is 好吧，让我们键入启动车是
started, beautiful, stop, car is stopped, help, 开始，美丽，停止，汽车停止，帮助，
we get this guideline, but there's so much indentation 我们得到了这个指导方针，但是缩进太多了
before our commands, we'll fix that in a second. And finally 在执行命令之前，我们将在一秒钟内解决此问题。最后
let's test the quit command, oops, our program 让我们测试一下quit命令，哎呀，我们的程序
didn't work properly. Here is the reason. With these if statements, 不能正常工作。这是原因。有了这些if语句，
we're comparing the command with start stop, and 我们正在将命令与开始停止进行比较，并且
help. Anything else will end up here, so that's why our 帮助。任何其他事情都会在这里结束，所以这就是为什么我们
program says it doesn't understand that. So that's why our program 程序说它不明白。这就是为什么我们的程序
says it doesn't understand that command. However, after this el statement 说它不明白那个命令。但是，在此el声明之后
the control will be moved to the beginning of the loop. 控件将被移至循环的开头。
At this point our command is quit, so our loop will complete and the 此时，我们的命令已退出，因此我们的循环将完成，并且
program terminates. In other words when we run this program 程序终止。换句话说，当我们运行该程序时
and type quit, our program actually quits but 并键入quit，我们的程序实际上退出了
we still see this message which shouldn't appear here. How can we solve this problem? 我们仍然看到此消息，该消息不应出现在此处。我们如何解决这个问题？
Well, we can come back here and just before 好吧，我们可以回到这里和之前
the else block, add another el if, something like else块，如果再添加另一个el，例如
this. el if command equals 这。如果命令等于，则为el
quit then you can immediately break. 退出，您可以立即休息。
This will solve our problem, but note that we have kind of repeated 这将解决我们的问题，但请注意，我们已经重复了一遍
this expression in two places. The reality is that 这个表达在两个地方。现实情况是
we don't really need this condition on the top, because with these if statements 我们实际上不需要最上面的条件，因为有了这些if语句
well more accurately with this el if we can jump out of this loop and terminate 如果我们可以跳出此循环并终止，则可以更准确地使用此el
our program. So, we can simplify our condition 我们的程序。因此，我们可以简化条件
to something like this. True. So while true means 像这样真的。因此，虽然真实意味着
this block of code is going to get executed repeatedly, 该代码块将被重复执行，
until we explicitly break out of it, 直到我们明确打破它，
okay? Now let's test our program one more time. So, 好的？现在让我们再测试一次我们的程序。所以，
quit now our program terminates and we don't see that message 退出，现在我们的程序终止，我们看不到该消息
beautiful. So let's fix the last problem. You saw that when we 美丽的。因此，让我们解决最后一个问题。你看到了，当我们
typed help, these guidelines appeared with so much in 键入帮助，这些准则在
indentation, and here's the reason, look, right here in our code, 缩进，这就是原因，在我们的代码中，
they are already indented. So when we use triple quotes, what we type here 他们已经缩进了。因此，当我们使用三重引号时，我们在此处键入
will be printed exactly as is. So, because we 将完全照原样打印。所以，因为我们
have an indentation here, this indentation will also be printed on the terminal. 在此处有一个压痕，该压痕也将被打印在终端上。
So, let's delete these 所以，让我们删除这些
okay, run the program one more time, type help, 好的，再运行一次程序，输入帮助，
the indentation is gone. Beautiful. Now here's a challenge for you. I want you to 压痕消失了。美丽的。现在这对您来说是一个挑战。我要你去
take this program to the next level. So right now if we type 将此程序带入一个新的水平。所以现在如果我们输入
start we get this message car started. And if we type start again 启动，我们得到此消息汽车启动。如果我们再次键入开始
we get the same message. It would be better if 我们收到相同的消息。如果会更好
we got a message like car is already started so it doesn't make sense to 我们收到一条消息，例如汽车已经启动，因此
start a car twice. Similarly, if we type stop 开车两次。同样地，如果我们输入stop
it says car stopped, if we type it again we get the exact same 它说汽车停了下来，如果我们再次键入它，我们得到的完全一样
message, it doesn't make sense to stop the car twice. So here's what I need you to do 消息，两次停车都没有意义。所以这就是我需要你做的
if the car is stopped and the user tries to stop it again, 如果汽车停了下来，而用户又试图停了下来，
the program should say hey, the car is already stopped, what are you doing? And similarly 程序应该说嘿，汽车已经停了，你在做什么？同样
if the car is already started and the user tries to start it again, 如果汽车已经启动并且用户尝试再次启动它，
the program should yell at the user. So go ahead and make the necessary changes to 该程序应该对用户大吼大叫。因此，继续进行必要的更改
implement this scenario. 实施此方案。
Alright to add this to our program, we need 好的，将其添加到我们的程序中，我们需要
to know if the car is started or not. So there is one more piece of information 知道汽车是否启动。因此，还有更多信息
we need to store in the memory. What is the kind of data we need to store here? 我们需要存储在内存中。我们需要在这里存储什么类型的数据？
A boolean. Is the car started or not, it's a matter of yes 一个布尔值。汽车是否启动，是的。
or no. True or false. So on the top, here 或没有。对或错。所以在顶部，在这里
we can define another variable like started and initially we set it 我们可以定义另一个变量，例如begin，最初我们对其进行设置
to false. So the car is not started, right? Now 虚假。所以汽车没有启动，对吧？现在
when the user types the start command, here we need to check 当用户键入启动命令时，在这里我们需要检查
to see if the car is already started. If not the we'll start it 看看汽车是否已经启动。如果没有，我们将开始
or otherwise we'll yell at the user. So in this block we'll write 否则我们会对用户大吼大叫。因此，在此块中，我们将编写
another if statement, if it's already started 另一个if语句（如果已经开始）
and we print car is already 我们已经打印好车了
started. Otherwise, so if you add an 开始。否则，如果您添加一个
el statement here. And at this point, el声明在这里。在这一点上，
you set started to true. So we start 您将开始设置为true。所以我们开始
the car and we print this message, okay? Now we need to make a similar 汽车，我们打印此消息，好吗？现在我们需要做一个类似的
change for the stop command. So if the car is 更改停止命令。所以如果汽车是
already stopped we need to print a different message. If 已经停止，我们需要打印其他消息。如果
not started, so here we're using the not operator to see 没有开始，所以这里我们使用not运算符来查看
if the car is stopped. So if it's not started that means 如果汽车停了。因此，如果未开始，则意味着
it's stopped, okay? So if it stopped we print 停止了，好吗？所以如果它停止了，我们打印
car is already stopped with 车已经停了
double p's, otherwise so else 双p的，否则
we need to stop the car, how do we do that? We 我们需要停车，我们该怎么做？我们
set started to false. And then we'll print this message. 设置开始为false。然后，我们将打印此消息。
As easy as that. Let's go ahead and run our program. 就这么简单。让我们继续运行我们的程序。
So, initially our car is stopped. So I'm going to type 因此，最初我们的汽车停了下来。所以我要输入
stop, it says the car is already stopped, so lets 停止，它说汽车已经停止了，所以让
start it, okay, now our car is started, let's 启动它，好吧，现在我们的车启动了，让我们
start it one more time. The program is yelling at us. So we can 再开始一次。该程序对我们大吼大叫。所以我们可以
not start the car twice. Beautiful. Now let's stop it 不能两次启动汽车。美丽的。现在停止
it says the car is stopped, let's stop it one more time, we get this message 它说汽车停了，让我们再停一次，我们收到此消息
again. 再次。
In this tutorial, I'm going to talk to you guys about 在本教程中，我将与大家讨论
for loops in python. In the last tutorial, you learned about while loops for循环在python中。在上一教程中，您了解了while循环
you learned that we use while loops to execute a block of code multiple times. 您了解到，我们使用while循环多次执行代码块。
In python we have another kind of loop, that is a for loop, and we use that 在python中，我们还有另一种循环，即for循环，我们使用它
and we use that to iterate over items of a collection, such as a string. 我们使用它来遍历集合的项目，例如字符串。
Because a string is a sequence of characters, so it looks like a collection 因为字符串是字符序列，所以它看起来像一个集合
so we can use a for loop to iterate over each character in a 因此我们可以使用for循环遍历a中的每个字符
string and then do something with it. Here's an example. We type out 字符串，然后对其进行处理。这是一个例子。我们输入
for then we define a variable, this is what we call a loop 然后我们定义一个变量，这就是我们所说的循环
variable. In each iteration, this variable will hold 多变的。在每次迭代中，此变量将保持
one item. So, let's call it item, in 一个项目。所以，我们称它为
here we type out a string like Python, and then 在这里，我们输入一个类似Python的字符串，然后
colon. So with this for loop we can iterate over a string and in each 冒号。因此，有了这个for循环，我们可以遍历一个字符串，并在每个字符串中
iteration this item variable will hold one character at a time 迭代此项目变量一次将容纳一个字符
in the first iteration it will be set to p then 在第一个迭代中，它将被设置为p
in the second iteration it will be set to y, and in the third iteration it will be set to 在第二次迭代中，它将设置为y，在第三次迭代中，它将设置为
t and so on. So here we are inside our for block, t等。所以在这里，我们位于for块中，
because of the indentation here, so whatever we type here will be executed in 由于此处的缩进，因此我们在此处键入的任何内容都将在
each iteration, for now we can simply print this item 每次迭代，现在我们可以简单地打印该项目
now let's run this program and see what happens. 现在让我们运行该程序，看看会发生什么。
So you can see each character in this string is printed on 这样您就可以看到此字符串中的每个字符都印在
a new line. Let's look at another example. In Python we can 新线。让我们看另一个例子。在Python中，我们可以
define lists using square brackets, so let me remove this string from 使用方括号定义列表，所以让我从
here, and define a list using square brackets, 在这里，并使用方括号定义一个列表，
a list is simply a list of items, a list of numbers, a list of 列表只是项目列表，数字列表，
customers, a list of emails, products, blog posts, whatever. 客户，电子邮件，产品，博客文章列表等等。
So here we can define a list of names like Mosh, 因此，我们可以在此处定义名称列表，例如Mosh，
Jon, Sarah, and then go ahead 乔恩（Jon），莎拉（Sarah），然后继续
and run our program so we can see in each iteration we get one name 并运行我们的程序，这样我们就可以看到在每次迭代中我们都有一个名字
and print it on a new line. We can also 并在新行上打印。我们也可以
loop over a list of numbers, for example, 例如，遍历数字列表，
1, 2, 3, 4, let's run it, again 1，2，3，4，让我们再次运行它
we see each number on a new line, but what if we want 我们会在新行上看到每个数字，但是如果我们想要
a list of numbers? We don't to explicitly type out a list 数字列表？我们不会明确输入列表
with let's say 100 or 1000 numbers, we don't want to type, 5, 6 假设有100或1000个数字，我们不想输入5、6
7 all the way to 100. That is when we use the range function. 7一直到100。这就是我们使用范围功能的时候。
So, let me delete this, 所以，让我删除它，
In Python we have a built in function called range, for creating 在Python中，我们有一个名为range的内置函数，用于创建
range of numbers. So, we give it a number, let's say 10, 数字范围。因此，我们给它一个数字，假设是10，
let's run this program, now we can see 让我们运行该程序，现在我们可以看到
here on the terminal we have 0 all the way 在终端上，我们一路为0
to 9. So 10 is not included. 到9。因此不包括10。
So basically when we call the range function, this range creates 因此，基本上，当我们调用范围函数时，该范围会创建
an object, it's not a list, it's a special kind of object we can 一个对象，它不是一个列表，它是一种特殊的对象，我们可以
iterate over, in each iteration this object will spit out a new number. 迭代，此对象将在每次迭代中吐出一个新的数字。
We can also work with a range of numbers here, let's say you want to start 我们也可以在此处处理一系列数字，假设您要开始
from 5, and go all the way to 10. 从5开始，一直到10。
So, let's run our program, now we have the numbers 所以，让我们运行我们的程序，现在我们有了数字
5, 6, 7, and 9. Also, this range 5、6、7和9。此外，此范围
function can optionally take a step, so we can pass 函数可以选择采取步骤，因此我们可以通过
two asa step to this function, 作为此功能的两个步骤，
and when we run our program, we can see our first number 当我们运行程序时，我们可以看到我们的第一个数字
is 5, now we go two steps forward to get 7, 是5，现在我们向前走两步得到7，
once again we go to two steps forward we get 9 and that is 再一次，我们向前走两步，我们得到9，即
the end of our range. So this is the basics of using for loops in python. 我们范围的尽头。因此，这是在python中使用for循环的基础。
Now here's an exercise for you. I want you to write a program 现在，这是一个适合您的练习。我要你写一个程序
to calculate the total cost of all the items in a shopping cart. 计算购物车中所有物品的总费用。
So let's say we have a list of prices like 10, 假设我们有一个价格清单，例如10，
20, and 30, I want you to use a for loop, 20和30，我希望您使用for循环，
to calculate the total cost of all the items in our imaginary shopping cart, 计算我们假想的购物车中所有物品的总成本，
so calculate that, and then print it on the terminal. That's pretty 所以计算一下，然后在终端上打印出来。真漂亮
easy. And you should do it in a couple minutes. 简单的。而且您应该在几分钟内完成。
So as you learned we use for 因此，如您所知，我们用于
loops to iterate over all the items in a collection, 循环访问集合中的所有项目，
a collection can be a string, it can be a list, it can be a range object that is 集合可以是字符串，可以是列表，可以是范围对象，即
returned from the range function. Anything, any kind of object that has multiple 从范围函数返回。任何事物，任何具有多个物体的物体
items. So in this example we're going to use a for loop to iterate over 项目。因此，在此示例中，我们将使用for循环进行迭代
the list of prices. So for item in 价格清单。因此，对于
prices, colon, and by the way this loop variable 价格，冒号以及顺便说一下，此循环变量
we don't have to call this item, can call this anything. For example, in this case 我们不必叫这个项目，可以叫任何东西。例如，在这种情况下
we can rename it to price. So for price, 我们可以将其重命名为价格。因此，为了价格，
in prices. Now in each iteration this 价格。现在在每次迭代中
price will hold one value. In the first iteration it's going to hold 10, then it's 价格将保持一个值。在第一个迭代中，它将保持10，然后是
gooing to be 20, and then it's going to be 30. So we need to define 变为20，然后变为30。所以我们需要定义
another variable to calculate the total so 另一个变量来计算总数，所以
we define that outside of our for loop, let's call it total 我们在for循环之外定义它，我们称其为total
and initially we set it to 0. Now in each 最初我们将其设置为0。现在每个
iteration we get the current price and add it to the total so 迭代，我们得到当前价格并将其加到总数中，这样
we write total equals total plus price 我们写的总数等于总数加价格
or as you learned earlier we can use the augmented 或者如您先前所了解的，我们可以使用增强型
assignment operator to simplify this code. 赋值运算符以简化此代码。
So, after our for loop. This total variable has 因此，在我们的for循环之后。该总变量具有
a total of all the prices we can simply print it here, 所有价格的总和，我们可以在这里简单地打印出来，
or we can use a formatted string, so a string 或者我们可以使用格式化的字符串，所以一个字符串
prefix with f, the other label, like total, 带f的前缀，另一个标签，如total
curly braces to dynamically include some value in our string, 大括号以动态地在字符串中包含一些值，
in this case our total variable. So let's go ahead 在这种情况下，我们的总变量。所以我们继续吧
and run this program, there you go, so the total cost of 并运行该程序，然后就可以了，因此，
all the items in our imaginary shopping cart is 60. 我们想象中的购物车中的所有物品都是60。
In this tutorial I'm going to talk to you guys about nested loops 在本教程中，我将与大家讨论嵌套循环
in python. Using a nested loop basically means adding one loop 在python中。使用嵌套循环基本上意味着添加一个循环
inside of another loop, and with this technique we can do some amazing things 在另一个循环中，并且通过这种技术，我们可以做一些令人惊奇的事情
for example we can easily generate a list of coordinates. So, a 例如，我们可以轻松生成坐标列表。所以，一个
acquired (?) as you know is a combination of x and y 如您所知，获得的（？）是x和y的组合
value. Let's say 0 and 0. Now let's say you wan to generate 价值。假设0和0。现在假设您要生成
a list of coordinates like this. So we have 0 and 0, 这样的坐标列表。所以我们有0和0，
then we'll have 0 and 1, then 0 and 2, next 那么我们将有0和1，然后是0和2，接下来
we're going to change x, so we're going to use 1 for x, 我们将要更改x，因此我们将x用作1，
and once again we're going to use these 3 values for the y coordinates 再一次，我们将使用这3个值作为y坐标
so 1 and 0 then 1 and 1 所以1和0然后1和1
and 1 and 2, you got the point. We can 1和2，你明白了。我们可以
easily generate these coordinates using nested loops. Let me show you. 使用嵌套循环轻松生成这些坐标。让我演示给你看。
So, we start with one loop, let's say for x in 因此，我们从一个循环开始，比如说x in
range 4. With this loop, we can generate value 范围4。通过此循环，我们可以生成值
for the x coordinate. Let's print this on the terminal, 用于x坐标。让我们在终端上打印它，
Okay, so, we get the values, 0 好了，我们得到的值是0
to 3. Now for each x, like 0, we 到3。现在对于每个x，就像0，我们
should generate a few y values. So that is where we use 应该生成一些y值。这就是我们使用的地方
a nested loop. So inside of this loop we're going to add 嵌套循环。因此，在此循环中，我们将添加
another loop, so instead of just printing x first we want to add 另一个循环，所以我们不想添加仅先打印x
another loop, for y in range 另一个循环，范围为y
let's say 3, now we can print x and y together 假设3，现在我们可以一起打印x和y
so, print, here, we use a formatted string. 因此，在这里打印，我们使用格式化的字符串。
to display coordinates like this. So we add parenthesis 显示这样的坐标。所以我们加上括号
inside of this parenthesis first we need to add x so curly braces 首先在此括号内，我们需要添加x这样的花括号
x then a comma followed by x然后是逗号，然后是逗号
another set of curly braces, and y, 另一组花括号，y，
let's run this program and see what we get. 让我们运行该程序，看看会得到什么。
There you go. So, we have these coordinates 妳去所以，我们有这些坐标
0 and 0, 0 and 1, 0 and 2, then you have 0和0、0和1、0和2，那么您有
1 and 0 1 and 1 1 and 2 and so on. So let me explain exactly 1和0 1和1 1和2等等。所以让我确切地解释一下
how this program gets executed. So in the first iteration, 该程序如何执行。所以在第一次迭代中
of our outer loop, x is 0. Now we are 我们的外循环的x是0。现在我们是
on line 2, here we have a new loop which we call an 在第2行，这里有一个新的循环，我们称之为
inner loop. In this inner loop, in the first iteration y 内循环。在此内部循环中，在第一次迭代中y
is going to be 0, so we print 0 and 0 on the 将会是0，所以我们在
terminal. Now the control goes back to line 2 or our 终端。现在，控件返回到第2行或
inner loop. In this second iteration y will be set to 1, but 内循环。在第二次迭代中，y将设置为1，但是
we are still in the first iteration of our outer loop. So 我们仍处于外循环的第一次迭代中。所以
x is still 0, but now y is incremented to 1. x仍为0，但现在y增至1。
So that is why we see 0 and 1 on the terminal. 这就是为什么我们在终端上看到0和1的原因。
Once again, the control goes back to line 2, we are in the third 控件再次回到第2行，我们位于第三行
iteration of our inner loop, so this will continue until our inner loop 内循环的迭代，因此将一直持续到内循环为止
completes. That is when y reaches 2 because 完成。那是当y达到2时，因为
this range function generates number 0 to 3 but not including 此范围函数生成数字0到3，但不包括
3. So we'll have 0 1 and 2. After this inner loop completes, 3.因此我们将得到0 1和2。
then the control goes back to line 1, and at this point we're going to 然后控件返回到第1行，这时我们将转到
be in the second iteration of our outer loop. So x will be 在外循环的第二次迭代中。所以x将是
1, then the control will be moved to line 2, or our inner 1，则控件将移至第2行，即我们内部的
loop, at this point, this range function is going to generate the numbers 0 循环，此时，此范围函数将生成数字0
to 3 one more time. So this inner loop will be executed 3 times. 到3再多一次。因此，此内部循环将执行3次。
And then we'll go back to our outer loop. So this is how 然后我们回到外循环。所以这就是
nested loops get executed. 嵌套循环被执行。
Okay, here's an exercise for you, but this one is a little bit 好的，这是适合您的一种锻炼，但是这个有点
more challenging then the exercises you have done so far. So I really don't 比到目前为止的练习更具挑战性。所以我真的不
expect you to do it, but if you do it, wow, I will be so proud of you, 希望你能做到，但是如果你做到了，哇，我会为你感到骄傲的，
so see what I've done here? Using nested loops, 看看我在这里做了什么？使用嵌套循环
I've written some code to draw this f shape, can you see that? So I 我已经编写了一些代码来绘制此f形，您看到了吗？所以我
let me give you a hint, first of all we have this 让我给你一个提示，首先我们有这个
list, called numbers, in this list we have these values, 列表，称为数字，在此列表中，我们具有这些值，
5, 2, 5, 2, 5, 2. These values determine 5、2、5、2、5、2。这些值确定
the number of x's we have in each line. So, 每行中x的数量。所以，
for example, the first item in this list, this tells us that we should have 例如，此列表中的第一项，它告诉我们应该有
5 x's on the first line. There you go, so 1, 2, 3, 第一行有5 x。你去了，所以1，2，3，
4, 5, on the second line we're going to have 2 x's, 4，5，在第二行，我们将有2 x，
on the third line we're going to have 5 x's like this. 在第三行，我们将有5 x这样的。
So I've written code to convert a simple list of numbers 所以我写了代码来转换一个简单的数字列表
into a shape like this. Now here's a tip for you. 变成这样的形状现在给您一个提示。
Using your for loop you need to iterate over this list. In 使用for循环，您需要遍历此列表。在
each iteration you get one number, this determines the number of x's 每次迭代都会得到一个数字，这决定了x的数量
to be displayed on that particular line. So if you want to cheat, 显示在该特定行上。所以如果你想作弊，
you can get this number and multiply by a string that contains x, 您可以获取该数字并乘以包含x的字符串，
so if you multiply x by 5, we'll get 5 x's, that's not what 因此，如果您将x乘以5，我们将得到5 x，那不是
I want you to do. I want you to use an inner loop here to 我要你做。我希望您在这里使用一个内循环
generate a string that contains 5 x's. So imagine 生成一个包含5个x的字符串。所以想像
in Python we cannot multiply a string by a number 在Python中，我们不能将字符串乘以数字
so to solve this problem we need a nested loop. So go ahead and spend 因此，要解决此问题，我们需要一个嵌套循环。所以继续花钱
five minutes on this exercise. And by the way, do your best to solve this. It is 五分钟的练习时间。顺便说一句，尽力解决这个问题。这是
a little bit challenging, but it's not extremely difficult. It just requires 有点挑战，但这并不是很难。只需要
a little bit of focus. You'll see my solution next. 一点点的关注。接下来，您将看到我的解决方案。
Alright so first we need to iterate over 好吧，首先我们需要迭代
all the items in this list. So for item 此列表中的所有项目。所以对于项目
in numbers, or, you could rename this variable 以数字表示，或者，您可以重命名此变量
to x_count. That is the number of x's 到x_count。那是x的个数
on each line. Okay? Now I told you that if you want to cheat you can write code 在每一行上。好的？现在我告诉你，如果你想作弊就可以编写代码
like this. Print x times 像这样。打印x次
x underline count. If you run this program we get the same x下划线计数。如果您运行此程序，我们将得到相同的结果
output. So this is the beauty of Python, with Python 输出。这就是Python的魅力所在
we can write expressions like this, we can multiply a string by a number to 我们可以编写这样的表达式，我们可以将字符串乘以数字以得出
repeat it. A lot of other programming languages don't support this feature. But 重复。许多其他编程语言不支持此功能。但
for this exercise, I wanted you to imagine that we don't have this feature in Python 对于本练习，我想让您想象一下，我们在Python中没有此功能
so you will have to use an inner loop to solve this problem. Here's how 因此您将必须使用内部循环来解决此问题。就是这样
it works. In the first iteration, x count is going to be 5. 有用。在第一次迭代中，x计数将为5。
So we need to generate 5 x's. How can we do that? 因此，我们需要生成5个x。我们该怎么做？
Well, let's say we define a variable called output and initially set it to 好吧，假设我们定义了一个名为output的变量，并将其初始设置为
an empty string. Now we need to add 5 x's to this string. So, 一个空字符串。现在我们需要在该字符串中添加5 x。所以，
we can use another loop for count in range, 我们可以使用另一个循环来计算范围
of x underline count. So we're using the range function x下划线计数。所以我们正在使用范围函数
to generate a sequence of numbers from 0 up to 生成从0到最大的数字序列
x count. So in our first iteration x count is going to be 5, so x数。因此，在我们的第一次迭代中，x计数将为5，因此
range of 5 would generate the numbers 1, 2, 3, 4. 5的范围将生成数字1、2、3、4。
So this inner loop will be executed 5 times. 因此，此内部循环将执行5次。
That is exactly what this count represents. 这就是这个数字所代表的意义。
So now in each iteration we simply need to 所以现在在每次迭代中，我们只需要
append an x to our output variable. So we set 将x附加到我们的输出变量中。所以我们设定
output, plus, equals x, 输出，加等于x，
and then after this inner loop we simply print 然后在这个内循环之后，我们简单地打印
the output. With his we'll print 5 x's on 输出。有了他，我们将打印5 x
the first row. Then we go to the second iteration of our outer loop. 第一行。然后我们转到外循环的第二次迭代。
At this point x count is going to be 2, now 此时，x计数将为2，现在
on line 3, we're going to reset our output variable to an 在第3行，我们将把输出变量重置为
empty string. So we start over. Then we go to our inner loop, 空字符串。因此，我们重新开始。然后我们进入内在循环，
this loop will be executed 2 times, so we'll append to x's 该循环将执行2次，因此我们将附加到x的后面
to the output variable and then print it, as simple as that. 到输出变量，然后将其打印出来，就这么简单。
So see, it wasn't really that difficult, but it was slightly more difficult then the 所以看，这并不是真的那么困难，但是比
previous exercises. So let's run this program, there you go. 以前的练习。因此，让我们运行此程序，就可以了。
Now if you're adventurous, I want you to modify the values that we have 现在，如果您喜欢冒险，我希望您修改我们拥有的值
in our numbers list, 在我们的号码列表中
to print and l here. 打印和我在这里。
Now in this tutorial we're going to take a closer look at lists. 现在，在本教程中，我们将仔细研究列表。
So, I'm going to define a list of names, let's send them 所以，我将定义一个名称列表，让我们发送它们
to John Bob Mosh 致约翰·鲍勃·莫什（John Bob Mosh）
Sarah and Mary. So, 莎拉和玛丽。所以，
if you print this list here, what we see on 如果您在此处打印此列表，我们将看到
the terminal look exactly like how we define our lists we have 终端看起来就像我们定义列表的方式一样
square brackets, and in between these square brackets we have our item 方括号，在这些方括号之间，我们有我们的物品
our items, so we have 5 strings in this list. 我们的商品，因此此列表中有5个字符串。
So we can also access an individual element using an index just like 因此我们也可以使用索引访问单个元素，就像
how we can access an individual character in a string using an index. 我们如何使用索引访问字符串中的单个字符。
So, here we type out square brackets, 因此，在这里我们键入方括号，
and specify an index. The index of the first item in this list 并指定一个索引。此列表中第一项的索引
is 0. So, let's run this program, there you go, 是0。所以，让我们运行该程序，然后开始，
we get Jon now if you want to print out the third element in this list 如果您要打印此列表中的第三个元素，我们现在得到乔恩
it's index is 2, so names of 2, 它的索引是2，所以名称是2
returns Mosh, now we can also pass 返回莫什，现在我们也可以通过
a negative index here, so negative 1, refers to the last item 此处为负索引，因此负1表示最后一项
in this list, that is Mary, let's run the program, 在这个列表中，那就是玛丽，让我们运行该程序，
there you go, we see Mary, if you pass negative 2, this 你去了，我们看到玛丽，如果你通过负2，这个
returns the second item from the end of the list. So let's run the program, 返回列表末尾的第二项。因此，让我们运行该程序，
there you go, we get sarah, so this is exactly like accessing 到那里，我们得到了萨拉，所以这就像访问
individual characters in a string. We can also 字符串中的单个字符。我们也可以
use a colon to select a range of items, for example if 使用冒号选择项目范围，例如
you pass 2 colon. This will get all items 您通过2个冒号。这将获得所有物品
starting from the index of 2, that is Mosh here all the 从索引2开始，这就是Mosh
way to the end of the string. So let's run this program 到字符串末尾的方式。所以让我们运行这个程序
there you go. We get this list with 3 你去。我们得到这个清单3
items, Mosh, Sarah, and Mary. We can also specify 项，莫什，莎拉和玛丽。我们也可以指定
an end index, let's say 4, so this will return all 结束索引，比方说4，所以这将返回所有
the items up to this index, but it doesn't include the item at this index. 直到此索引的项目，但不包括此索引的项目。
So when we run this program we only see Mosh and 因此，当我们运行该程序时，我们只会看到Mosh和
Sarah, the item I've indexed 4which is the 5th element or 莎拉（Sarah），我索引为4的项目是第5个元素，或者
5th item in this list is not returned. So Mary 不返回此列表中的第5个项目。所以玛丽
is not returned. And also here we have default values, so if you 不返回。而且这里我们有默认值，所以如果您
leave out the end index this expression is going to return 省略该表达式将要返回的结束索引
all the items starting from the index of 2, to the end of the list 从索引2开始到列表末尾的所有项目
or if you leave out the start index, this expression asumes 或者，如果省略起始索引，则此表达式假定
0 as the default index, so it will return all the items from the 0作为默认索引，因此它将返回
beginning to the end of the list. And by the way, 从列表的开始到末尾。顺便说一下，
just like strings, these square brackets here, don't modify our 就像字符串一样，这里的方括号不要修改我们的
original list, they simply return a new list. For example, if we pass 原始列表，他们只是返回一个新列表。例如，如果我们通过
2 here, you can see this returns a new list with 3 items. 2在这里，您可以看到它返回了一个包含3个项目的新列表。
So if you go back here and print our original 因此，如果您返回此处并打印我们的原件
list of names right after you can see it's not affected. 在您看到名称不受影响后立即列出名称。
So here we want to use square brackets with a colon to select a 所以在这里我们要使用带有冒号的方括号来选择
range of items, we get a new list, and by the way we can also 范围内的商品，我们会得到一个新列表，顺便说一下，我们还可以
modify any of the elements in this list. For example let's say we made a mistake and 修改此列表中的任何元素。例如，假设我们犯了一个错误，
the first item shouldn't be john with an h, 第一项不应该是带h的john，
so we want to remove the h, that is very easy, so we access it, 所以我们要删除h，这很简单，因此我们可以访问它，
using an index that is names of 0, and we set it to a new value 使用名称为0的索引，并将其设置为新值
like this. Now, let's print our list 像这样。现在，让我们打印列表
so, you can see the first item in this list 因此，您可以看到此列表中的第一项
is now data. So this is the basics of lists. And here's a 现在是数据。因此，这是列表的基础。这是一个
exercise for you. I want you to write a program to find the largest number 为你运动。我希望您编写一个程序以查找最大数量
in your list. This is a fantastic exercise for beginners, so go ahead and 在您的列表中。对于初学者来说，这是一个很棒的练习，所以继续
spend a few minutes on this, then come back and continue watching. 花几分钟时间，然后再回来继续观看。
Alright, let's 好吧，让我们
define a list of numbers, numbers, with a bunch of random numbers 定义数字列表，数字，以及一堆随机数字
3, 6, 2, 8, 4 and 10. 3、6、2、8、4和10。
Now to find the largest number in this list. We need to define another 现在在此列表中查找最大的数字。我们需要定义另一个
variable let's call it max, this variable will hold 变量我们称其为max，该变量将保持
the largest number, now initially you want to assume 最大的数字，现在您最初要假设
the first item in this list is the largest number. So we set max to 此列表中的第一项是最大的数字。因此我们将max设置为
numbers of 0. We're only assuming that the first item 数字0。我们仅假设第一项
is the largest number. Chances are our assumption is wrong. So we need 是最大的数字。我们的假设很可能是错误的。所以我们需要
to iterate over this list, we need to loop through it, get 要遍历此列表，我们需要遍历它，获取
each item and compare it with max. If it's greater than Max, then 每个项目并将其与最大值进行比较如果大于Max，则
we need to reset max to that number. So in the first iteration we get 我们需要将max重置为该数字。因此，在第一个迭代中，我们得到
3, and max is also 3. Is 3 greater than 3，最大值也为3。大于3
3. No, so we move on, we get the second number, is 3.不，我们继续，我们得到第二个数字，是
6, greater than 3? It is, so we need to reset max 6，大于3？是的，所以我们需要重置最大
to 6. Once again, we continue, we get 2, these two greater 到6。再一次，我们继续得到2，这两个更大
than 6, no it's not, so we move on, then we get 8, 比6，不，不是，所以我们继续，然后我们得到8，
is 8 greater than 6? It is, so we should reset max to 8. 8大于6？是的，所以我们应该将max重置为8。
That is pretty easy. So here we need a for loop, for 那很容易。所以在这里我们需要一个for循环
number in numbers colon 数字冒号
now we need too heck to see if this number is greater than max, 现在我们太想知道这个数字是否大于最大值，
so, if number is greater than max, 因此，如果number大于max，
max colon then we need to reset max, so max 最大冒号，那么我们需要重置最大，所以最大
to this new number, that's all we had to do. 到这个新数字，这就是我们要做的。
So, let's print max, and run our 因此，让我们打印max，然后运行
program we can see the largest number in this list is 10. 程序，我们可以看到此列表中最大的数字是10。
It doesn't matter whether this number is at the end of the list or the beginning. 这个数字是在列表的末尾还是开头都没有关系。
So if I move 10 and put it right at the beginning 所以如果我移动10并把它放在开头
we should still see the same result. Let's run our program, 我们仍然应该看到相同的结果。让我们运行我们的程序，
we still see 10, if I put this somewhere in the middle, our 我们仍然看到10，如果我把它放在中间的某个地方，
program should still work. Let's put it right after 2. 程序仍然可以正常工作。让我们把它放在2之后。
Run the program, we still get 10. 运行程序，我们仍然得到10。
In this tutorial I'm going to talk to you guys about two dimensional 在本教程中，我将与大家讨论二维
lists in python. Two dimensional lists are extremely powerfully and they have a lot 在python中列出。二维列表功能非常强大，并且有很多功能
if applications in data science and machine learning. Here's 在数据科学和机器学习中的应用。这是
an example, In math we have a concept called matrix, which is like 例如，在数学中，我们有一个叫做矩阵的概念，就像
a rectangular array of numbers, let me show you. So 一个矩形的数字数组，让我告诉你。所以
we have 1, 2, 3, 4, 5, 6, 7, 8, 9. 我们有1、2、3、4、5、6、7、8、9。
So we have a rectangular array of numbers. You have rows, 因此，我们有一个矩形的数字数组。你有行，
and columns. So this is a 3 x 3 matrix 和列。所以这是一个3 x 3的矩阵
in math. Now we can model this in python using 在数学上。现在我们可以在python中使用
a 2 dimensional list. A 2 dimensional list is a list where 二维列表。二维列表是一个列表，其中
each item in that list is another list. So, 该列表中的每个项目都是另一个列表。所以，
you want to define a matrix. We set it to a list, each 您想定义一个矩阵。我们将其设置为列表，每个
item in this list, is going to be another list, and that list represents 此列表中的项目将是另一个列表，并且该列表代表
the items in each row. So, the first 每行中的项目。所以，第一个
item in our list is going to be another list, and in this other list we're going to have 我们列表中的项目将是另一个列表，而在另一个列表中，我们将拥有
the values 1, 2, and 3. Now the second 值1、2和3。现在是第二个
item in our matrix list, once again, we have a list, 矩阵列表中的项目，我们又有一个列表，
this list represents the items in the second row. So, 此列表表示第二行中的项目。所以，
4, 5, and 6, and finally 7, 8 4、5和6，最后是7、8
9. So as you can see we have a 2 dimensional list 9.因此，如您所见，我们有一个二维列表
Each item in our outer list is another list. 我们外部列表中的每个项目都是另一个列表。
Okay? So, this is how we can implement a matrix in 好的？因此，这就是我们如何在
python, now to access an individual item in our matrix, python，现在可以访问矩阵中的单个项目，
once again we use square brackets, let me delete this stuff, 再次使用方括号，让我删除此内容，
alright, so how do we access 1 here, 好了，那么我们如何在这里访问1，
well, you start with our list then we add square 好吧，您从我们的列表开始，然后我们添加正方形
brackets first we need to go and get the first item in this list. 首先需要放在方括号中，然后获得此列表中的第一项。
Right? So we pass 0, now this expression 正确的？所以我们传递0，现在这个表达式
returns another list. That is the inner list. In this list, 返回另一个列表。那是内部列表。在这个清单中
let's say you want to access the second item, so, 假设您要访问第二个项目，因此，
once again we add square brackets, and we pass 1, that 再次添加方括号，然后传递1，
is the index of 2 in this list, alright. 是此列表中2的索引，好的。
So if we print this on the terminal 所以如果我们在终端上打印
we get 2. Okay? So using 2 square brackets 我们得到2。好吗？因此，使用2个方括号
we can access individual items in our matrix, and 我们可以访问矩阵中的各个项目，并且
also we can modify these values using this syntax, so, 我们也可以使用这种语法修改这些值，因此，
before printing this, let's change this to 20, so matrix 在打印之前，让我们将其更改为20，这样矩阵
of 0, and 1, let's change it to 20, 的0和1，我们将其更改为20，
and then print it, there you go, it's modified, now here you 然后将其打印出来，然后进行修改，现在就在这里
can also use nested loops to iterate over all the items 也可以使用嵌套循环遍历所有项目
in this matrix. Let me show you. So, 在这个矩阵中。让我演示给你看。所以，
we start with a rows for the rows in matrix, 我们从矩阵中的行开始，
so with this loop, we are iterating over our Matrix 所以通过这个循环，我们迭代了矩阵
list, in each iteration row will contain 1 列表，在每个迭代行中将包含1
list, 1 item, okay? Now, here we need to 清单，1件，好吗？现在，在这里我们需要
use an inner loop. So we need to loop over this row 使用内部循环。所以我们需要遍历这一行
which is a list of items. We can type out 4 这是项目列表。我们可以输入4
item in row colon and print 行冒号并打印项目
item. Okay? So, let's run this program, 物品。好的？因此，让我们运行该程序，
there you go, we get all the item 到那里，我们得到了所有物品
in our list. Hey, I just 在我们的清单中。嘿，我只是
wanted to make a quick announcement. In case you haven't seen my website yet, head over to codewithmosh.com 想发表一个快速公告。如果您还没有看到我的网站，请访问codewithmosh.com
this is my coding school, where you can find plenty of courses 这是我的编码学校，在那里您可以找到很多课程
on web and mobile application development. In fact recently I published a 有关网络和移动应用程序开发的信息。实际上，最近我发布了
comprehensive python course that goes way beyond this beginners 全面的python课程，远远超出了这些初学者
youtube. And if you're serious about learning python and getting a job, I highly encourage YouTube。如果您认真学习python和找到工作，我强烈建议您
you to enroll in this course. Just like this tutorial you can watch it anytime, 您可以参加本课程。就像本教程一样，您可以随时观看，
anywhere as many times as you want, and you will also receive a certificate 您可以随时随地进行多次，并且还会收到证书
of completion that you can add to your resume, and the course comes with a 30 day 完成后，您可以将其添加到简历中，该课程为期30天
money back guarantee, so if you're not happy we'll give all your money back, 退款保证，因此，如果您不满意，我们将退还您所有的钱，
no questions ask. The price for this course is 149 dollars, but 没问题问。这门课程的价格是149美元，但是
the first 200 students can get it for only 15 dollars. So if you're interested, 前200名学生只需15美元就可以得到它。因此，如果您有兴趣，
the link is below this video, click the link, and get started. 该链接位于该视频下方，请单击该链接，然后开始使用。
In this tutorial, I'm 在本教程中，我是
going to talk to you guys about the list methods, or list functions. These are the 将与大家讨论list方法或list函数。这些是
operations that we can perform in a list. So let's define 我们可以在列表中执行的操作。所以我们来定义
a list of numbers, here we pass a bunch of random numbers, like 数字列表，在这里我们传递了一堆随机数，例如
5, 2, 1, 7, and 5、2、1、7和
4. Now there are a number of things we can do with this list, we can 4.现在，我们可以使用此列表做很多事情，我们可以
add new items to it, we can remove existing items, we can check for the existence of an item 向其中添加新项目，我们可以删除现有项目，我们可以检查项目是否存在
these are the operations that we can perform on a list. So, 这些是我们可以对列表执行的操作。所以，
the we type numbers, we can see all these functions or more accurately 我们键入数字，我们可以看到所有这些功能或更准确地看到
the methods that are available in our list objects. 列表对象中可用的方法。
So we can call the append method to add a new item to this list. Let's say 因此，我们可以调用append方法将一个新项目添加到此列表中。比方说
13. Actually, no it's not a good number. 13.实际上，不，这不是一个好数字。
I'm joking I'm not superstitious, so let's add 20, it 我在开玩笑我不是迷信，所以我们加20
doesn't really matter and then print our list 并不重要，然后打印我们的列表
when we run the program we can see 20 is added at the end of this list 当我们运行该程序时，我们可以看到此列表的末尾添加了20
but what if you want to add a number somewhere in the middle, or at the beginning 但是，如果您想在中间或开头添加数字，该怎么办
of our list? For that we use a different method, that is called 我们名单上的？为此，我们使用了另一种方法，即
insert. So, insert, now this method 插。所以，现在插入此方法
takes 2 values, let me show you. So when we open parenthesis 取两个值，让我告诉你。所以当我们打开括号时
look at this little tool tip above the insert method. 看看insert方法上方的这个小工具提示。
You see the first value that we need to pass here is an index, so 您会看到我们需要在此处传递的第一个值是索引，因此
this is the index at which we want to insert this new item. Let's 这是我们要插入此新项目的索引。让我们
say we want to add an item at the beginning of our list, so we passed our index position 说我们想在列表的开头添加一个项目，因此我们通过了索引位置
of 0, and then the second value is the actual 的0，然后第二个值是实际的
object we want to add to this list. Let's say we want to add the number 10, 我们要添加到此列表的对象。假设我们要加10，
now when we print this list you can see that the 现在，当我们打印此列表时，您可以看到
number 10 is placed at the beginning of the list and 数字10放在列表的开头，
all the other items are pushed to the right. We can also remove an item so 所有其他项目都被推到右边。我们也可以删除一个项目，这样
we call remove and pass the item that 我们称其为删除并传递
we want to remove 5. Now we 我们要删除5。现在我们
print our list so we see 5 is gone, and we have 打印我们的列表，所以我们看到5消失了，我们有
2, 1, 7, 4. If you want to remove all the items in the list, you can call 2、1、7、4。如果要删除列表中的所有项目，可以致电
the clear method, so, clear 清除方法，所以清除
this method doesn't take any values, so, we simply 该方法没有任何值，因此，我们只需
call it and it empties our list, all the items are removed. 调用它会清空我们的列表，所有项目都将被删除。
We also have another useful method called hop, 我们还有另一种有用的方法，称为“跃点”
and with this we can remove the last item in a list. 这样我们就可以删除列表中的最后一项。
Let me show you. So, we run our program, you can see the number 4 让我演示给你看。这样，我们运行我们的程序，您可以看到数字4
is removed from the end of our list. Now if you want to 已从我们列表的末尾删除。现在，如果你想
check for the existence of an item in our list, you can call the index method. 如果要检查列表中是否存在某项，可以调用index方法。
So, we call index and pass a value here, like 5 因此，我们调用index并在此处传递一个值，例如5
and this returns the index of the first 这将返回第一个的索引
occurrence of this item. So let's print this on the terminal. 出现此项目。因此，让我们在终端上打印它。
We don't need this line anymore. So the 我们不再需要此行。所以
index of 5 is 0. What if we pass a number that doesn't exist 5的索引是0。如果我们传递一个不存在的数字怎么办
in this list? Let's say 50? Run the program, 在这个清单中？比方说50？运行程序，
we get an error. We get a value error. 50 is not 我们得到一个错误。我们收到一个值错误。 50不是
in the list. There is also another way to check for the existence of an item, 在列表中。还有另一种检查项目是否存在的方法，
we can use the in operator. So, let me show you 我们可以使用in运算符。所以，让我告诉你
we type our 15 in numbers, 我们输入15个数字
earlier we used the in operator with a string, we 之前我们使用in运算符和一个字符串，我们
check for the existence of a character or a sequence of a character in a string, 检查字符串中是否存在字符或字符序列，
now here we're checking for the existence of 50 in the list of numbers, so 现在在这里，我们要检查数字列表中是否存在50，所以
let's print this, we get a boolean value, 让我们打印出来，我们得到一个布尔值，
false, so unlike the index method, this expression, 错误，因此与索引方法不同，此表达式
doesn't generate an error, so it's safer to use this. We also have another 不会产生错误，因此使用此方法更安全。我们还有另一个
method for counting the occurances of an item, let's say we have 计算项目出现次数的方法，假设我们有
another 5 over here. 这里还有另外5个。
Now we can call numbers.count and pass 5 现在我们可以打电话给number.count并传递5
and this should return 2 because we have 2 5s in this list. 这应该返回2，因为此列表中有2个5。
Take a look. There you go. That is pretty useful 看一看。妳去那很有用
now if you want to sort your lists you can call sort method. So, 现在，如果您想对列表进行排序，则可以调用sort方法。所以，
we call the sort method here, this method doesn't take any values so, 我们在这里称为sort方法，该方法没有任何值，
look at he return value, that is none, none 看他的返回值，就是没有，没有
is an object in python that represents the absence of a value. 是python中的一个对象，表示不存在值。
So this sort method doesn't really return any values it simply sorts this 所以这种排序方法实际上并没有返回任何值，它只是对它进行排序
list, in place, so instead of printing the return value 列表，所以不用打印返回值
oft his method, we simply call it to sort our list 通常使用他的方法，我们只需调用它即可对列表进行排序
and then print our list. Take a look. 然后打印我们的列表。看一看。
Now, all the items are assorted in ascending order. We can also 现在，所有项目都按升序分类。我们也可以
sort the items in descending order, so after we sort the list 按降序对项目进行排序，因此在对列表进行排序之后
we can call the reverse method. We can simply reverse 我们可以调用反向方法。我们可以简单地反转
our list. Now let's go ahead and run our program, take a look. 我们的清单。现在，让我们继续运行我们的程序，看一看。
Our numbers are sorted in descending order. 我们的数字按降序排列。
And one last method I want to show you here that is pretty useful is the copy 我想在这里向您展示非常有用的最后一种方法是复制
method. So copy, with this method you can get a copy 方法。所以复制，用这种方法你可以得到一个副本
of our list. So let's define another variable called numbers 2, 我们的清单中。因此，让我们定义另一个称为数字2的变量
now numbers 2, is a copy of our original list. So if 现在数字2是我们原始列表的副本。因此，如果
you make any changes to our original list, if you add new items to it, if you remove 您对我们的原始列表进行了任何更改，如果您向其中添加了新项目，又将其删除了
existing items, these operations are not going to impact our second list. 现有项目，这些操作不会影响我们的第二个列表。
Let me show you. So after we show you a copy of our numbers list 让我演示给你看。因此，在向您显示我们的号码清单副本之后
let's add a new item to this list, so numbers.apphend 让我们向此列表添加一个新项目，以便数字.apphend
ten. So the first list is updated, so now we have a 十。因此，第一个列表已更新，所以现在我们有一个
new item in our first list, then lets print the second list. 新项目添加到我们的第一个列表中，然后让我们打印第二个列表。
Take a look, we don't have the number 10 here, because these are 看一下，我们这里没有数字10，因为这些是
2 independent lists. So these are all the operations 2个独立列表。这些都是操作
that we can perform on lists. We can add new items to a list, we can 我们可以在列表上执行。我们可以将新项目添加到列表中，我们可以
remove exxisitn items, we can check for the existence of an item, we can sort 删除exxisitn项目，我们可以检查项目是否存在，可以进行排序
our list, and copy them. Now here's an exercise for this tutorial, 我们的列表，然后复制它们。现在，这是本教程的练习，
I want you to write a program, to remove the duplicates on our list. 我希望您编写一个程序，以删除列表中的重复项。
Again, this is a fantastic exercise. So spend a few minutes on this and then 同样，这是一个很棒的练习。所以花一些时间，然后
come back and continue watching. 回来继续观看。
Alright let's say we have a list of numbers with 好吧，假设我们有一个数字列表
a bunch of duplicates. So 2, 2, 4, 6, 一堆重复项。所以2、2、4、6
6, 3, 4, 6, 1. We want to remove 6、3、4、6、1。我们要删除
the duplicates. So we need to define another list 重复项。所以我们需要定义另一个列表
let's call that new list. Initially we 让我们称这个新列表。最初我们
set it to an empty list. Then we need to iterate over 将其设置为空列表。然后我们需要迭代
our first list, get each item, and if we don't have that number 我们的第一个列表，获取每个项目，如果我们没有那个数字
in this unix list, then we'll add it to this second list. 在此Unix列表中，然后将其添加到第二个列表中。
As simple as that. So, for number 就如此容易。所以，对于数字
in numbers, now we need to check to see if we 在数量上，现在我们需要检查是否
have this number in the second list. So we use the in 在第二个列表中有此号码。所以我们用
operator. If number not 操作员。如果没有
in units 单位
so if we don't have an operator in this units list, 因此，如果我们在此单位列表中没有运算符，
then we'll need to add it, so units. 那么我们需要添加它，所以添加单位。
apphend number, that's all we have to do. 知道数字，这就是我们要做的。
So, let's go ahead and print the units list 所以，让我们继续打印单元列表
there you go. So you have 2, 4, 你去。所以你有2、4
6, 3,and 1. The duplicates are removed. 6、3和1。重复项将被删除。
In this tutorial I'm going to talk to you guys about another important structure. 在本教程中，我将与大家讨论另一个重要的结构。
in Python called tuple. Tuples are similar to lists 在Python中称为tuple。元组类似于列表
so we can use them to store a list of items. But unlike lists we can 因此我们可以使用它们来存储项目列表。但是与列表不同，我们可以
not modify them, we cannot add new items, we cannot remove existing items, we 不修改它们，我们不能添加新项目，我们不能删除现有项目，我们
tuples are immutable. We cannot mutate or change them. So 元组是不可变的。我们无法对其进行突变或更改。所以
let me show you. So I'm going to start by defining a list of numbers, 让我演示给你看。因此，我将从定义数字列表开始，
1, 2, 3, 4, so we use square brackets to define lists and 1、2、3、4，因此我们使用方括号来定义列表和
parenthesis to define tuples, so if we change this to 圆括号来定义元组，因此如果我们将其更改为
parenthesis, 1, 2, 3. Now we have a 括号1、2、3。现在我们有一个
tuple. So if we type numbers. 元组。因此，如果我们键入数字。
look here we don't have the append or insert methods, so we cannot add new items to this tuple. 看这里，我们没有append或insert方法，因此我们无法向该元组添加新项目。
We also don't have remove clear and pop, we cannot 我们也没有删除清除和弹出按钮，我们不能
remove any of these items here. We only have two methods, count, 在此处删除任何这些项目。我们只有两种方法，计数，
and index. We use count to count the number of occurrences in an item, 和索引。我们使用count来计数一个项目中的出现次数，
and index, to find the index of the first occurrence, 和索引，以找到第一个匹配项的索引，
of an item. So we can only get information about a tuple, we can't change it. 一个项目。因此，我们只能获取有关元组的信息，而不能进行更改。
And by the way, these other methods that you see here, they start 顺便说一句，您在这里看到的其他方法
with two underscores, we refer to these as magic methods, they're more of an advanced 有两个下划线，我们将其称为魔术方法，它们更像是一种高级方法
topic, so they go beyond the scope of this tutorial. If you're interested 因此，它们超出了本教程的范围。如果你有兴趣
to learn bout them. You can get my python course, I've covered them in detail. 学习回合他们。您可以获取我的python课程，我已经详细介绍了它们。
So similar to lists you can address individual items using 与清单类似，您可以使用
squre bracketts,s o we can get the first item like this and then 方括号，所以我们可以得到这样的第一项，然后
print another terminal, there you go, the first item is 1, 打印另一个终端，然后走，第一个项目是1，
but if you try to change the first item we'll get an error, so, 但是，如果您尝试更改第一项，则会收到错误消息，因此，
numbers of 0, we set it to 10 and run our program 数字0，我们将其设置为10并运行程序
there you go. We get this type error, because the tuple object 你去。我们收到此类型错误，因为元组对象
does not support item assignment. So we cannot 不支持项目分配。所以我们不能
mutate or change tuples, they are immutable. Now practically 更改或更改元组，它们是不可变的。现在实际上
speaking, most of the time you'll be using lists, but tuples are also 讲，大多数时候您将使用列表，但是元组也
useful. If you want to create a list of items and make sure 有用。如果要创建项目列表并确保
no where in your program you accidentally modify that list, then it's better to 没有程序中您不小心修改该列表的位置，那么最好是
use a tuple, 使用元组，
In this tutorial I'm going to show you a powerful 在本教程中，我将向您展示一个强大的功能
feature we have in python called unpacking. 我们在python中拥有的功能称为拆包。
So lets find a tuple called coordinates 因此，让我们找到一个称为坐标的元组
and here we pass 3 values, 1, 2, 3. So you imagine these are 我们在这里传递3个值1、2、3
the coordinates for x y and z. Now let's say xy和z的坐标。现在说
we want to get these values and use them in a few expressions, a few complex 我们想要获取这些值并在一些表达式中使用它们
expressions in our program. Maybe we want to include them as part of a large 程序中的表达式。也许我们想将它们作为大项目的一部分
complex formula. So together we'll have to write code like this, 复杂的公式。因此，我们必须一起编写这样的代码，
coordinates of 0, then let's say we want to multiply this 坐标为0，那么我们要乘以
by coordinates of 1, and then multiply it by coordinates 乘以1的坐标，然后乘以坐标
of 2, our code is getting a little bit too long, this is just 2，我们的代码变得太长了，这仅仅是
a very simple example. But let's say we want to use these values in quite a few places 一个非常简单的例子。但是，假设我们要在很多地方使用这些值
in our program, a better approach is to get these values 在我们的程序中，更好的方法是获取这些值
and store them in separate variables like we can get 并将它们存储在单独的变量中，如我们可以得到
coordinates of 0, and store it in x, then you can 坐标为0，并将其存储在x中，则可以
get coordinates of 1 and store it in y. 获得1的坐标并将其存储在y中。
And similarly we get coordinates of 2, 同样，我们得到2的坐标
and then store it in z. Now we started repeating coordinates of 然后将其存储在z中。现在我们开始重复
2 or coordinates of 0 multiple times, we can simply work with these 2或0的坐标多次，我们可以简单地使用这些
variables, x times y times z, that is better. 变量，x乘以y乘以z，那更好。
Right? So nothing new so far. But in Python we have a powerful 正确的？到目前为止，没有什么新鲜事物。但是在Python中，我们拥有强大的功能
feature called unpacking and with that we can achieve 称为拆包的功能，借助该功能，我们可以实现
the same result with far less code. So we can define our variables 具有更少代码的相同结果。所以我们可以定义我们的变量
x, y, and z. And set them to our x，y和z。并将它们设置为我们的
tuple. What we have on line 6 is exactly 元组。我们在第6行上拥有的正是
identical to what we have on lines 2-4. 等同于第2-4行的内容。
So this is a shorthand to achieve the same result. 因此，这是达到相同结果的捷径。
So let me delete this and explain how this code works. 因此，让我删除它并解释该代码如何工作。
When Python interpreter sees this statement, it will get the 当Python解释器看到此语句时，它将获得
first item in this tuple and assign it to the 该元组的第一项并将其分配给
variable. Then it will get the second item in this tuple, then 多变的。然后它将获得该元组中的第二项，然后
similarly we get the third item in this tuple and assign it to 类似地，我们获得该元组中的第三项并将其分配给
the third variable we have here, so we are unpacking 我们在这里拥有的第三个变量，所以我们要拆包
this tuple into 3 variables. Now if we 该元组分为3个变量。现在，如果我们
print x you can see x 打印x您可以看到x
is 1, similarly y is 2, there you go. 是1，类似地y是2，那么您就去了。
So this is unpacking. And by the way this is not 所以这是开箱。顺便说一句，这不是
limited to tuples, we can use this feature for lists as well. So, 仅限于元组，我们也可以将此功能用于列表。所以，
if I change parenthesis to square brackets, now 如果我将括号改为方括号，现在
coordinates is a list, so we can unpack our list into 3 variables 坐标是一个列表，因此我们可以将列表解压缩为3个变量
now we run our program we can see y is 2. 现在我们运行我们的程序，我们可以看到y为2。
In this tutorial I'm going to talk to you about dictionary 在本教程中，我将与您讨论字典
in python. We use dictionaries in situations where we want to 在python中。我们在需要的情况下使用字典
store information that comes as key value pairs. Here's 存储作为键值对出现的信息。这是
an example. Think of a customer. A customer has a bunch of attributes 一个例子。想一想客户。客户有很多属性
like name, email, phone number, address 例如姓名，电子邮件，电话号码，地址
and so on. Now each of these attributes has a value. 等等。现在，每个属性都有一个值。
For example the name can be jon smith the email can be 例如，名称可以是乔恩·史密斯，电子邮件可以是
jon@ gmail.com the phone can be whatevr jon @ gmail.com电话可以是whatevr
so what we have ere is a bunch of key value pairs. So in this 所以我们这里是一堆关键值对。所以在这个
example, our keys are name, email, and phone, 例如，我们的密钥是姓名，电子邮件和电话，
and each key is associated with a value. So this is where we use 并且每个键都与一个值相关联。这就是我们使用的地方
a dictionary. With a dictionary, we can store a bunch of key value pairs. 一本字典。使用字典，我们可以存储一堆键值对。
So let me show you how to define a dictionary in python. 因此，让我向您展示如何在python中定义字典。
Back to our program, I'm going to define a variable, customer, 回到我们的程序，我将定义一个变量，客户，
and here we set it to curly braces. With these curly braces we can 在这里，我们将其设置为花括号。有了这些花括号，我们可以
define dictionary. In this example we have an empty dictionary that doesn't have 定义字典。在此示例中，我们有一个空字典，其中没有
any key value pairs. Now we can add one or more key 任何键值对。现在我们可以添加一个或多个密钥
value pairs in between the braces. So let's 花括号之间的值对。那么让我们
add a key value pair here, I'm going to set the key to a name, and 在此处添加一个键值对，我将把键设置为一个名称，然后
the value to John Smith, then we add a comma, 值给约翰·史密斯（John Smith），然后添加一个逗号，
to add another key value pair. So let's set age to 添加另一个键值对。因此，我们将年龄设置为
30 let's add another key value pair is 30让我们添加另一个键值对是
underline verified and we set this to a boolean. 下划线已验证，我们将其设置为布尔值。
Now what matters here is that these keys should be 现在重要的是这些键应该是
unique. So if I add another key value pair here, 独特。因此，如果我在此处添加另一个键值对，
set age to 40, now look pycharm 将年龄设置为40，现在看起来pycharm
has highlighted the age key, because we have duplicated that and 突出显示了年龄密钥，因为我们已经复制了该密钥，并且
that's not allowed. So each key should be unique in a dictionary, just like, 那是不允许的。因此，每个键在字典中应该是唯一的，就像
the dictionaries we have in the real world, in a real dictionary we have a bunch of words 在现实世界中的字典，在真正的字典中，我们有一堆单词
and they're definition each word is only listed once in a dictionary. 并且它们定义了每个单词在字典中只列出一次。
We don't have the word book twice. So let's delete the second 我们没有两次单词本。所以我们删除第二个
duplicate key value pair, so the keys should be unique, 重复的键值对，因此键应该是唯一的，
and in this example, I'm using strings, but they can also be 在这个例子中，我使用的是字符串，但是它们也可以是
numbers, we're going to look at that later, but the value can be anything, it can be 数字，我们稍后再讨论，但是该值可以是任何值，也可以是
a string, a number, a boolean, a list, literally anything. 字符串，数字，布尔值，列表等等。
Now we can access each item in this dictionary 现在我们可以访问该词典中的每个项目
using square brackets. So, we type customer, 使用方括号。因此，我们键入客户，
square brackets and then specify key like name 方括号，然后指定名称之类的键
and this will return the value associated with 这将返回与
the name key. Let's print it on the terminal, have a look, 名称键。让我们在终端上打印一下，看看，
there you go, so, the name is John Smith, now 你去了，所以，名字叫约翰·史密斯，现在
what if we pass a key that doesn't exist, lets say first date. 如果我们传递了一个不存在的密钥，该怎么办，比如说第一次约会。
You run the program, you get a key error because we don't have 您运行该程序，会遇到一个关键错误，因为我们没有
a key called birth date. Also, if we spell 一个称为出生日期的密钥。另外，如果我们拼写
name with let's say a capital N, we get the same 用一个大写的N作为名字，我们得到相同的
error because we don't have a key with the exact same sequence of 错误，因为我们没有与序列完全相同的键
characters in this dictionary. Now to get around this we can 这本词典中的字符。现在要解决这个问题，我们可以
use the get method, so instead of using the square brackets 使用get方法，而不是使用方括号
we call the get method and specify the key 我们调用get方法并指定密钥
Now if you use a key that doesn't exist here, it doesn't yell at us. For example, 现在，如果您使用此处不存在的钥匙，它不会对我们大喊大叫。例如，
if you pass birth date 如果您通过生日
it simply returns the non value. Earlier I told you that none is an object 它只是返回非值。之前我告诉你，没有东西是物体
that represents the absence of a value. So 表示没有值。所以
instead of getting a key error we get none and we can also option 而不是得到一个关键错误，我们什么也没有，我们也可以选择
supply a default value, for example, if this dictionary doesn't have this 提供默认值，例如，如果此词典中没有此值
key, we can supply the default value, let's say 键，我们可以提供默认值，例如
January 1st 1980. Let's run the program 1980年1月1日。运行程序
now instead of getting none we get this default value. 现在我们得到这个默认值，而不是一无所获。
So, this is how we can access the value associated with the key 因此，这就是我们可以访问与键关联的值的方法
in a dictionary. We can also update these values for example 在字典中。例如，我们也可以更新这些值
before a print statement we can write code like this, customer of 在打印声明之前，我们可以编写这样的代码，
name, let's update the name to jack 名称，让我们将名称更新为jack
smith, now this little warning is telling us here we can put jac 史密斯，现在这个小警告告诉我们在这里我们可以放江淮
smith here instead of defining it once, and then update 史密斯在这里，而不是一次定义，然后更新
it. Don't worry about them, it doesn't really matter. Now with this line if 它。不必担心它们，这并不重要。现在，如果这条线
we print the name of this customer, we should see jack smith, let me show you. 我们会打印此客户的姓名，我们应该去看杰克·史密斯，让我告诉你。
So, I'm going to use the square bracket notation again, let's print 所以，我将再次使用方括号符号，让我们打印
the name of the customer you can see that is updated here, 您可以看到的客户名称已在此处更新，
we can also add a new key here, let's set the 我们也可以在此处添加新密钥，让我们设置
birthdate to some value like january first 出生日期具有某种价值，例如一月一号
1980. And then we can print it here, 1980。然后我们可以在这里打印
so as you see we can easily add new key value pairs 如您所见，我们可以轻松添加新的键值对
to a dictionary. So this is the basics of using dictionaries 到字典。这是使用字典的基础
in python. They're extremely important and they have a lot of applications in the real 在python中。它们非常重要，并且在实际应用中有很多应用
world. Okay, here's an exercise for you. So here we have 世界。好的，这是一个练习。所以我们有
this program that asks our phone number. Let's type 1 这个程序询问我们的电话号码。让我们输入1
234. We type it in digits and then this will translate 234.我们用数字键入它，然后它将翻译
it, to words, take a look. Enter, it prints, 1, 2, 3, 用言语来看一下。输入，它会打印1、2、3，
4. That's a pretty cool program, so go ahead and 4.这是一个很酷的程序，所以继续
spend a few minutes on this exercise, it's pretty easy, I will see you 花几分钟时间做这个练习，这很简单，我会见到你的
next. 下一个。
Alright, so first we need to get the users phone number, we call the input function 好了，所以首先我们需要获取用户的电话号码，我们调用输入功能
with the label phone, we get the result and store it 使用标有手机的电话，我们得到结果并将其存储
in this variable, now let's say the user enters 123 在这个变量中，假设用户输入123
4. So we need to look through this string, get each character and 4.因此，我们需要浏览该字符串，获取每个字符并
translate it to a world, so what we need to implement this scenario. 将其转换为一个世界，因此我们需要实现此方案。
is a dictionary, because a dictionary is a structure that allows us to 是字典，因为字典是一种结构，可以让我们
a key to a value. So we can have a dictionary with keys 价值的关键。所以我们可以有一个带钥匙的字典
like 1234. And we map each of these keys 像1234。而且我们映射了每个键
to a word. So we cannot put digit 1 to 一句话。所以我们不能将数字1放到
the word 1 we can map 2 我们可以映射的单词1
to two you get the point. So let's define 到两个，您就明白了。所以我们来定义
a dictionary, you can call it digits, underline mapping 一本字典，您可以将其称为数字，下划线映射
now this dictionary I'm going to add a few key value pairs. 现在，我将在字典中添加一些键值对。
One, we map it to 1, 2, we 一，我们将其映射到1，2，我们
to 2, 3, to 3, 到2、3、3
and finally, 4 to 4. Now technically we should 最后是4到4。现在从技术上讲，我们应该
add all the digits from 0 to 9, but I don't want to waste all your time 将0到9之间的所有数字相加，但我不想浪费所有时间
typing repetitive things here, you got the point. So lets move on, 在这里输入重复的内容，您就明白了。因此，让我们继续前进，
now we need to look through the phone string. So 现在我们需要查看电话字符串。所以
4 character in phone, we get each 电话中有4个字符，每个字符
character and then use it to access a key value pair in 字符，然后使用它来访问一个键值对
dictionary. So, digits underline mapping 字典。因此，数字下划线映射
we can use square brackets or call the get method, 我们可以使用方括号或调用get方法，
I would prefer to use the get method, so in case the user enters some character 我更喜欢使用get方法，以便在用户输入某些字符的情况下使用
that is not part of our dictionary, our program is not going to yell at them. 那不是我们字典的一部分，我们的程序不会对他们大喊大叫。
So, we call the gt method and pass this character 因此，我们调用gt方法并传递此字符
a the key, and if we don't have this key, we can supply 一个钥匙，如果我们没有这个钥匙，我们可以提供
a default value like exclamation mark, so with this we get a word 像感叹号这样的默认值，因此我们得到一个词
now we need to add this word to an output string, so we can define 现在我们需要将此单词添加到输出字符串中，以便我们可以定义
an output string, initially we set it to an empty string, 输出字符串，最初我们将其设置为空字符串，
in each iteration we get this and add it to our output string. 在每次迭代中，我们都将其添加到输出字符串中。
So, we type output, plus equals. 因此，我们输入输出，加上等于。
This and we should also add a 这，我们还应该添加一个
space at get. So the words are not close to each other, okay? 获得的空间。所以这两个词不是很接近，好吗？
That's all we have to do. Now finally let's print 这就是我们要做的。现在终于让我们打印
this output, run our program, so I want to 此输出，运行我们的程序，所以我想
type 1, 3,4, 5, lets 类型1、3、4、5，
see what we get. We get 1, 3, 4 with an exlamantion 看看我们得到什么。我们得到1、3、4的称赞
mark. 标记。
In this tutorial I'm going to show you something really cool 在本教程中，我将向您展示一些非常酷的东西
that you can do with dictionaries, so here in this program you can type 您可以使用字典进行操作，因此在此程序中，您可以输入
a message like good morning followed by a smiley face, 像早安的消息，然后是笑脸，
when we press enter, we get this beautiful smiley face, or 当按下回车键时，我们会得到一张美丽的笑脸，或者
we can type i am sad, with a sad smiley face 我们可以输入我很悲伤，带有悲伤的笑脸
and it gets translated to this beautiful emoji. 它被翻译成这个美丽的表情符号。
So this is another application if using dictionaries, we have a dictionary 所以这是另一个应用程序，如果使用字典，我们有一个字典
that maps these characters into smiley faces. 将这些角色映射成笑脸。
So lets go ahead and build this program together, we start by 因此，让我们一起构建该程序，我们开始
calling the input function, here we pass a greater than symbol 调用输入函数，这里我们传递一个大于号
as an indicator for the user to type a message, we give that message, store 作为用户输入消息的指示，我们给该消息存储
it here, as you know that is a string, now we need to 如您所知，它是一个字符串，现在我们需要
split this string by a space, so if the user types 用空格分隔此字符串，因此如果用户键入
good morning with a smiley face, we want to break this down into 早上好，笑脸，我们想把它分解成
3 words, good morning, and smiley face. 3个字，早上好，笑脸。
To do that we can call the split method. So we call 为此，我们可以调用split方法。所以我们打电话
message.split and pass message.split和通过
a string with one space as a separator. What this method 一个以一个空格作为分隔符的字符串。这个方法什么
does is basically it goes through this string and anywhere it finds this 基本上是通过该字符串以及任何找到此字符串的地方
character, in this case a space, it uses it as a boundary to 字符，在这种情况下为空格，它将其用作边界
separate this string into multiple words. And then it will return 将此字符串分成多个单词。然后它将返回
a list. Let me show you. So let's store that here, words, and then 一个列表。让我演示给你看。因此，让我们将其存储在此处，然后再用单词
Then print it on the terminal, 然后在终端上打印
let's go ahead and run our program. So if you type good morning 让我们继续运行我们的程序。因此，如果您输入早上好
sunshine, enter, we get a list with three items 阳光，输入，我们得到包含三个项目的列表
each item is a string, okay? Now, 每个项目都是一个字符串，好吗？现在，
back to our program, we need to define a dictionary for mapping special characters 回到我们的程序，我们需要定义一个字典来映射特殊字符
like these 2 into a smiley face, so, 像这两个变成笑脸，所以，
we can call that emojis 我们可以称之为表情符号
set it to curly braces, here we add a key value pair, 将其设置为花括号，这里我们添加一个键值对，
a smiley face, and we map that to a string, 一张笑脸，我们将其映射到字符串，
in this string we want to add an emoji, if you're on a mac keyboard you can press 在此字符串中，我们要添加表情符号，如果您使用的是Mac键盘，则可以按
control command and space and this should bring up 控制命令和空间，这应该引起
this emoji box, if you're on Windows honestly I 这个表情符号框，如果您确实是在Windows上，我
really don't know how you can do this, but there must be applications who do this for you. So lets go 真的不知道如何做到这一点，但是必须有一些应用程序可以为您做到这一点。所以放手
ahead and pick this happy smiley face, good, 向前挑一张幸福的笑脸，好，
now lets add another key value pair, or sad face 现在让我们添加另一个键值对或悲伤的面孔
we map this to, 我们将此映射到
this face here, good. So, we 这张脸在这里，很好。所以，我们
have a list of words now we need to look through this list, get 现在有一个单词列表，我们需要浏览这个列表，得到
each word and potentially map it to an emoji. 每个单词，并可能将其映射到表情符号。
So we can write a for loop for word in words, 因此，我们可以为单词中的单词编写一个for循环，
now we want to go to our dictionary, and see if you have an item with this 现在我们要去字典，看看您是否有与此相关的物品
word as the key. If you have an item with that key, we get 单词作为关键。如果您有带有该钥匙的物品，我们会得到
it's value, otherwise we want to use the same word. So if a user types 它的价值，否则我们想使用相同的词。因此，如果用户输入
good morning, we don't want to translate those words, we just want to return those. So that is the case, 早上好，我们不想翻译这些单词，我们只想返回那些单词。这样的话
where we use the get method to supply a default 我们使用get方法提供默认值
value, so we wan to get an item with a key word, and 价值，所以我们希望得到一个带有关键词的物品，并且
if we don't have an item with that key, we simply use that word as 如果我们没有带有该钥匙的物品，我们只需使用该词作为
the default value. Now similar to the exercise that we did in the last tutorial 默认值。现在类似于我们在上一个教程中所做的练习
we need an output variable. So let's define that here, 我们需要一个输出变量。所以我们在这里定义
output set it to an empty string, now back to line 输出将其设置为空字符串，现在返回到行
9, we get the return value of the get method, 9，我们得到get方法的返回值，
and add it to our output variable. So output 并将其添加到我们的输出变量中。所以输出
plus equals whatever we get from the get method, and finally 加等于我们从get方法得到的结果，最后
we need to append a space at the end. 我们需要在末尾添加一个空格。
That's it, we're done. So let's print the output 就是这样，我们完成了。因此，让我们打印输出
and run our program and I'm going to type good morning 并运行我们的程序，我要输入早上好
sunshine with a smiley face, we get that 阳光带着笑脸，我们明白了
beautiful, let's try the sad face as well, I am sad. 美丽，让我们也尝试悲伤的脸，我很悲伤。
Too bad. Beautiful! So as you can see 太糟糕了。美丽的！如您所见
dictionaries have a lot of use cases in real applications. 字典在实际应用中有很多用例。
Here's a solution from the last tutorial where we created an emoji 这是上一个教程中创建表情符号的解决方案
converter. Now so far we have been writing all our code right here, 转换器。到目前为止，我们已经在这里编写了所有代码，
in app,py, but as our programs grow we need a better way to organize our code. 在app，py中，但是随着程序的增长，我们需要一种更好的方式来组织代码。
We need to break up our code into smaller, more manageable 我们需要将代码分解为更小，更易于管理的代码
and more maintainable chunks which we call functions. So function 还有更多可维护的块，我们称之为函数。所以功能
is a container for a few lines of code that perform a specific 是用于执行特定操作的几行代码的容器
task for example you have learned about a few of the built in functions in 例如，您已经了解了以下任务中的一些内置函数
python like print, and input, each of these functions python像print和input，这些功能中的每一个
have a purpose, they know how to perform a specific task. So when we 有目标，他们知道如何执行特定任务。所以当我们
build large complex programs, we should break up our code into smaller 构建大型的复杂程序，我们应该将代码分解为更小的代码
reusable chunks which we call functions to better organize our code. 可重用的块，我们称之为函数，以更好地组织我们的代码。
And that's what I'm going to show you in this tutorial. So let's write this simple 这就是我将在本教程中向您展示的内容。所以让我们写这个简单
program, for printing a greeting message. So we're going to do a print, 程序，用于打印问候消息。因此，我们将进行打印，
hi there, and lets add another message 嗨，让我们添加另一条消息
welcome aboard. So here we have a simple 欢迎上车。所以在这里我们有一个简单的
program with only two lines of code. Now let's say these two lines 程序只有两行代码。现在让我们说这两行
potentially we're going to need them in other programs so we can put them in a function that 可能我们会在其他程序中需要它们，因此我们可以将它们放在一个函数中，
we can reuse. Let me show you how to do that, so, 我们可以重复使用。让我告诉你如何做，所以，
we start typing out death, that is a reserve keyword in 我们开始输入死亡，这是
Python, and it's short for define. When Python interpreter sees this it Python，它是定义的缩写。当Python解释器看到它时
knows that we're defining a function, next we need to give our function 知道我们正在定义一个函数，接下来我们需要提供我们的函数
a name, lets say greet_user. 一个名字，比如说greet_user。
So all the best practices you learned about naming your variables also apply here, 因此，您了解的有关命名变量的所有最佳做法也都适用于此，
which means we should name our functions with lower case characters 这意味着我们应该用小写字母命名函数
if there are multiple words, we need to separate them using an underscore 如果有多个单词，我们需要使用下划线将它们分开
and you should always, always, always use meaningful 而且你应该永远，永远，永远使用有意义的
descriptive names for your functions. So, here we define a function 功能的描述性名称。所以，我们在这里定义一个函数
called greet user, after that we'll need to add parenthesis 称为greet用户，之后我们需要添加括号
followed by a colon. Now you know that whenever we add a colon at the end of a line 其次是冒号。现在您知道，只要我们在行尾添加冒号
we're telling python that we're defining a block of code. So when we 我们告诉python我们正在定义代码块。所以当我们
press enter, the next line is indented. Now any code that we write here 按Enter键，下一行缩进。现在我们在这里写的任何代码
will belong to this function. So I'm going to move these two lines 将属于此功能。所以我要移动这两行
these two print statements inside of our function. You can simply 函数中的这两个print语句。你可以简单地
press tab to indent them, beautiful, also lets remove 按制表符可以缩进它们，美观，也可以删除
this extra line break, that is better, so these two lines 这个额外的换行符，更好，所以这两行
now are part of our greet user function, so whenever we 现在已经成为我们问候用户功能的一部分，所以无论何时我们
call this function, these two lines will be executed. Okay? Now, 调用此函数，将执行这两行。好的？现在，
let's remove indentation so here we are outside of our function, 让我们删除缩进，这样我们就不在我们的功能范围内了，
let's do a print statement and print start 让我们做一个打印语句并开始打印
after that let's call our function, so greet user. 之后，让我们调用函数，向用户打招呼。
And finally let's do another create statement and print 最后，让我们做另一个create语句并打印
finish. Now we have this little warning here, this 结束。现在我们在这里有这个小警告
underline, if you hover your mouse over this line, this tool was telling you 下划线，如果您将鼠标悬停在此行上，则此工具会告诉您
that we should add two blank lines after a function definition. This is coming from 我们应该在函数定义之后添加两个空行。这是来自
pep8 which is a document that defines the best practices for pep8是一个文档，定义了以下方面的最佳做法
formatting our code. We'll look at that in the future. So for now to make pycharm 格式化我们的代码。以后我们会讨论的。所以现在做pycharm
happy, lets add an extra line break to this function 高兴，让我们为此功能添加一个额外的换行符
so whenever we define a function we need to add two lines breaks after. 因此，每当我们定义一个函数时，我们都需要在其后添加两个换行符。
Okay? so, now let's run our program and see what happens. 好的？因此，现在让我们运行程序，看看会发生什么。
Alright, so we have 4 messages on the terminal 好了，所以我们在终端上有4条消息
first we get the start message then we get the messages 首先我们收到开始消息，然后我们收到消息
coming from our create function, so either and welcome aboard, and finally we see 来自我们的create函数，因此欢迎加入，最后我们看到
the finished message. So let me explain the flow of our program 完成的消息。所以让我解释一下我们程序的流程
when python runs this code it doesn't actually print these 当python运行此代码时，它实际上不会打印这些
two messages on the terminal because these two lines of code are inside 终端上的两条消息，因为这两行代码都在里面
of this function, so they would only get executed if we call 这个函数，所以只有在我们调用时，它们才会被执行
this function. If we don't call this function, these lines don't get executed. 此功能。如果我们不调用此函数，则不会执行这些行。
Okay? So the execution of our program actually starts here, 好的？因此，我们的程序实际上是从这里开始执行的，
the first message that we see on the terminal is the start message. After 我们在终端上看到的第一条消息是开始消息。后
that, Python sees that we are calling the greet function, so Python看到我们正在调用greet函数，所以
it will jump over here and then execute these two lines. 它将跳过这里，然后执行这两行。
Then, it will jump out of this function and continue the normal 然后，它将跳出此功能并继续正常
execution of our program so it will print the finish message on the terminal. 执行我们的程序，以便它将在终端上显示完成消息。
So this is how functions work. Also note that the order of this 这就是函数的工作方式。另请注意，此顺序
code matters, so here we're calling the greet function after 代码很重要，因此我们在此之后调用greet函数
after we have defined it. If you try and call it before you define it you will see an error. 在定义好之后。如果在定义前尝试调用它，将会看到错误。
For example, if we call the greet 例如，如果我们打招呼
user function right here, see we immediately get this red underline 用户功能在这里，看到我们立即得到这个红色下划线
which says unresolved reference, greet user which basically 表示未解决的参考，基本上是向用户打招呼
means python doesn't know what is this greet user, it's not defined anywhere. 表示python不知道这个问候用户是什么，它在任何地方都没有定义。
So we always define our functions first, and then 所以我们总是先定义我们的功能，然后再定义
call them. 给他们打电话。
Here's a function we created in the last tutorial 这是我们在上一个教程中创建的函数
now I got a question for you, what is the difference between 现在我有一个问题要问您，
calling this functions nd the print function of python? The difference 调用此功能和python的打印功能？区别
is that the print function takes some information, in this case 在这种情况下，打印功能需要一些信息
the message that we want to print, but our greet function doesn't take 我们要打印的消息，但我们的问候功能不接受
any information. Wouldn't it be nicer if you could pass the name of the user here and then 任何信息。如果您可以在此传递用户名，然后再传递它，那会更好吗？
instead of saying hi there, you could print the name of the user. So, 不用在那打招呼，您可以打印用户名。所以，
in this tutorial, I'm going to show you how to pass information to your functions, and 在本教程中，我将向您展示如何将信息传递给您的函数，以及
that is pretty easy, so back to the definition of our greet 那很容易，所以回到我们的问候定义
user function, inside of these parenthesis, we can add parameters 用户功能，在这些括号内，我们可以添加参数
these parameters are pale holders for receiving information. 这些参数是接收信息的空白。
For example, you can add a name parameter, and we can pass the 例如，您可以添加名称参数，然后我们可以传递
name of the user when calling this function. So let's pass Jon 调用此函数时的用户名。所以让我们通过乔恩
here, now when we call this function and pass this value 在这里，现在当我们调用此函数并传递此值时
this name parameter will be set to Jon. So it 此名称参数将设置为Jon。所以
will act like a local variable that we defined inside of this function. 将像我们在此函数内部定义的局部变量一样起作用。
Just imagine, we didn't have this parameter, and instead we had 试想一下，我们没有此参数，而是
a variable like name that was set to jump. Now here we could simply 像name这样的变量被设置为跳转。现在在这里我们可以简单地
print the name of this user, so we could use a formatted string, 打印此用户的名称，因此我们可以使用格式化的字符串，
and print the value of the name variable, right? Now, 并打印name变量的值，对吗？现在，
we don't really have this local variable defined in this function 我们实际上没有在此函数中定义此局部变量
we have a parameter, it's exactly the same thing. So 我们有一个参数，这是完全一样的。所以
with these parameters we can receive information in our functions. Now let's go ahead and 使用这些参数，我们可以在函数中接收信息。现在，让我们继续前进，
run this program, so take a look. 运行此程序，所以看看。
We get Hi John welcome aboard, we can take this to the next 嗨，约翰受到大家的欢迎，我们可以将它带到下一个
level. Now we can call this function one more time. So 等级。现在我们可以再调用一次此函数。所以
greet user, and this time supply a different name. Let's say Mary. 向用户打招呼，这次提供了另一个名称。假设玛丽。
So we are reusing our greet function and passing it a different 因此，我们正在重用greet函数并将其传递给其他函数
value. Imagine if we didn't have this function you would have to 价值。想象一下，如果我们没有此功能，您将不得不
repeat this line twice , once for hi jon and another time for hi mary. 重复此行两次，一次为hi jon，另一次为hi mary。
So this is the benefit of defining functions, we can take a few 这就是定义函数的好处，我们可以采取一些措施
lines of code that have a specific purpose and put them inside of a 具有特定目的的代码行，并将其放入
function, so now let's run our program one more time 功能，所以现在让我们再运行一次程序
there you go. So you get hi job, welcome aboard, then you get hi mary 你去。这样您就可以找到高工作，欢迎您上车，然后您就可以好玛丽
welcome aboard. Now note that when a function has a parameter 欢迎上车。现在请注意，当函数具有参数时
we are obligated to pass a value for that parameter. 我们有义务为该参数传递一个值。
So if you remove jon from here and run 因此，如果您从此处删除jon并运行
our program, we get this type error, greet user, 在我们的程序中，出现此类型错误，向用户打招呼，
missing one required positional argument. 缺少一个必需的位置参数。
Argument in programming is the value that we supply to a function, so 编程中的参数是我们提供给函数的值，因此
back to this example, marrying this case is an 回到这个例子，嫁给这种情况是
argument that we pass to the name parameter. And lot of 我们传递给name参数的参数。还有很多
programmers don't know the difference between parameters and arguments and think they are the same. 程序员不知道参数和参数之间的区别，并认为它们是相同的。
But they are not, parameters are the holes or placeholders 但是它们不是，参数是孔或占位符
that we define in our function for receiving information, 我们在接收信息的功能中定义的
arguments are the actual pieces of information that we supply to these functions. 参数是我们提供给这些函数的实际信息。
Okay? So, let's bring back 好的？所以，让我们带回来
this jon string, now we can also define multiple 这个jon字符串，现在我们还可以定义多个
parameters, for example, let's rename this parameter to first name as I told 参数，例如，让我将这个参数重命名为名字
you before, you can right click here, go to refactor and then 您之前，可以右键单击此处，进行重构，然后
rename, or preferably you can use a short cut. So the shortcut for 重命名，或者最好使用快捷方式。所以捷径
this on Mac is shift and f6. 在Mac上，这是shift和f6。
And this brings up the renamed dial up box, here we can change this to first 这将调出重命名的拨号框，在这里我们可以将其更改为first
underline name. Now we can add a second parameter 下划线名称。现在我们可以添加第二个参数
so comma followed by last underline name 因此逗号后跟最后一个下划线名称
so back to our formatted string, let's also print 回到我们格式化的字符串，让我们也打印
the last name, beautiful, so here when calling this function, 姓氏，很漂亮，所以在这里调用此函数时，
then we can supply another argument so jon 那么我们可以提供另一个论点，所以乔恩
smith and lets delete this line we don't really need it anymore 史密斯，让我们删除此行，我们不再需要它了
run our program, take a look, hi jon smith, 运行我们的程序，看看吧，乔恩·史密斯，
so in the last tutorial you learned that whenever 因此，在上一教程中，您了解到
we define parameters for our functions we should always supply 我们为我们的功能定义参数，我们应该始终提供
values otherwise we'll get an error. Let's look at that error one more time. 值，否则我们将得到一个错误。让我们再来看一次该错误。
So In going to delete this second argument and only pass jon. 因此，在删除第二个参数时，仅传递了jon。
Run our program, we get this message, 运行我们的程序，我们收到此消息，
greet user missing one required, position 向用户打招呼，缺少一个必需的位置
argument. So these arguments that you have here like jon 争论。所以你在这里像乔恩这样的论点
and smith you refer to these as positional arguments. 和史密斯，您将这些称为位置参数。
Which means their position or argument matters. In other 这意味着他们的立场或论点很重要。其他
words, the first argument we add here is the value or the first parameter 话来说，我们在这里添加的第一个参数是值或第一个参数
and the second argument is the value for the second parameter. 第二个参数是第二个参数的值。
So if you change their position or order, we'll get different results. 因此，如果您更改他们的头寸或订单，我们将获得不同的结果。
Let's take a look. Let's pass smith first and then 让我们来看看。让我们先通过史密斯，然后再通过
jon. Okay, good, delete, now let's 乔恩好吧，好，删除，现在让我们
go with this, so instead of getting Hi Jon Smith, 这样做，而不是让嗨乔恩·史密斯（Hi Jon Smith），
we get hi smith jon. So that is the reason we refer 我们打招呼史密斯·乔恩。这就是我们提到的原因
to these arguments as positional arguments, they're positioned or 这些参数作为位置参数，它们的位置或
order matters. But in python we also have keyword arguments, and 顺序很重要。但是在python中，我们也有关键字参数，并且
with those the position doesn't matter. Let me show you how they work. So, 与那些位置无关紧要。让我告诉你它们是如何工作的。所以，
let's say here you want to pass Jon as the value for the first 假设在这里您要传递Jon作为第一个的值
name parameter. We can simply specify that here. So first name 名称参数。我们可以在这里简单地指定。所以名字
equals jon. Now what we have here is a keyword argument. 等于乔恩。现在，我们这里有了一个关键字参数。
the key word argument. So this combination of having the parameter name, 关键字参数。因此，具有参数名称的组合
followed by it's value is what we call a keyword argument, and what we get with this keyword 紧随其后的是我们称之为关键字参数的值，以及我们从该关键字得到的值
argument the position doesn't really matter. So here we're supplying 论据立场并不重要。所以我们在这里提供
Jon as an argument fort he first parameter. Now similarly, 乔恩作为第一个参数的论点。现在类似
we can use a keyword argument for smith, so last 我们可以为史密斯使用关键字参数，所以最后
name equals smith, so that we have 2 名字等于史密斯，所以我们有2
keyword arguments. So with these keyword arguments we don't have to worry about 关键字参数。因此，有了这些关键字参数，我们不必担心
the order of the parameters. Now that doesn't mean we should always use keyword arguments. 参数的顺序。现在，这并不意味着我们应该始终使用关键字参数。
Not really. Most of the time we use positional arguments, but 并不真地。大多数时候，我们使用位置参数，但是
in certain situations these keyword arguments helming us improve 在某些情况下，这些促使我们前进的关键字参数会有所改善
the readability of our code. So on line 7 it's quite clear 我们代码的可读性。所以在第7行上很清楚
that we are supplying smith as the last name and jon 我们提供史密斯作为姓氏和乔恩
as the first name. Now in this particular example, even if we didn't have 作为名字。现在，在这个特定示例中，即使我们没有
the keyword arguments, just passing two positional arguments like jon 关键字参数，只传递两个位置参数，例如jon
and smith, would be sufficient, because it's easy to guess 和史密斯就足够了，因为很容易猜到
what is the purpose of these arguments. But sometimes you're dealing with functions 这些论点的目的是什么。但是有时候你在处理函数
and you're passing numerical values to them, in those situations 在这种情况下，您将数值传递给它们
it may not be quite clear what those values represent. Let me show you an example. 这些值代表什么可能还不清楚。让我给你看一个例子。
Let's say we have a function for calculating the total cost of an order, 假设我们有一个用于计算订单总成本的函数，
so we still call that calculate, underline cost, 所以我们仍然称其为计算成本，强调成本，
so when calling this function, you need to supply three pieces of information. 因此，在调用此函数时，您需要提供三条信息。
One is the total cost of all the order items lets say 50 一是所有订单商品的总成本，可以说50
dollars. The other is the shipping cost, let's say 美元。另一个是运输成本，比方说
5 dollars, and the last piece is discount, let's say 0, 5美元，最后一块是折扣，假设0，
.1. Someone reading this code, may not be sure .1。有人在阅读此代码，可能不确定
what these three values represent, in this case, we can improve 这三个值代表什么，在这种情况下，我们可以改善
the readability of this code, by using keyword arguments. So we can 通过使用关键字参数，此代码的可读性。所以我们可以
prefix each value with the name of parameter they target, for example, 在每个值前面加上它们所针对的参数名称，例如，
we can set total to 50 and then 我们可以将总数设置为50，然后
shipping to 5, and then discount to 0.1. 运费至5，然后折扣至0.1。
Now if you give this code to someone else, they 现在，如果您将此代码提供给其他人，他们
can immediately tell what these values represent. So that is the power 可以立即知道这些值代表什么。这就是力量
of keyword arguments. So here's what I want you to take away. 关键字参数。所以这就是我要你带走的东西。
For the most part, use positional arguments, but if you're dealing with 在大多数情况下，请使用位置参数，但是如果您要处理
functions that take numerical values, see if you can improve the 带有数值的函数，看看是否可以改善
readability of your code by using keyword arguments. You simply 通过使用关键字参数来提高代码的可读性。你只是
prefix the arguments that you pass with the name of their parameters and this will 给您传递的参数加上参数名称的前缀，这将
increase the readability of your code. Now there is one more thing you need to know about 提高代码的可读性。现在，您还需要了解一件事
keyword arguments. These keyword arguments should always come after 关键字参数。这些关键字参数应始终放在后面
positional arguments. Let me show you what I mean. So, 位置参数。让我告诉你我的意思。所以，
back to our simple greet user function, let's use a keyword argument 回到我们的简单问候用户函数，让我们使用关键字参数
for the first thing. So, let's set 首先。所以，让我们开始吧
first name to jon and see what happens. So we immediately get this error and 乔恩的名字，看看会发生什么。因此，我们立即收到此错误，
positional argument after keyword argument. 关键字参数之后的位置参数。
So when calling this function we're supplying one keyword argument 因此，在调用此函数时，我们将提供一个关键字参数
and one positional argument, and python doesn't like this. So, 和一个位置参数，而python不喜欢这样。所以，
if you're mixing positional and keyword arguments, you should always use 如果您要混合使用位置参数和关键字参数，则应始终使用
and then the keyword arguments. 然后是关键字参数。
In other words, lets remove this keyword argument here, 换句话说，让我们在此处删除此关键字参数，
so jon is now a positional argument, is targeting the first 所以乔恩现在是一个位置论点，针对第一个
parameter. Now after this positional argument we can 范围。现在，在这个位置论点之后，我们可以
supply any number of keyword arguments, so if you set last name to smith 提供任意数量的关键字参数，因此，如果您将姓氏设置为史密斯
look, python doesn't have any problem with this because we are adding 看起来，python对此没有任何问题，因为我们正在添加
a keyword argument after a positional argument. 位置参数后的关键字参数。
So let's quickly recap, for the most part use positional arguments 因此，让我们快速回顾一下，大部分情况下使用位置参数
if you're dealing with functions that take multiple numerical values 如果您要处理带有多个数值的函数
and it's not quite clear what those values represent, use keyword arguments 还不清楚这些值代表什么，请使用关键字参数
to improve the readability of your code, and finally if 提高代码的可读性，最后是
your passing both positional and keyword arguments, use the 您同时传递位置参数和关键字参数，请使用
keyword arguments after the positional arguments. 在位置参数之后的关键字参数。
So far you have learned how to create functions and send them information using 到目前为止，您已经了解了如何创建函数并使用以下方法发送信息
their parameters in this tutorial I'm going to show you how to create functions that return 它们的参数在本教程中，我将向您展示如何创建返回的函数
values, this is particularly useful if you're doing some kind of 值，如果您正在执行某种操作，这将特别有用
calculation your function and you want to return the result to whoever is using your 计算您的函数，并且您想将结果返回给使用您的函数的任何人
function. let me show you. So let's start by defining a 功能。让我演示给你看。因此，我们先定义一个
function, called square, this function simply calculates 函数，称为平方，此函数仅计算
the square of a number. So we need to add one parameter here, 数字的平方。因此，我们需要在此处添加一个参数，
that is is our number, now here we want to calculate number 那是我们的数字，现在我们要计算数字
times number, that is the square of a number. 乘以数字，即数字的平方。
Now to return this color outside of this function we simply 现在，要在此函数之外返回此颜色，我们只需
use the return statement. So return. Now, 使用return语句。所以回来。现在，
our square function is very simple, it only had one line of code. 我们的平方函数非常简单，它只有一行代码。
But in a real program, you might have a function that has ten lines of code to calculate 但是在实际程序中，您可能有一个包含十行代码的函数来计算
something. So, this return statement is very 某物。所以，这个return语句非常
valuable. So now we can return values to the caller of our function. 有价值的。因此，现在我们可以将值返回给函数的调用者了。
So, with this, when we call the square function, 因此，当我们调用平方函数时，
let's say we give it 3, now this function returns a value, 假设我们给它3，现在此函数返回一个值，
just like an input function of python, this input function 就像python的输入函数一样，这个输入函数
waits for the user to type something and press enter and then it will 等待用户键入内容并按Enter，然后它将
return the user's input as a string so we can get it 以字符串形式返回用户的输入，以便我们获取它
and store it in a variable like this, right? We have the same story with our 并将其存储在这样的变量中，对吗？我们有同样的故事
story, with our square function. So our square function returns the value 故事，具有我们的平方功能。所以我们的平方函数返回值
we can simply get it and store it in a variable. Let's call that 我们可以简单地获取它并将其存储在变量中。叫那个
result. Now, we can print 结果。现在，我们可以打印
result on the terminal, there you go, so result is 9, 结果在终端上，您去了，所以结果是9，
we could also pass this function called 我们也可以传递这个函数
directly inside of the print function without defining a separate variable. 直接在打印功能内部，而无需定义单独的变量。
Sometimes this is useful for writing shorter code, so in this case. 有时，这对于编写较短的代码很有用，因此在这种情况下。
So, in this case, we don't really need this result variable. We simply want to print 因此，在这种情况下，我们实际上并不需要此结果变量。我们只想打印
the square of 3. So, we could simply pass this function 3的平方。因此，我们可以简单地传递此函数
call right here, as an argument for the print 在这里打电话，作为打印的参数
function. So let's delete this variable now our code is 功能。现在让我们删除此变量
shorter so with this we're calling the square function, this returns a 更短，因此我们调用平方函数，这将返回一个
value and we'll pass that value as an argument to the print function. 值，我们将把该值作为参数传递给打印函数。
Okay? When we run this program, we get the exact same 好的？当我们运行该程序时，我们得到的结果完全相同
result. There you go. Now what happens if we don't 结果。妳去现在，如果我们不这样做会发生什么
use a return statement in our function. So in the last example we simply used 在我们的函数中使用return语句。因此，在最后一个示例中，我们只是使用了
a print statement. Let's temporarily remove 打印声明。让我们暂时删除
this return statement and print the result 此return语句并打印结果
on the terminal. Like this. So let's run our program 在终端上。像这样。因此，让我们运行我们的程序
one more time and see what we get. We see two things, the number 再有一段时间，看看我们得到了什么。我们看到两件事，数字
9, and none. What is happening here? Well 9，没有。这是怎么回事出色地
when Python interpreter executes this code, first it will call 当Python解释器执行此代码时，首先它将调用
the square function. So the control moves to the square function 平方函数。所以控制移到平方函数
here we calculate the square of this given number and then print it 在这里，我们计算该给定数字的平方，然后打印出来
on the terminal. That is the reason we see 9 right here, 在终端上。这就是我们在这里看到9的原因，
now, by default, all functions return the value 现在，默认情况下，所有函数均返回该值
none. So if we don't have a return statement 没有任何。因此，如果我们没有退货声明
here, by default python returns none. None 在这里，默认情况下python不返回任何内容。没有任何
is an object that represents the absence of a value, it's like nothing 是一个代表缺少值的对象，就像什么都没有
or null i c, c++ java and Javascript. 或null ic，c ++ java和Javascript。
So, in this example, we didn't have a return statement, and 因此，在此示例中，我们没有return语句，并且
by default python returned none from this function. 默认情况下，python从此函数不返回任何内容。
So, after this square function is executed, the value none 因此，执行此平方函数后，值none
is returned and passed as an argument to the print function, that is the reason 返回并作为参数传递给打印功能，这就是原因
we see none on the second line. So here are the two things 我们在第二行上看不到任何内容。所以这是两件事
you need to take away from this tutorial. By default all functions in Python 您需要阅读本教程。默认情况下，Python中的所有功能
return none. You can change that, so if you have a function that 不返回任何内容。您可以更改它，所以如果您有一个功能可以
calculates something, you can return the result using the return statement. 计算某些东西，您可以使用return语句返回结果。
Here's the code for our emoji converter program that we wrote earlier. 这是我们先前编写的表情符号转换器程序的代码。
If you missed that tutorial, make sure to go back and watch it, as 如果您错过了该教程，请确保返回并观看它，因为
I told you before, there is a table of content right below this video in the 我之前曾告诉过您，该视频下方的内容表
description. So we can simply click on the emoji converter tutorial to watch it. 描述。因此，我们只需单击emoji转换器教程即可观看。
Now, your exercise is to reorganize this code using a function. 现在，您的练习是使用一个函数来重新组织此代码。
So I want you to extract a function in this code, because this algorithm 因此，我希望您在此代码中提取一个函数，因为此算法
for converting these smiley faces into emoji's is something that 可以将这些笑脸转换为表情符号
we probably want to use in a couple different applications. We can use it in a chat 我们可能想在几个不同的应用程序中使用。我们可以在聊天中使用它
application in an email application and so on. We don't want to write all this code every time 电子邮件应用程序中的应用程序等。我们不想每次都写所有这些代码
we want to convert these characters into smiley faces. 我们希望将这些字符转换为笑脸。
So, out of all these lines of code that we have from line 1 to 因此，在从第1行到第3行的所有这些代码行中
line 10, the lines 10-2 belong to our 第10行，第10-2行属于我们
algorithm, all these lines together implement this feature. 算法，所有这些行一起实现此功能。
So, you should put these lines in a separate function, 因此，您应该将这些行放在单独的函数中，
Now, why don't we have the input in this function? Because 现在，为什么我们没有此功能的输入？因为
the input will can come in different forms, currently we're using the import function 输入将以不同的形式出现，当前我们正在使用导入功能
to receive the input from the terminal, but in other applications 从终端接收输入，但在其他应用程序中
we might receive the input from a graphical user interface, so the input can come in 我们可能会从图形用户界面接收输入，因此输入可以输入
different forms. We don't want to put that in our function, because this line will not be reuseable. 不同的形式。我们不想将其放在函数中，因为该行将不可重用。
You want to give our function the actual message, 您想给我们的功能实际的信息，
as a string. We don't care how we got that message. In one 作为字符串。我们不在乎我们如何收到该消息。合而为一
program you might get it from the terminal, in another program you might get it from 程序，您可能会从终端获得它，在另一个程序中，您可能会从
a graphical user interface. So that is the reason this line up code should not 图形用户界面。因此，这就是此排队代码不应出现的原因
be in that function. By the same function, you shouldn't include 处于该功能中。通过相同的功能，您不应该包含
the last line in that function because what we do with the output is different from 该函数的最后一行，因为我们对输出的处理与
one program to another. In this program, we are printing the output 一个程序到另一个。在此程序中，我们正在打印输出
in another program, you might send an output as an email, or as a response in 在另一个程序中，您可以将输出作为电子邮件或作为响应发送给
a chat application, so as a general rule of thumb you're function should 聊天应用程序，因此一般而言，您应该发挥作用
not worry about receiving input and 不用担心收到输入
printing it. These lines of code should not belong to your functions. So go 打印它。这些代码行不应属于您的功能。去啊
ahead and reorganize this code by extracting a function. 并通过提取函数来重新组织此代码。
Alright, on the top, first we need to define our function. So first we type 好的，首先，我们需要定义我们的功能。首先我们输入
def, give our function a name like emoji_ def，给我们的函数起一个名字emoji_
converter, so the name of this function clearly tells me what 转换器，所以此函数的名称清楚地告诉我什么
it does. Each function should be responsible for one and only one task, 是的。每个功能应仅负责一项任务，
and that task should be clearly explained in the name of the function. 并且应该在函数名称中清楚地说明该任务。
So, our emoji converter function should take 因此，我们的表情符号转换器功能应
a parameter, we call that message, that is a string, right? Colon 一个参数，我们称该消息为字符串，对吧？冒号
now we need to move the lines 现在我们需要移动线
5 all the way to the end of our for block 5一直到我们的for块结束
into the function, so let's select all these lines, you can 进入函数，因此让我们选择所有这些行，您可以
cut them from here, by pressing command and x on Mac, or 在Mac上按Command和x，从此处剪切它们，或者
control and x on Windows, then we paste it here, Windows上的控件和x，然后将其粘贴到此处，
as you can see these lines are automatically indented 如您所见，这些行会自动缩进
so, they are part of the emoji converter function, if this didn't happen on your 因此，它们是表情符号转换器功能的一部分，如果您的手机上没有发生这种情况
computer, make sure to select these lines and use the 计算机，请确保选择这些行并使用
tab to indent them. Alright, so here's our emoji converter function 标签以使其缩进。好了，这就是我们的表情符号转换器功能
beautiful. Now after that 美丽的。在那之后
in the main flow of our program, first we get the input from the user 在程序的主要流程中，首先我们从用户那里获得输入
we store it in this variable message and then we call 我们将其存储在此可变消息中，然后调用
emoji converter and pass this message, 表情符号转换器并传递此消息，
this function should return a value, that is what we use to calculate 这个函数应该返回一个值，这就是我们用来计算的
the end of this function, so right after this for block we need to add 该函数的结尾，因此在此for块之后，我们需要添加
a return statement, return output, 返回语句，返回输出，
now that our function returns a value, we can get it and store it 现在我们的函数返回了一个值，我们可以获取并存储它
in a separate variable, let's call that result 在一个单独的变量中，让我们称之为结果
and then we can simply print that here, or 然后我们可以在这里简单地打印出来，或者
we can make this code shorter, we don't really need this code here so we can simply 我们可以使这段代码更短，我们在这里实际上并不需要此代码，因此我们可以简单地
call the emoji converter, and print the result. 调用表情符号转换器，然后打印结果。
Like this. Now here we have an underline because 像这样。现在这里有一个下划线，因为
as I told you before we need to blank lines after 就像我之前告诉你的，之后我们需要空白行
our function definitions. So currently we have only one blank line 我们的功能定义。所以目前我们只有一个空白行
we need to add another black line, good, let's go ahead, 我们需要添加另一条黑线，好的，让我们继续前进，
and run this program, and make sure everything works as before 并运行该程序，并确保一切正常
so I'm going to type a message like good morning with a smiley face 所以我要像笑脸一样打个早安
good, let's run it one more time, times that, 好，让我们再运行一次，
to add okay beautiful, so, here's the 要添加好漂亮的东西，所以，这是
final result, we defined this function called 最终结果，我们定义了此函数，称为
emoji converter, this function takes a parameter called message. 表情符号转换器，此函数采用一个称为message的参数。
And finally returns the output. 最后返回输出。
In this tutorial I'm going to teach you how to handle errors in your 在本教程中，我将教你如何处理自己的错误
python programs, so let's start by writing a small program python程序，所以让我们从编写一个小程序开始
to get the user age from the terminal. So we call the input variable 从终端获取用户年龄。所以我们称输入变量
input, and a label here, 输入和此处的标签，
like age, this returns a string, so we need to pass it to 像age一样，它返回一个字符串，因此我们需要将其传递给
the end funciton and store the result in 结束函数并将结果存储在
a variable called age, now let's print age to make sure you have 一个名为age的变量，现在让我们打印age以确保您拥有
implemented everything properly we run our program, we type 正确执行我们运行的程序的所有内容，然后键入
20, 20 is printed here, beautiful, now look at 20，这里印有20，很美，现在来看
the exit code of this program, exit code 0 means 该程序的退出代码，退出代码0表示
our program terminated successfully, there were no errors, but what if 我们的程序成功终止，没有错误，但是如果
we run this program one more time and instead of entering 我们再运行一次该程序，而不是输入
a numerical value, we enter something like asd. 一个数值，我们输入类似asd的值。
We get a value error with his message invalid literal 我们收到他的消息无效文字的值错误
for int with base 10. Basically what this message is telling 用于以10为底的int。基本上，此消息告诉您什么
us is that this string asd does not contain 我们是这个字符串asd不包含
a valid home number that can be converted to an integer. Now look at the exit 可以转换为整数的有效家庭电话号码。现在看看出口
code of this program, exit code 1 means our exit code crashed, 该程序的代码，退出代码1表示我们的退出代码崩溃了，
so 0 always means success and anything but 0 means crash 所以0总是表示成功，而0之外则表示崩溃
now as a good python programmer you should anticipate this situation. 现在作为一名优秀的python程序员，您应该预见到这种情况。
You don't want to let your entire program crash just because the user entered 您不想仅仅因为用户输入而让整个程序崩溃
an invalid value. So instead of letting the program 无效的值。所以不要让程序
crash you should handle the situation and print a proper error message, and 崩溃时，您应该处理这种情况并打印正确的错误消息，并且
that's what I'm going to show you in this tutorial, now before we get any further 这就是我将在本教程中向您展示的内容，现在我们将继续进行介绍。
look at the type of error we get here, value error, 看看我们得到的错误类型，值错误，
so remember this, we're going to get back to this shortly 所以请记住这一点，我们将在不久后回到这一点
now how can we handle these errors, in python we have a construct called 现在我们如何处理这些错误，在python中，我们有一个名为
try accept we use that to handle errors. 尝试接受我们使用它来处理错误。
Let me show you how it works. So on the top 让我告诉你它是如何工作的。所以在顶部
we type try: now as you know we are defining 我们输入try：现在，如您所知，我们正在定义
a code block so, I'm going to move these two lines, 一个代码块，所以，我将移动这两行，
inside of our try block so press tab here. 在我们的try块中，因此请在此处按Tab。
And remove this black line, now these two lines are part of our 删除这条黑线，现在这两行是我们的一部分
try block, right? So after try we type 尝试阻止，对不对？所以尝试后，我们输入
accept, and then we add the type of the error 接受，然后我们添加错误的类型
that our program may encounter, that is value error 我们的程序可能会遇到的，那就是值错误
okay? Then, we add a colon and in this block we can 好的？然后，我们添加一个冒号，在此代码块中，我们可以
define what should happen if our program encounters 定义如果我们的程序遇到该怎么办
an error of type value error. In this case we want to print 类型值错误的错误。在这种情况下，我们要打印
a proper error message, so print, 正确的错误消息，请打印，
invalid value. So with this try and accept we are telling python 无效值。因此，通过尝试并接受，我们正在告诉python
hey, go ahead and try running one or these two lines of code, 嘿，继续尝试运行其中一两行代码，
if you encounter, an error of type. Value error 如果遇到，则为类型错误。值错误
then instead of crashing the program, try this error message on the terminal 然后不要崩溃程序，请在终端上尝试此错误消息
so this is how this works. Now more accurately in programming 所以这就是它的工作方式。现在可以更准确地进行编程
we reefer to this kind of error as an exception. So an exception 我们将这种错误视为例外。所以一个例外
is a kind of error that crashes our program. So our 是一种使我们的程序崩溃的错误。所以我们
user enters an invalid value, this line of code 用户输入的无效值，此行代码
in line 2 will raise an exception, and on line 4 will catch it 第2行将引发异常，第4行将捕获异常
and print this error message, so our program will no longer 并打印此错误消息，因此我们的程序将不再
crash. Let me show you. So let's go ahead and run this 碰撞。让我演示给你看。所以让我们继续运行
age 20, everything 20岁，一切
works just like before and the exit code is 0, let's 就像以前一样工作，退出代码为0，让我们
rerun this program, and enter asd, 重新运行该程序，然后输入asd，
so we get this proper error message invalid error menu and once again 因此，我们得到此正确的错误消息无效的错误菜单，然后再次
the exit code is 0, so that means our program completed successfully. 退出代码为0，这意味着我们的程序已成功完成。
Didn't crash, now, we can also handle different kinds of 没崩溃，现在，我们也可以处理不同种类的
errors or exceptions, for example right when we get the age 错误或例外情况，例如在我们达到年龄时
let's define a variable income and set it to 20,000. 让我们定义一个可变收入并将其设置为20,000。
And then define another variable called risk and set it 然后定义另一个称为风险的变量并进行设置
to income divided by age. 收入除以年龄。
Let's run this program and enter 0 as the game to see what happened. 让我们运行该程序并输入0作为游戏，看看发生了什么。
So 0 is obviously a numerical value 所以0显然是一个数值
so when we enter this value, technically we shouldn't get any exceptions. 因此，当我们输入此值时，从技术上讲，我们不会出现任何异常。
Take a look. Our program crashed, we 看一看。我们的程序崩溃了，我们
did a 0 division error, because we cannot divide a number by 0. 发生了0除法错误，因为我们无法将数字除以0。
Once again look at the exit code, so we couldn't catch this kind of error or 再次查看退出代码，因此我们无法捕获此类错误或
this kind of exception with this accept block. 这种带有接受块的异常。
Accept block is only cashing exceptions of type value 接受块仅是类型值的兑现例外
error. And this happens when we try to convert a nonnumerical value, 错误。当我们尝试转换非数值时，就会发生这种情况，
to an integer. So in a situation like this. We should handle 到一个整数。所以在这样的情况下。我们应该处理
different kinds of exceptions, we can add another 不同种类的异常，我们可以添加另一个
except statement for an exception of type 0 类型为0的异常的except语句
division error. Now in this block we can print a 除法错误。现在，在此块中，我们可以打印一个
different kind of message, like age cannot be 不同的讯息，例如年龄
0. Let's run our program one more time. Now, 0.让我们再运行一次程序。现在，
I'm going to enter 0 as the age so we get this 我要输入0作为年龄，所以我们得到这个
error message age cannot be 0 and look at the exit code. 错误消息的年龄不能为0，并查看退出代码。
It's 0, so our program didn't crash, so to recap, we 它是0，所以我们的程序没有崩溃，所以回顾一下，我们
`used try accept blocks to handle exceptions that are `尝试使用try accept块来处理以下异常
raised in our programs, as a good programmer you should always anticipate 在我们的程序中提出来的，作为一名优秀的程序员，您应该始终期待
these kind of exceptions and handle them properly. 这些异常，并正确处理它们。
In this tutorial I'm going to talk to you guys about comments in python. 在本教程中，我将与大家讨论python中的注释。
We use comments to add notes or comments to our programs. 我们使用注释为程序添加注释或注释。
For example, here I'm going to make a print statement, 例如，在这里我要做一个打印声明，
sky is blue. Now, before that, I 天空是蓝色的。现在，在那之前，我
can add a comment using a hi sign and then whatever we type here 可以使用hi符号添加注释，然后在此处输入任何内容
is going to get ignored it's not going to get executed. Let me show you so 将被忽略，将不会被执行。让我给你看
let's run this program, look we only see this 让我们运行这个程序，看起来我们只会看到这个
message. Sky is blue. So with this comment we can explain 信息。天空是蓝色的。因此，通过此评论，我们可以解释
something about our code, we can use it as reminders to fix things or 关于我们的代码的某些内容，我们可以将其用作提醒以修复问题或
clear things up, or we can use it to communicate things with other developers 清除问题，或者我们可以使用它与其他开发人员进行交流
reading our code, why we have written this code in a certain way. 阅读我们的代码，为什么我们要以某种方式编写此代码。
These are good use cases for using comments, we can also 这些是使用注释的好用例，我们也可以
have comments over multiple lines, so we can simply add more 对多行有评论，所以我们可以简单地添加更多
comments, each line should start with a new hi sign. Now 注释，每行应以新的hi符号开头。现在
one thing you need to avoid when using comments is explaining what the 使用注释时需要避免的一件事是解释
code does. So here's an example of a bad comment. 代码呢。因此，这是一个不好评论的例子。
Let me just delete these two lines, and with this comment I'm going to 让我删除这两行，并在此注释中
say print sky is blue. Why 说打印的天空是蓝色的。为什么
is this a bad comment, because it's telling me the obvious, it's telling me 这是一个不好的评论，因为它告诉了我显而易见的事情，它告诉了我
this slide is going to print sky is blue. Now the problem with this comment is 这张幻灯片要打印的天空是蓝色的。现在，此评论的问题是
that apart from being verbose and repetitive, if you come here, 除了冗长和重复之外，如果您来到这里，
and change sky to ocean, now this comment gets 并改变天空为海洋，现在这个评论得到了
outdated. So overtime we change this code, then we have to come back and 过时的。所以加班，我们更改此代码，然后我们必须返回
modify the corresponding comment. So I've seen some developers 修改相应的注释。所以我看过一些开发人员
add comments in front of their functions, for example, they define 在其功能前面添加注释，例如，它们定义
a function let's say a square that takes a number 一个函数，假设一个带数字的正方形
and simply returns number times number. 并简单地返回数字乘以数字。
But it is obvious that this function calculates and returns the 但是很明显，此函数会计算并返回
square of the given number. So there is really no need to add a comment and 给定数字的平方。因此，实际上没有必要添加评论并
explain that. Calculates and returns the 解释一下。计算并返回
square of a number. This is very repetitive and it creates 一个数字的平方。这是非常重复的，它创建了
noiser code. Someone else reading your code they get distracted with all 干扰代码。其他人阅读您的代码后，他们会全神贯注
these unnecessary comments, so use comments to explain whys and hows. 这些不必要的评论，因此请使用评论解释原因和方式。
Not why's if you have made certain assumptions, we can use 不是为什么，如果您做出某些假设，我们可以使用
comments to explain those assumptions. Or we can use them to add notes to remind yourself 评论以解释这些假设。或者我们可以使用它们添加注释以提醒自己
or other developers to do something in the code. 或其他开发人员在代码中做某事。
So comments are good, but too much of a good thing is a bad thing. 因此，评论是好的，但过多的好事却是坏事。
In this tutorial I'm going to talk to you guys about classes in python. 在本教程中，我将与大家讨论python中的类。
Classes are extremely important in programming and they're not 类在编程中非常重要，但不是
specific to python, in fact, a lot of other programming languages 特定于python，实际上，还有许多其他编程语言
do support the notion of classes. We use classes to define new types. 确实支持类的概念。我们使用类来定义新类型。
For example, so far you have learned about the basic types in Python 例如，到目前为止，您已经了解了Python中的基本类型
like numbers, strings, and booleans, 像数字，字符串和布尔值，
these are the basic or simple types in python, you also learn 这些是python中的基本或简单类型，您还可以学习
about a couple of complex types like lists and 关于一些复杂的类型，例如列表和
dictionaries. While these types are extremely useful, they cannot 字典。尽管这些类型非常有用，但它们不能
always be used to model complex concepts, for example, think about 总是用来为复杂的概念建模，例如，考虑
the concept of a point, or a shopping cart. A shopping cart is not 点或购物车的概念。购物车不是
a boolean, it's not a list, it's not a dictionary, it's a different kind of 布尔值，不是列表，不是字典，是另一种类型
thing. So we can use classes to define new types to 事物。因此，我们可以使用类来定义新类型
model real concepts. Now in this new model I'm going to show you how to 模型真实的概念。现在，在这个新模型中，我将向您展示如何
define a new type called point, and this new type is going to have methods 定义一个称为point的新类型，该新类型将具有方法
for working with points. For example, back to our main program. Let's 点的使用。例如，回到我们的主程序。让我们
create a list, numbers, 1, 2, 3, 创建一个列表，编号为1、2、3，
you know that here, when we type that dot, 您知道在这里，当我们键入该点时，
functions or methods available in list objects, now similar to this, 列表对象中可用的函数或方法，现在与此类似，
we're going to create a new type called point, this point is 我们将创建一个称为point的新类型，这一点是
going to have metas like move, draw, get, 将具有诸如移动，绘制，获取，
distance from another point, these are the operations that we can 到另一点的距离，这些是我们可以进行的操作
perform on points. So let me show you how to do this. 在点上执行。因此，让我向您展示如何执行此操作。
We start by defining a class by using the class keyword, 我们首先使用class关键字定义一个类，
and right after that we give our class a name. Now look at the 之后，我们给班级起一个名字。现在看看
naming convention I've used here. I've capitalized the first letter here, this is what we call 我在这里使用的命名约定。我在这里大写了第一封信，这就是我们所说的
a pascal naming convention. So the naming convention we Pascal命名约定。所以我们的命名约定
used for naming our classes is different from the convention we use for naming 用于命名类的习惯与用于命名的惯例不同
our variables and functions. For variables and functions we always 我们的变量和函数。对于变量和函数，我们始终
use lower case letters and we separate multiple words using 使用小写字母，我们使用
an underscore. But when naming classes, we don't use an underscore 下划线。但是在命名类时，我们不使用下划线
to separate multiple words, instead we capitalize 分隔多个单词，而是大写
the first letter of every word. So in this case our class has only a single 每个单词的第一个字母。因此，在这种情况下，我们的班级只有一个
word, if you had multiple words, let's say email client 单词，如果您有多个单词，假设是电子邮件客户端
look I've capitalized the first letter 看起来我大写了第一个字母
of every word. Once again, this is called pascal naming convention 每个字。再一次，这称为Pascal命名约定
and it comes from the old pascal language that you might have heard of. 它来自您可能听说过的古老的Pascal语言。
So, back to our point class. Here we add 所以，回到我们的重点课。在这里我们添加
a colon which means we're going to define a block, now 冒号，这意味着我们现在要定义一个块
in this block we can define all the functions or methods that belong 在此块中，我们可以定义所有属于该函数或方法的函数
to points, for example, we can define a function called 例如，我们可以定义一个函数
move for moving a port, now note that as soon as we 为移动端口而移动，现在请注意，只要我们
type open parenthesis, pycharm automatically adds self here, 输入开括号，pycharm会在此处自动添加自我，
this is a special keyword and we're going to get back to this shortly. 这是一个特殊的关键字，我们将在不久之后再讲。
So, for now, in this method, let's print 所以，现在，用这种方法，让我们打印
move on the terminal, now let's define another 在终端上移动，现在让我们定义另一个
method like draw, so define draw 像draw这样的方法，所以定义draw
and in this method, let's print draw on the terminal, now 然后使用这种方法，现在在终端上打印绘图
let's remove the indentation, we're done 让我们删除缩进，我们完成了
with the definition of our point class, so we need to add two line breaks 与我们的点类的定义，所以我们需要添加两个换行符
okay, so with this class we defined a new 好的，所以在这个课程中，我们定义了一个新的
type with this new type we can create new objects, so 使用这种新类型进行键入，我们可以创建新对象，因此
an object is an instance of a class, a class simply defines 一个对象是一个类的实例，一个类只是定义
the blueprint or the template for creating objects, and 用于创建对象的蓝图或模板，以及
objects are the actual instances based on that blue print. 对象是基于该蓝图的实际实例。
So we can have tens of hundreds of points on the screen, these are the 所以我们可以在屏幕上有数以百计的点，这些是
objects or the instances. So to create an object, 对象或实例。因此，要创建一个对象，
we type out the name of our class and then call it like a function 我们输入类的名称，然后像函数一样调用它
this creates a new object and then returns it. So then we can store 这将创建一个新对象，然后将其返回。这样我们就可以存储
that object in a variable, let's call that point 1, 该对象在变量中，我们称其为1，
there you go, now when we use the dot operator. 现在，当我们使用点运算符时，就可以了。
Look, we have these two methods that we 看，我们有这两种方法
defined, draw and move, we also have a bunch of other methods that we 定义，绘制和移动，我们还有很多其他方法
start with two underscores, these are called magic methods 从两个下划线开始，这些被称为魔术方法
we'll look at them later in the course. Now, let's call the draw method 我们将在本课程的稍后部分介绍它们。现在，让我们调用draw方法
of our point object, and run our program 点对象，然后运行我们的程序
so you can see draw is printed on the terminal. Now 这样您就可以看到在终端上打印了抽奖。现在
apart from methods these objects can also have attributes and these attributes 除了方法之外，这些对象还可以具有属性，并且这些属性
are like variables that belong to a particular object. For example, 就像属于特定对象的变量一样。例如，
here, after we've defined .1. 在我们定义.1。之后
We can set .1.x to 我们可以将.1.x设置为
10. And .1.1 to 20. 10.和.1.1至20。
Now we can easily print out these attributes, let's print 现在我们可以轻松打印出这些属性，让我们打印
.1.x and run our program one more time .1.x并再次运行我们的程序
take a look, so the x coordinate of .1 is 10. 看一下，所以.1的x坐标是10。
Now we can create another object, let's call that.2 现在我们可以创建另一个对象，我们称之为2。
so .2 once again we type out the name 所以.2我们再次输入名称
of our class and then call it like a function. Now this object is completely 类，然后像函数一样调用它。现在这个物体已经完全
different then the first object. So if you print 与第一个对象不同。所以如果你打印
.2.x 2.x
look we get this attribute error, because this point object doesn't have an 看起来我们得到这个属性错误，因为该点对象没有
attribute called, so each object is a different 属性被调用，所以每个对象都是不同的
instance of our points class. Now here 点类的实例。现在在这里
we can assign a value to .2.x. Let's 我们可以为.2.x分配一个值。让我们
send that to 1, and then run our program so we can see the 将其发送到1，然后运行我们的程序，这样我们就可以看到
x coordinates of .2 is 1. So to recap .2的x坐标为1。
we use classes to define new types, these types can have 我们使用类来定义新类型，这些类型可以具有
methods that we define in the body of the class and they can also 我们在类的主体中定义的方法，它们也可以
have attributes that we can set anywhere in our programs. 具有可以在程序中的任何位置设置的属性。
You have learned how to create new types using classes 您已经了解了如何使用类创建新类型
now therein a tiny problem in this implementation. 现在，在此实现中存在一个小问题。
We can create a pooint object without an x or y coordinate 我们可以创建一个没有x或y坐标的点对象
let me show you. So point we create this 让我演示给你看。所以点，我们创建这个
object here, and before we set point.x let's 在这里设置对象，然后再设置point.x
print point .x run our program 打印点.x运行我们的程序
we get this attribute error which you 我们得到这个属性错误，你
saw in the last tutorial, so point object has no attribute called x 在上一教程中看到了，所以point对象没有名为x的属性
This is the problem we have here, it is possible, 这是我们这里的问题，有可能，
to have a point object without an x or y coordinates. 具有没有x或y坐标的点对象。
And that doesn't really make sense, because whenever we talk about a point, 这真的没有道理，因为每当我们谈论一个要点时，
we ned to know where that point is located. To solve this problem, we 我们需要知道该点的位置。为了解决这个问题，我们
use a constructor. A constructor is a function that gets called 使用构造函数。构造函数是一个被调用的函数
at the time of creating an object. So here on line 9, when creating this 在创建对象时。所以在第9行，当创建这个
point object, we want to pass values for x or y 点对象，我们要传递x或y的值
coordinates, let's say 10 and 20, and with this, 坐标，比如说10和20，并以此，
this point object that we get here, will have it's 我们到达这里的这一点对象将具有
x and y coordinates initialized. So how do we do this? x和y坐标已初始化。那么我们该怎么做呢？
We need to add a special method in this class called constructor. 我们需要在此类中添加一个特殊的方法，称为构造函数。
So, on the top, I define a new function, 因此，在顶部，我定义了一个新函数，
look at the name of this function, double underscore init, double under 看一下这个函数的名字，双下划线init，双下
score. So init is short for initialized, and this is the 分数。所以init是初始化的简称，这就是
function or the method that gets called when we create a new point object. 创建新的点对象时调用的函数或方法。
Now, press enter, so this automatically adds, 现在，按Enter，这样会自动添加，
self in parenthesis, we're going to come back to this shortly. 自我用括号括起来，我们将在不久后再讲到这一点。
Now, right after self, we want to add 2 extra parameters, 现在，在self之后，我们要添加2个额外的参数，
x and y, so let's type out x and y, x和y，所以我们输入x和y
and then in the body of this method, we should read the values past 然后在此方法的主体中，我们应该读取过去的值
here, and use them to initialize our object, so when we pass 在这里，并使用它们来初始化我们的对象，所以当我们通过
10 and 20, these arguments will be used for 10和20，这些参数将用于
x and y parameters. Now to initialize x和y参数。现在开始初始化
our object, we type our code like this. Self.x equals 我们的对象，我们像这样键入我们的代码。 Self.x等于
x. And then self.y equals y. X。然后self.y等于y。
What is going on here, this self that you see here is a reference to the current 这里发生了什么，您在这里看到的这个自我是对当前事物的引用
object. So, back to line 13, 目的。因此，回到第13行
when we create a new point object, self references that object in 当我们创建一个新的点对象时，自我引用该对象
memory, the same object, that we're referencing using this cariable. 内存，就是我们使用此cariable引用的相同对象。
So earlier we typed point.x equals 10, 所以我们之前输入point.x等于10，
with this code we set the x attribute of this point object. 使用此代码，我们设置了该点对象的x属性。
Now what we have in the constructor is exactly the same, we use the self 现在我们在构造函数中拥有的是完全相同的，我们使用self
to reference the current object and then we set the x attribute 引用当前对象，然后设置x属性
to the x argument passed to this function. So, 传递给此函数的x参数。所以，
using this init method, we can initialize our objects and 使用此init方法，我们可以初始化我们的对象并
we refer to this method as a constructor, this method is used to construct 我们将此方法称为构造函数，该方法用于构造
or create an object, okay? so, 或创建一个对象，好吗？所以，
Now, let's remove line 14, so we created 现在，我们删除第14行，因此我们创建了
point object with these values and then print point.x let's run our program 点具有这些值的对象，然后打印point.x让我们运行程序
there you go, x is 10, we can also change 你去，x是10，我们也可以改变
these values later, so just before printing point.x we can set 这些值稍后，因此在打印point.x之前，我们可以进行设置
point.x to 11 and then run our program 将point.x设置为11，然后运行我们的程序
so x is updated, beautiful, alright, here's a 所以x更新了，很漂亮，好吧，这是一个
exercise for you. I want you to define a new type called person 为你运动。我要你定义一个新的类型叫做person
these person objects should have a name attribute as well as a talk 这些人对象应该具有名称属性以及对话
method. This is a very easy exercise so, 方法。这是一个非常容易的练习，
you can tackle it in probably a couple of minutes. 您可能会在几分钟内解决它。
Alright, so 好啦
first we start with a class keyboard, we define this person class 首先我们从一个类键盘开始，我们定义这个人类
once again look at the naming convention I have used here, the first letter 再次看看我在这里使用的命名约定，第一个字母
of the first word in this case the only word is uppercase. 在这种情况下，第一个单词的唯一单词是大写。
Now, in this class we define all the methods we need, currently we only have 现在，在这个类中，我们定义了我们需要的所有方法，目前我们只有
method that is the talk method, so define talk, 方法是通话方法，因此定义通话，
pycharm automatically adds self, we come back to this shortly, pycharm自动添加自我，我们很快就会回到这个话题，
for now let's just print talk. 现在，让我们来谈谈。
So this is the body of our person class. We remove the indentation 这就是我们这个人类的主体。我们删除缩进
and add two line breaks after defining our 并在定义我们的代码后添加两个换行符
classes. Now we can create the personal object, let's call that jon, 类。现在我们可以创建个人对象，我们称其为乔恩，
we set it to person, we can call jon. 我们将其设置为person，我们可以调用jon。
talk, let's run the program so we get this 谈谈，让我们运行程序，以便我们得到这个
message, beautiful, but our person objects should also have 信息，很漂亮，但是我们的人对象也应该有
a name attribute, it doesn't make sense to have a person without the name. 名称属性，没有名字的人是没有意义的。
So that is when we use the constructor function. So on the top, 这就是我们使用构造函数的时候。所以在最上面
we add a new method, at the name of this method is double 我们添加了一个新方法，该方法的名称为double
underscore, init double underscore. So we 下划线，init双下划线。所以我们
call this method a constructor. Now in this method we need to 将此方法称为构造函数。现在，在这种方法中，我们需要
add another parameter which is name, so we 添加另一个名为name的参数，所以我们
simply set self.name to name. Once 只需将self.name设置为name。一次
again, self references the current object, we're setting the name 再次，self引用当前对象，我们设置名称
attribute of the current object, to the name argument passed to this method. 当前对象的属性，传递给此方法的name参数。
With this we can go back to line 9, and 有了这个，我们可以回到第9行，
when creating a person object we pass the name, let's see jon smith 在创建人员对象时，我们传递名称，让我们看看乔恩·史密斯（Jon Smith）
now let's print jon.name and run our program 现在让我们打印jon.name并运行我们的程序
there you go. So jon Smith is printed on the terminal, beautiful, 你去。乔恩·史密斯（Jon Smith）印在终端上
so this is all you had to do as part of this exercise. But 因此，这是您在本练习中要做的全部工作。但
let's make this program a little more interesting. Instead of printing 让我们使该程序更有趣。代替打印
this boring message here, let's print hi, I am Jon Smith. 这条无聊的消息，让我们打个招呼，我是乔恩·史密斯。
So, we can use a formatted string with a message 因此，我们可以在消息中使用格式化的字符串
like Hi, I am, now we want to dynamically 像嗨，我是，现在我们要动态地
add the name of this person. How do we do this? Well, look at 添加此人的名字。我们如何做到这一点？好吧，看看
the parameter of this talk method. As I told you before, 此对话方法的参数。就像我之前告诉你的
every method in our class should have this parameter, self. 我们类中的每个方法都应具有此参数self。
And they should be the very first parameter of each method, okay? So, 而且它们应该是每种方法的第一个参数，好吗？所以，
with this self we can get reference to the current object, so 通过这个自我，我们可以获得对当前对象的引用，因此
we can add curly braces and type out self 我们可以添加花括号并输入self
.name. Thsi returns the name attribute of the current 。名称。此返回当前属性的名称属性
person object. With this we can remove 人对象。有了这个，我们可以删除
line 10, where we print jon.name and simply call 第10行，我们在其中打印jon.name并简单地调用
jon.talk. Lets run our program. 乔恩·托克让我们运行我们的程序。
Hi, I am Jon Smith. There we go, beautiful. 嗨，我是乔恩·史密斯。我们去了，美丽。
Now we can build another person object, let's say Bob, is a new person 现在我们可以建立另一个人对象，比如鲍勃，是一个新人
called Bob Smith, when we say 叫鲍勃·史密斯（Bob Smith），当我们说
Bob.talk. And run our program Bob.talk。并运行我们的程序
we get a different message, hi I'm Bob Smith, so 我们收到不同的消息，嗨，我是鲍勃·史密斯，所以
each object is a different instance of a person class. 每个对象都是一个人员类的不同实例。
In this tutorial Im going to talk to you about inheritance in Python, 在本教程中，我将与您讨论Python的继承，
inheritance is a mechanism for using code and once again 继承是一种使用代码的机制，
it's no limited to python, most languages that support classes 它不仅限于python，大多数支持类的语言
also support inherence. So let ms how you how this works. Let's say 也支持内在性。因此，让我们了解您的工作方式。比方说
we have this dog class with a simple walk method, in this method 我们有一个狗类，带有一个简单的行走方法，在这种方法中
we're simply printing the walk message on the terminal, now let's say 我们只是在终端上打印步行消息，现在让我们说
in real program, instead of just one line of code here we're going to have 10 lines of 在实际程序中，我们将只用10行代码，而不是这里的一行代码
code. Now, what if in the future we want to define a 代码。现在，如果将来我们要定义一个
another class let's say cat and we want to add 另一个类，比如说猫，我们想添加
this walk method there as well. Sow e'll have to repeat all that code, 还有这种步行方法。播种将不得不重复所有这些代码，
in this new class, walk. 在这门新课上，走路。
This is bad. because you have repeated or duplicated our 这不好。因为您重复或重复了我们的
code. In programming we have a principle called dry 代码。在编程中，我们有一个叫做干的原理
which is short for don't repeat yourself. 这是简短的描述，请不要重复自己。
Let's say sometime in the future, we discover a problem with our walk method. If you 假设在将来的某个时候，我们发现步行方法存在问题。如果你
have repeated or duplicated this method in many other places, then we'll 已经在许多其他地方重复或重复了此方法，那么我们将
have to come back and fix that problem in every single place we have 必须回来并在我们拥有的每个地方修复该问题
duplicated this code. So that's why in programming we should not define something 复制了此代码。这就是为什么在编程中我们不应该定义一些东西
twice. So how can we solve this problem. 两次。那么我们如何解决这个问题。
There are different approaches, one approach that is easier to understand for beginners is inherence 有不同的方法，对于初学者来说更容易理解的一种方法是固有性
Now here's how it works. We define a new class called 现在，它是如何工作的。我们定义了一个新类，称为
maml and move the walk method right there. Then we'll have maml，然后将walk方法移到那里。那我们有
the dog and cat classes inherit that method 狗和猫类继承了该方法
from their parent just like how humans inherit certain 就像人类如何继承某些人一样
attributes or behaviors form their parents. That' exactly the same, so 属性或行为是他们的父母。完全一样，所以
on the top, we define a new class, let's call it 在顶部，我们定义一个新类，我们称之为
mammal then we need to move the walk method there. So, 哺乳动物，那么我们需要将步行方法移到那里。所以，
we select it, cut it, using command and x on Mac, or 我们选择它，在Mac上使用Command和x将其剪切，或者
control x on Windows and then paste it here, beautiful, 在Windows上控制x，然后将其粘贴到此处，很漂亮，
now we want our dog class to inherit this class from the mammal class 现在我们希望我们的狗类从哺乳动物类继承这个类
so right after the class name we add parenthesis and 所以在类名之后，我们加上括号和
then type out the name of the parent class. In this case, mammal. 然后输入父类的名称。在这种情况下，是哺乳动物。
That's all we have to do. So with his the dog class 这就是我们要做的。所以和他的狗班
will inherit all he methods defined in the mammal class. 将继承哺乳动物类别中定义的所有方法。
Now there is a tiny problem here, if you look at line 9, there is a 现在这里有一个小问题，如果您看一下第9行，
red underline here. The reason this is happening is because 红色下划线在这里。发生这种情况的原因是
python doesn't like an empty class, so right now our dog python不喜欢空类，所以现在我们的狗
class is empty, it doesn't have anything, we either need to add methods 类为空，它没有任何东西，我们要么需要添加方法
specific to dogs or just to make Python happy, 专门针对狗，或者只是为了让Python开心，
we can use the path statement, and that basically means nothing. 我们可以使用path语句，这基本上没有任何意义。
We're telling python interpreter, hey, pass this line, don't worry about it. But with this, we 我们正在告诉python解释器，嘿，通过这一行，不用担心。但是有了这个，我们
don't have an empty class, okay? Now as I told you before 没有空课，好吗？现在就像我之前告诉你的
after each class I should have two line breaks so right now we 每次上课后，我应该有两个换行符，所以现在我们
only have one line break and that is the reason we have this little warning here, so let's add 只有一个换行符，这就是我们在这里发出这个小警告的原因，所以让我们添加
another black line, beautiful, so our dog class is 另一条黑线很漂亮，所以我们的狗类是
inheriting the walk method from the mammal, you need to apply the same change 从哺乳动物继承步行方法，您需要应用相同的更改
to the cat class. So we'll have cat 去猫课。所以我们要猫
inherit from mammal, and then, 从哺乳动物那里继承下来，然后，
use the path statement here. With these changes, 在这里使用path语句。有了这些变化，
now we can create either a dog or cat object, let's say dog, 现在我们可以创建狗或猫的对象，比如说狗，
one, we set it to a dog object, and 首先，我们将其设置为狗对象，然后
when we type dot look we have the walk method that is defined 当我们输入点外观时，我们具有定义的walk方法
in the mamall class. We can easily call it, let's run our program 在mamall班上。我们可以轻松地调用它，让我们运行我们的程序
there you go, you see the walk message, 去那里，您会看到步行信息，
so both the dog and cat classes are inheriting all the classes 所以狗和猫类都继承了所有类
methods defined in their parent class. Now here we can add methods 在其父类中定义的方法。现在在这里我们可以添加方法
specific to dogs, for example, we can define a method called 例如，特定于狗，我们可以定义一个方法
bark, and then print bark. 树皮，然后打印树皮。
Now, we don't need the path statement because we already defined 现在，我们不需要path语句，因为我们已经定义了
one method in our dog class. So now when we type out 我们狗类中的一种方法。所以现在当我们输入
dog1. look we have two methods 狗1。看我们有两种方法
one is the walk method that we inherited and the bark method that we just 一个是我们继承的walk方法，而我们只是树皮方法
defined in the dog class. Similarly, we can add a method 在狗类中定义。同样，我们可以添加一个方法
specific to a cat, for example, we can define a method called 例如，特定于猫，我们可以定义一个方法
be annoying, I hate cats, so let's print 烦人，我讨厌猫，所以让我们打印
annoying , now when we create the cat 恼人的是，现在当我们创建猫的时候
object, let's remove that, cat1 对象，让我们删除它，cat1
and type out cat1. you have these two methods 并输入cat1。你有这两种方法
dog and be annoying. So these are the basics of inheritance in python 狗，烦人。所以这些是python中继承的基础
Now there is more to this that really goes beyond the scope of this beginners tutorial. 现在，还有更多的东西确实超出了本入门教程的范围。
If you're interested to learn more about inheritance and other mechanisms 如果您有兴趣了解有关继承和其他机制的更多信息
for reusing code, I encourage you to get my complete Python course. 为了重用代码，我鼓励您获得完整的Python课程。
In this tutorial, I'm going to talk to you about modules in python. 在本教程中，我将与您讨论python中的模块。
A module in python is basically a file with some python code. python中的模块基本上是带有一些python代码的文件。
And we use modules to organize our code into files. 我们使用模块将代码组织到文件中。
Just like sections in a super market. When you go to a super market there are different sections 就像超级市场中的部分一样。当您去超级市场时，会有不同的部分
for fruits, vegetables, cleaning products, and so on. We don't have 用于水果，蔬菜，清洁产品等。我们没有
one section with all the products in the super market. We have the same concept 超级市场中所有产品的一个部分。我们有相同的概念
in programming. So instead of writing all our code, instead of writing 在编程中。因此，与其编写所有代码，不如编写
all the functions and classes in app.py we want to break up our code app.py中的所有函数和类，我们想分拆我们的代码
into multiple files. We refer to each file as a module. 成多个文件。我们将每个文件称为模块。
With this, not only is our code better organized and structured, 这样，我们的代码不仅可以更好地组织和结构化，
but we'll also have the ability to reuse our code. For example, 但是我们也可以重用我们的代码。例如，
over here in app.py, I've defined two functions for converting 在app.py的这里，我定义了两个函数来进行转换
weight from pounds to kilograms and vice versa. 重量从磅到千克，反之亦然。
Now we can take these two functions and put them in a separate module 现在我们可以将这两个功能放在一个单独的模块中
called converters, and then we can import that module into any 称为转换器，然后我们可以将该模块导入任何
program that needs these converter functions. Let me show you how to do this. 需要这些转换器功能的程序。让我告诉你如何做到这一点。
So, let's open up our project panel and right 因此，让我们打开我们的项目面板，然后
click the project, go to new, and add the new file, 单击项目，转到“新建”，然后添加新文件，
we're going to call this file, converters.py. 我们将其命名为converters.py。
Then, we go back to app.py 然后，我们回到app.py
select all this code, cut it and then 选择所有这些代码，将其剪切，然后
paste it into our new module. converters.py. 将其粘贴到我们的新模块中。 converters.py。
With this we have cleaned up our app module it's not bloated with different 有了这个，我们清理了我们的应用程序模块，它不会因其他问题而肿
functions, so as we write more functions with classes, we put them in their 函数，所以当我们用类编写更多函数时，我们将它们放在它们的
corresponding modules, a module should contain all the related 对应的模块，一个模块应包含所有相关的
functions and classes, okay? Now you want to 函数和类，好吗？现在你想
import the converters module into our app module, and that is really easy, on the 将converters模块导入到我们的app模块中，这很简单，在
top we write import converters 顶部我们编写导入转换器
without extension, so we don't add .py we only type out the name of 没有扩展名，因此我们不添加.py，我们只键入
the file. Let me close that project panel. Now, 文件。让我关闭该项目面板。现在，
this converter is an object so we can use the dot operator 这个转换器是一个对象，所以我们可以使用点运算符
to access it's members. So currently we have defined 访问它的成员。所以目前我们已经定义
these two functions inside of our module, kilogram to pound, 这两个功能在我们模块的内部，从千克到磅，
and pounds to kilograms. So we can easily call one of these functions 和磅到千克。因此我们可以轻松地调用以下功能之一
let's pass 70 kilos get the result and print it out. 让我们传递70公斤来得到结果并打印出来。
Run our program, so, 运行我们的程序，所以，
that is under 55 pounds. Now there is also another 不到55磅。现在还有另一个
syntax for importing modules, let me show you, so 导入模块的语法，让我告诉你，所以
instead of importing the entire module we can import specific functions from that 而不是导入整个模块，我们可以从中导入特定的功能
module. Here's how it works. We type out from 模块。这是它的工作方式。我们从
then we add the name of our module, so converters 然后我们添加模块的名称，因此转换器
import, now here if you press control and space 导入，如果您按Control和空格键，现在在这里
we can see the list of all the functions defined in this module. 我们可以看到此模块中定义的所有功能的列表。
So here we can grab one of these functions let's say kilogram to pound, and 因此，在这里我们可以抓取其中一个功能，比如说千克到磅，
with this we can directly call this function just like 这样我们就可以像直接调用该函数一样
the function defined in this file. App.py. Compare 该文件中定义的功能。 App.py。比较
what we have on line 4 to what we have on line 6. On line 6 我们在第4行到第6行所拥有的东西。在第6行
we'll have to prefix this function with the name of an object 我们必须在此函数的前面加上对象的名称
converters. So we have to type converters. and then we'll be able to 转换器。因此，我们必须键入转换器。然后我们就可以
access this function. In contrast. When we import 访问此功能。相比之下。当我们导入
a specific function from our module, then we can easily call that function 某个模块中的特定功能，那么我们可以轻松地调用该功能
without prefixing it with the module name. So here's what 而不用模块名作为前缀。所以这是什么
you need to take away. We use modules to better organize our code. Instead of 你需要带走。我们使用模块来更好地组织代码。代替
writing all the code, instead of writing all the functions in one file, you break up 编写所有代码，而不是将所有功能写在一个文件中，而是分手了
our code across multiple files. Each file is called 我们的跨多个文件的代码。每个文件被称为
a module and it should contain all the related functions and classes 一个模块，它应该包含所有相关的函数和类
then we can import a module into another module, in this case, we are importing 然后我们可以将一个模块导入另一个模块，在这种情况下，我们正在导入
the converters module into our app module. And as you saw, 将转化器模块整合到我们的应用模块中。如你所见
there are two ways to import this module, we can import the entire module, and then 有两种导入该模块的方法，我们可以导入整个模块，然后
we'll get an object with the same name as the module so we can 我们将获得与模块同名的对象，因此我们可以
type converters . and then we'll be able to access all the 类型转换器。然后我们就可以访问所有
functions and classes defined in this module. The other appraoch 本模块中定义的函数和类。另一个方法
is to impot a specific function or class from a module using the 是使用
from import statement. Now here 从导入语句。现在在这里
is your exercise. Earlier in the course you had an exercise for finding the 是你的运动。在课程的早期，您练习了如何找到
largest number in the list. So here on the top we have 列表中最大的数字。所以在最上面
a list of numbers, initially we set max to the first number in this list 数字列表，最初我们将max设置为该列表中的第一个数字
then, we look through this list, get each number, 然后，我们浏览此列表，获取每个数字，
if the current number is grater than max, then we reset max. 如果当前数字大于最大值，则重置最大值。
And finally when we are done with our loop we print max on the terminal. 最后，当我们完成循环时，我们将在终端上打印max。
Now here's what I want you to do. This code currently 现在，这就是我想要您做的。该代码目前
has no organization. We don't have any functions, we don't have any modules, we wrote all 没有组织。我们没有任何功能，我们没有任何模块，我们编写了所有
the code in app.py, that is okay for small programs, app.py中的代码，对于小型程序来说还可以，
but as your programs grow, you need to properly organize your code into 但是随着程序的增长，您需要正确地将代码组织到
classes and modules. So, as part of this exercise, I want 类和模块。因此，作为本练习的一部分，我想
you to write a function, call it find max. 您编写一个函数，调用它来查找最大值。
This function should take a list, and return the largest number in that list. 此函数应获取一个列表，并返回该列表中最大的数字。
Now after you do this, go ahead and put this function 现在，执行此操作后，继续执行此功能
in a separate module. So extract it from here, and put it in a module, 在一个单独的模块中。因此，从这里提取它，并将其放入模块中，
called utils. So in this module we're going to have a bunch of 称为utils。因此，在本模块中，我们将有一堆
utility functions, oaky? Then import the utility 实用功能，橡木色？然后导入实用程序
module into the current module and call this function. 模块插入当前模块并调用此函数。
Finally, get the result and print it on the terminal, this is a 最后，获取结果并将其打印在终端上，这是一个
fantastic exercise to teach you how to properly organize your code. So, 出色的练习，教您如何正确组织代码。所以，
go ahead and spend a couple minutes on this exercise. 继续并花几分钟进行此练习。
So the first 所以第一个
step is to define a function called find max. So on the 步骤是定义一个名为find max的函数。所以在
top, I'm going to define function, find max 顶部，我要定义函数，找到最大值
this function should take a list of numbers, so we 这个函数应该有一个数字列表，所以我们
add a parameter called numbers. Now inside of this function you 添加一个称为数字的参数。现在在此功能内
want to have these few lines, this is the algorithm for finding the 想要有这几行，这是寻找
largest number in a list, we don't want to bring the first line, because this 列表中最大的数字，我们不想带第一行，因为这
is where we create a list. So somewhere in our program we're going to create this list, 是我们创建列表的地方。因此，在程序的某个位置，我们将创建此列表，
and tehen pass it as an argument to pass max 并把它作为参数传递给max
function. Okay? So, let's go ahead and grab 功能。好的？所以，让我们继续前进
these few lines, cut them, and put them inside 这几行，剪下来，放进去
of find max function. Alright, so we find the 查找最大功能。好了，所以我们找到了
largest number in this list, finally we need to return it, so, 该列表中最大的数字，最后我们需要将其返回，因此，
return max. So here's our function. Now we 返回最大值这就是我们的功能。现在我们
need to move this into a separate module. So let's go to the panel 需要将此移到一个单独的模块中。所以我们去面板
right click the project and add a new 右键单击该项目并添加一个新的
file, we can also add a new python file that's the same, let's call that 文件，我们还可以添加一个相同的新python文件，我们称其为
utils so if you add a new python file utils，因此，如果您添加新的python文件
pycharm automatically adds .py extension, but if you go to pycharm自动添加.py扩展名，但是如果您转到
new file we'll have to explicitly type out 新文件，我们将必须明确输入
.py. So make sure to get the extension right. .py。因此，请确保正确使用扩展名。
Now, back to app.py, let's cut this code and 现在，回到app.py，让我们削减这段代码，
paste it into this new module, okay beautiful. 粘贴到这个新模块中，好漂亮。
Now I'm going o go back to app.py and import our new module. 现在，我要返回到app.py并导入我们的新模块。
We can either import the entire module, so import utils 我们可以导入整个模块，所以导入utils
and then access individual functions so we can call utils 然后访问各个函数，以便我们可以调用utils
.find max or we can explicitly .find max或我们可以显式
import this function from the utils module. It doesn't really make a difference. 从utils模块导入此函数。它并没有真正的改变。
So, we could type from utils 因此，我们可以从utils中键入
import find max. And then we 导入查找最大值然后我们
don't need to prefix this with the name of it's object, so we simply call 不需要为此添加前缀对象的名称，因此我们只需调用
find max. Now we need to call this after we initialize our list. 找到最大现在，我们需要在初始化列表后调用此函数。
So first we need to define the list of numbers. 因此，首先我们需要定义数字列表。
Then, we pass that list as an argument to find max 然后，我们将该列表作为参数传递给max
we get the result which is max and finally we print it 我们得到最大的结果，最后我们打印出来
on the terminal. let's go ahead and run our program, so the 在终端上。让我们继续运行我们的程序，所以
largest number is 10, beautiful, 最大的数字是10，很漂亮，
now one last thing before we finish this tutorial, here we have this little warning 现在，在完成本教程之前的最后一件事，在这里，我们有一点警告
under max and the tool tip says shadows built in name 在max下，工具提示显示阴影内置名称
max. The reason we see this is because we actually have a function called 最大限度。之所以看到这是因为我们实际上有一个名为
max. And it does the exact same job 最大限度。它做完全一样的工作
as our find max function. So this is actually built into python. 作为我们的发现最大功能。因此，这实际上是内置在python中的。
But I ask you to do it as an exercise because it's a great exercise for beginners. 但我请您将其作为练习，因为对于初学者来说，这是一个很好的练习。
Now, back to the warning, this warning is basically telling us that we are 现在，回到警告，该警告基本上告诉我们
overwriting the built in max function in python 覆盖python中内置的max函数
so we are changing the meaning of this function, and this is considered a bad practice, 因此我们正在更改此函数的含义，这被认为是不正确的做法，
let me show you what I mean. So let's comment out what we have on line 4, 让我告诉你我的意思。因此，让我们注释一下第4行的内容
by putting a hash sign here, we can also use, 通过在此处加一个井号，我们还可以使用
a short cut command and slash on Mac, or control on slash 在Mac上的快捷命令和斜杠，或在斜杠上进行控制
on Windows. So now this line is commented out. Look at the 在Windows上。因此，现在此行已被注释掉。看着那（这
color of max here, it's purple, it's the same color as print. And this is the color max的颜色，它是紫色，与打印的颜色相同。这就是颜色
used to identify the built in functions. So now we can call 用于识别内置功能。所以现在我们可以打电话
this function and give it a list of numbers 这个功能，并给它一个数字列表
run our program we get the same exact result however, 运行我们的程序，我们得到的结果完全相同，
if we bring this line back, once again we can use the same 如果我们把这条线带回来，我们可以再次使用相同的
shortcut that is command and slash on Mac or control slash on Windows. 在Mac上是命令和斜线的快捷方式，在Windows上是控制斜线的快捷方式。
Now, we are redefining max, so up to 现在，我们正在重新定义max
this line, max used to be a function, but after line 4 is executed 该行，max曾经是一个函数，但是在执行第4行之后
max is set to an integer, that is the largest number in this list. max设置为整数，即此列表中的最大数字。
So, we'll no longer be able to call it on line 5, 因此，我们将无法在第5行上调用它
let's run our program and see what happens. So there you go, 让我们运行我们的程序，看看会发生什么。所以你去了，
we get this type error, int object is not 我们得到这个类型错误，int对象不是
callable, because max is now an integer, it's not a function, 可以调用，因为max现在是整数，所以它不是函数，
so we cannot call it. So to solve this problem, we can rename 所以我们不能称之为。所以要解决这个问题，我们可以重命名
this variable to something else. So right click here. 这个变量给别的东西。因此，右键单击此处。
Go to refactor and rename, 去重构并重命名，
and rename this to maximum. 并将其重命名为最大。
So you can see the warning is gone. As you can see we have the same warning 这样您就可以看到警告已消失。如您所见，我们有相同的警告
in our utils module. So here we're redefining max 在我们的utils模块中。所以我们在这里重新定义max
and as I told you before this is a bad practice. We're changing the 就像我之前告诉你的那样，这是一种不好的做法。我们正在改变
meaning of built in functions in python. So, python中内置函数的含义。所以，
let's rename these as well, I'm going to use the short cut that is shift and 我们也将其重命名，我将使用shift和
f6 there you go and here we can change this to f6到那里，在这里我们可以将其更改为
maximum. Enter, done. 最大。输入，完成。
In this tutorial we're going to talk about packages in python, 在本教程中，我们将讨论python中的软件包，
packages are basically another way to organize our code, so currently 软件包基本上是组织代码的另一种方式，因此目前
we have only 3 files for modules in our project but a real project 我们的项目中只有3个模块文件，但实际的项目
can contain hundreds or even thousands of modules. 可以包含数百甚至数千个模块。
We don't want to add all those modules here, because over time this directory will get 我们不想在这里添加所有这些模块，因为随着时间的流逝，此目录将
bloated with so many files, so a better approach is to organize related files肿的文件太多了，所以更好的方法是整理相关文件
modules, inside of a package, so a package is a container 模块，位于包装内部，因此包装就是容器
for multiple modules In file system terms a package is 用于多个模块用文件系统术语来说，一个软件包是
a directory or folder. So in our project we can add a new directory 目录或文件夹。因此，在我们的项目中，我们可以添加一个新目录
and in that directory we can add all the directed modules, as a metaphor think 隐喻认为，在该目录中，我们可以添加所有定向模块
of a mall. When you go to a mall or a shopping center there are different 购物中心当您去购物中心或购物中心时，会有所不同
sections for mens women and kids clothing, so that is 男士女士和儿童服装的部分，因此
ilke a package, now when you go to the mens section, there are different areas 一包，现在当您去男士专区时，有不同的区域
fior different kinds of products, we have a section for shoes, t shirts, 提供不同种类的产品，我们有专门的鞋，T恤，
jackets, and so on, so each of these is like a module, so, 夹克等等，所以它们每个都像一个模块，所以，
in this tutorial, I'm going to show you how to create and use packages in Python, 在本教程中，我将向您展示如何在Python中创建和使用包，
here in our project panel, right click the panel and 在我们的项目面板中，右键单击面板，然后
add a new directory. 添加一个新目录。
Let's call this directory e commerce. So we're going to create 我们将此目录称为电子商务。所以我们要创建
a package called e-commerce and in this package we're going to have 一个名为“电子商务”的程序包，在这个程序包中，我们将拥有
all the modules related for an ecommerce application. For example, 与电子商务应用程序相关的所有模块。例如，
we can have modules for sales, shipping, customer service 我们可以有用于销售，运输，客户服务的模块
and so on. So let's go ahead 等等。所以我们继续吧
Now here we have an empty directory, in order to convert this to a package 现在这里有一个空目录，以便将其转换为包
we need to add a special file in it. So, right 我们需要在其中添加一个特殊文件。所以吧
click this directory and add a new python file, 点击此目录并添加一个新的python文件，
call that file double underscore in it, double underscore 将该文件称为双下划线，双下划线
this is a special convention in Python. 这是Python中的特殊约定。
When Python interpreter sees a file with this name and 当Python解释器看到具有该名称的文件时，
name in a directory, it treats this directory as a package, we also have a 目录中的名称，它将此目录视为一个包，我们也有一个
shortcut for that in pycharm so let me delete this directory pycharm中的快捷方式，让我删除此目录
and start again. So delete, once again right click 然后重新开始。所以删除，再次右键单击
the project, and go to new but instead of creating a new directory 项目，然后转到new，而不是创建一个新目录
we can create a new python package, let's call 我们可以创建一个新的python包，让我们称之为
our package ecommerce as you can see 如您所见，我们的包裹电子商务
pycharm automatically creates this file for us so we don't have to manually create pycharm会自动为我们创建此文件，因此我们无需手动创建
it. Okay? Now, in this package, let's add a new module, 它。好的？现在，在这个包中，让我们添加一个新模块，
so a new python file, let's call it 所以一个新的python文件，我们称它为
shipping okay? Now in this module we want to have 运送还好吗？现在在这个模块中我们想要
a function for calculating the shipping costs. So define 用于计算运输成本的功能。所以定义
calculate, underline, shipping. 计算，强调，运输。
Now don't worry about parameters or implementation, we simply print 现在不用担心参数或实现，我们只需打印
calculate underline shipping. 计算下划线的运费。
Now lets say you want to import this shipping module 现在假设您要导入此运输模块
into our app module, with this new structure this shipping 进入我们的应用程序模块，并采用这种新结构
module is now part of the ecommerce package, so we cannot import a direct 现在，该模块已成为电子商务软件包的一部分，因此我们无法直接导入
you have to start from the ecommerce package. So, 您必须从电子商务软件包开始。所以，
bak to app,py once again there are two ways to import this module. 再次对app，py再次有两种导入此模块的方法。
We can import the entire module or we can 我们可以导入整个模块，也可以
import one of it's functions or classes. So let me show you both approaches. 导入它的功能或类之一。因此，让我向您展示两种方法。
First, we're going to import the entire module. Now what is the name of our 首先，我们将导入整个模块。现在我们的名字是
package? it is ecommerce, right? So ecommerce. 包裹？是电子商务，对不对？电子商务。
shipping. So instead of typing import 运输。所以不要输入import
shipping we type import ecommerce 我们输入进口电子商务的运输
.shipping. we have to prefix it with the name of it's package. 。运输。我们必须给它加上包名称的前缀。
Now to access any of the functions or classes in this module 现在访问该模块中的任何函数或类
we'll have to type out ecommerce.shipping. 我们将不得不输入ecommerce.shipping。
and there you go. Now we can access the calculate shipping 然后你去。现在我们可以访问计算运费
function. So let's go ahead and run our program, 功能。因此，让我们继续运行我们的程序，
we see this message printed on the terminal, beautiful. However 我们看到此消息印在终端上，很漂亮。然而
with this approach, every time you want to call one of the functions 使用这种方法，每次您要调用其中一个功能时
to this module, we'll have to prefix it with ecommerce. 在此模块中，我们必须在其前面加上电子商务。
shipping. that is very verbose. So when working with packages 运输。这很冗长。因此，在使用软件包时
we often use the second approach, using the 我们经常使用第二种方法
from statement. So we can type from ecommerce 从声明。这样我们就可以从电子商务中输入
.shipping import .shipping导入
calculate shipping. Now we don't have to prefix this function 计算运费。现在我们不必为此功能添加前缀
with ecommerce.shipping, and we can call it multiple times 通过ecommerce.shipping，我们可以多次调用它
in this module, so our code is a little bit shorter. But what if 在此模块中，因此我们的代码要短一些。但是如果
you want to use multiple functions in this shipping module. We can either import them here, 您想在此运输模块中使用多种功能。我们可以在这里导入它们，
so calculate shipping, comma, let's say calculate_ 因此，请计算运费，以逗号表示，例如，compute_
tax. Or we can import the entire module and then 税。或者我们可以导入整个模块，然后
access all he functions or classes in that module. So, 访问该模块中的所有他的函数或类。所以，
let me revert this back. To import the entire module 让我将其还原。导入整个模块
we type from ecommerce so we remove.shipping 我们从电子商务中键入内容，因此我们将其删除。
so from this package, import 所以从这个包中导入
the shipping module. Now the shipping module, 运输模块。现在运输模块，
is an object so we can access 是一个对象，所以我们可以访问
all the functions and classes defined here, using the dot operator, so 这里使用点运算符定义的所有函数和类，因此
shipping. there you go, calculate shipping. So to 运输。到那儿，计算运费。所以
recap, when using the from statement we can either start from 回顾一下，当使用from语句时，我们可以从
the package and import a specific module, or we can 打包并导入特定模块，或者我们可以
start from package.module 从package.module开始
and then import a specific function. Like calculate shipping. 然后导入特定功能。像计算运费。
So, this was the basics of using packages in 因此，这是在
python. As I told you before, packages are extremely important, especially Python。正如我之前告诉您的那样，软件包非常重要，尤其是
when you want to work with a framework like django, we use django for building 当您想使用django之类的框架时，我们使用django进行构建
web applications with python, and I'm going to show you that later in this course. Web应用程序和python，我将在本课程的后面向您展示。
So in Django we have quite a few packages and 因此，在Django中，我们有很多软件包和
each package contains several modules. So make sure to watch the tutorials, 每个程序包包含几个模块。因此，请务必观看教程，
about modules and packages one more time, otherwise you're going to get confused later 再一次讨论模块和软件包，否则稍后您会感到困惑
when we get to Django. 当我们到达Django时。
In this tutorial I'm going to talk to you 在本教程中，我将与您交谈
guys about the built in modules in python, so python 关于python中的内置模块的人，所以python
comes with a standard library that contains several modules for common 带有一个标准库，其中包含几个通用模块
tasks such as sending emails, working with date and time, 诸如发送电子邮件，处理日期和时间，
generating random values and passwords and so on. There are so many modules 生成随机值和密码等。模块太多了
already built into Python and that means there is already lots of functionality 已经内置在Python中，这意味着已经有很多功能
that we can reuse. Let me show you where you can find 我们可以重用。让我告诉你在哪里可以找到
this standard library. So open up this browser 这个标准库。所以打开这个浏览器
and search for python 3, module index, 并搜索python 3，模块索引，
make sure to add the version number, because the modules in python 2 are 确保添加版本号，因为python 2中的模块是
different from modules in python3. So here we search for python 3 与python3中的模块不同。所以在这里我们搜索python 3
module index, and the first page here, you can see is 模块索引，这里的第一页是
python module index, or python 3, let's go ahead, python module index或python 3，让我们继续吧，
so these are all the modules built into python, 这些都是python内置的所有模块，
for example we have modules for working with date and time, 例如，我们有用于处理日期和时间的模块，
we have modules for sending emails for encoding values, 我们有用于发送电子邮件以编码值的模块，
there are so many modules here. Now the explanation of all these is 这里有很多模块。现在所有这些的解释是
beyond the scope of this course, that really requires it's own course. 超出了本课程的范围，这确实需要它自己的课程。
Because we have so many modules here, but don't let this list intimidate you. 因为我们这里有很多模块，但是不要让此列表吓到您。
This is not something that you need to learn right now, as you learn python 当您学习python时，这不是您现在需要学习的东西
as you build more applications, gradually you will get familiar with more modules 随着您构建更多应用程序，逐渐您将熟悉更多模块
here, in fact nobody knows all the modules in python 在这里，实际上没有人知道python中的所有模块
standard library. Everybody knows some modules based on the applications they have built. 标准库。每个人都基于他们构建的应用程序了解一些模块。
So in this tutorial, I'm going to show you how to use one of the built in modules, 因此，在本教程中，我将向您展示如何使用内置模块之一，
for generating random values. So on the top, 用于生成随机值。所以在最上面
we import the random module, now because 我们导入随机模块，因为
random is a built in module, we don't need to have a file here random是一个内置模块，我们不需要在这里有文件
called random.py. So python interpreter knows that random is a built 称为random.py。所以python解释器知道random是一个内置的
in module as long as it knows where to find it. 在模块中，只要它知道在哪里可以找到它。
Now if you're curious where this random module is stored on the disk, let me show you, so 现在，如果您想知道此随机模块在磁盘上的存储位置，请让我向您展示，
here in the project panel, expand external 在项目面板中，展开外部
libraries, then expand python 3, 库，然后展开python 3，
and then one more time python 3.7 library 然后再来一次python 3.7库
route. So this is a folder somewhere on your computer, in this folder, we have 路线。这是您计算机上某个位置的文件夹，在此文件夹中，
all the built in modules in python. So, python中的所有内置模块。所以，
if you scroll down, you should be able to find. 如果向下滚动，则应该可以找到。
The random module. There you go. It's right here. So random. 随机模块。妳去就在这里好随便喔。
py. You can open this and this shows you the source py。您可以打开它，这将向您显示源
code of this module. there you go. Now in this tutorial, 该模块的代码。你去。现在在本教程中，
we don't want to worry about hat, so let's go back to our app.py, 我们不想担心帽子，所以让我们回到我们的app.py，
and use this module to generate random values. So when we import 并使用此模块生成随机值。所以当我们导入
this module, now we have this object, random, so we can use the dot 这个模块，现在我们有了这个对象，是随机的，所以我们可以使用点
operator to acces it's methods. One method that is useful 操作员访问它的方法。一种有用的方法
here is the random method, and every time we call it it generates 这是随机方法，每次调用它都会生成
a random value between 0 and 1. So here we can do a for loop, 一个介于0和1之间的随机值。因此，在这里我们可以进行for循环，
let's say for I in, 比方说我
range 3. So just to refresh your memory we are using the 范围3。因此，为了刷新您的记忆，我们正在使用
range function to create a range object. We can look through this range object range函数创建一个范围对象。我们可以看一下这个范围对象
and in each iteration this object will spit out a value. 并且在每次迭代中，此对象都会吐出一个值。
So with this for loop, we can execute this code 3 times. Now, let's 因此，使用此for循环，我们可以执行此代码3次。现在，让我们
indent this. Okay, and finally, let's print the result, 缩进这个。好吧，最后，让我们打印结果，
There you go. So we can see 妳去所以我们可以看到
that in each iteration we get a new random value between 0 and 1. 在每次迭代中，我们都会得到一个介于0和1之间的新随机值。
Now what if we want a random value for a particular age? 现在，如果我们想要一个特定年龄的随机值怎么办？
Let's say random values between 10 and 20, well, 假设介于10到20之间的随机值
there is another method here, rand int, we use 2 arguments here 这里还有另一种方法rand int，我们在这里使用2个参数
to specify our range, let's say 10 and 20. 要指定我们的范围，比如说10和20。
Run our program one more time. Now we have the numbers 20 再运行一次我们的程序。现在我们有数字20
13 and 18. If we run our program one more time, 13和18。如果我们再运行一次程序，
We get different values, so 20, 19, 11, one more time. 我们得到了不同的值，所以再增加20、19、11。
Look, you also have another powerful method for 看，您还有另一种强大的方法
randomly picking an item from a list. Let's say we have a list of team members and you want to 从列表中随机选择一个项目。假设我们有一个团队成员列表，而您想
randomly pick someone as the leader. Let me show you how to do that. 随机选择某人作为领导者。让我告诉你如何做到这一点。
So, we define the list of team members, we set it to 因此，我们定义了团队成员列表，将其设置为
jon, mary, bob, 乔恩，玛丽，鲍勃，
and mosh. Now we can call random 和mo。现在我们可以叫随机
.choice and pass our members list .choice并通过我们的会员列表
this method randomly picks a method from this list and returns it. SO, 此方法从此列表中随机选择一个方法并将其返回。所以，
we can store the result in leader and then 我们可以将结果存储在Leader中，然后
print it on the terminal. let's run our program, 在终端上打印它。让我们运行我们的程序，
so now the leader is mary, if you run our program one more time 所以现在领导者是玛丽，如果您再运行一次我们的程序
this line is mosh now it's mosh again one more time, 这条线是现在，现在又是一次，
it really likes mosh, you get the point. So 它真的很喜欢吃甜食，你明白了。所以
the random module is very powerful, and it has a lot of applications. random模块功能非常强大，并且有很多应用程序。
Now here's a very cool exercise. I want you to write this program to 现在，这是一个非常酷的练习。我要你写这个程序到
roll a dice. So every time we run this program we get a different value. 掷骰子。因此，每次运行此程序时，我们都会获得不同的值。
Now we have 3 in 1, next time we get 3 and 6, one more time 现在我们有3合1，下次我们有3和6，还有一次
5 and 6, 4 and 3, double one, that's a very cool exercise. 5和6、4和3，重复一遍，这是一个非常酷的练习。
So before we get started, I want you to pay attention to a few things. 因此，在我们开始之前，我希望您注意一些事项。
I want you to define a class called dice 我要你定义一个叫做骰子的类
in this class we're going to have a method called rope so every time we 在这一节课中，我们将有一个称为rope的方法，因此每次
call this method, we get a tuple, a tuple remember is a list of 调用此方法，我们得到一个元组，一个元组记住的是一个列表
values but values cannot be changed, you cannot add a new item to it, we 值，但值不能更改，您不能向其中添加新项目，我们
cannot remove it. So it's like a read only list. So every time, 无法将其删除。因此，这就像一个只读列表。所以每次
we call the row method, we should get the tuple of two random values. 我们调用row方法，我们应该获得两个随机值的元组。
So go ahead, and do this exercise, You'll see my solution next. 因此，继续进行此练习，您将在接下来看到我的解决方案。
Alright, we start by importing the random module on the top, 好吧，我们首先从顶部导入random模块，
then we define a class called dice: 然后我们定义一个名为dice的类：
this class we want to have a method called row. So define row 这个类我们要有一个叫做row的方法。所以定义行
parenthesis, this automatically adds self, now in this method, 括号，这会自动添加自我，现在使用此方法，
you want to generate two random values between 1 to 6. 您想要生成1到6之间的两个随机值。
So we call random.randint. 因此，我们将其称为random.randint。
And pass 1 and 6. So this generates the first number, 并传递1和6。这样就生成了第一个数字，
we can ut that here, now let's call this one more time, 我们可以在这里说，现在让我们再打电话一次，
so I'm going to copy what we have on line 5, put it here, and 所以我要复制第5行的内容，放到这里，然后
change this variable to second. So we have two variables first and second. 将此变量更改为秒。因此，我们有两个变量第一和第二。
With two random values, finally we need to return them, 有了两个随机值，最后我们需要返回它们，
in a tuple, so return parenthesis instead of square brackets, 在元组中，因此返回括号而不是方括号，
first and second, now 第一和第二，现在
in python when you want to return a python from a function, you don't have to add 在python中，当您想从函数返回python时，不必添加
this parenthesis, so you can simplify your code and python will automatically 这个括号，因此您可以简化代码，而python会自动
interpret this as a tuple. So we are done 将其解释为元组。这样我们就完成了
with a definition of our class, we remove the indentation and add 用我们的类的定义，我们删除缩进并添加
two line breaks. Now we create an object of this type 两个换行符。现在我们创建这种类型的对象
so you set dice to dice 所以你把骰子设置成骰子
next we roll the dice, so dice.roll and 接下来我们掷骰子，所以dice.roll和
print the result on the terminal, that's all you have to do. 在终端上打印结果，这就是您要做的全部。
Let's run this program, so now we get 2 and 5, 让我们运行该程序，现在我们得到2和5，
lets run it one more time, 3 and 2, 1 and 1, beautiful. 让我们再运行一次，3和2，1和1，漂亮。
Now we have this little warning here, that says 现在我们这里有个小警告，说
expected 2 black lines found 1. Once again this is 预期找到2条黑线1.再次是
coming from pep 8, pep is short for python and 来自pep 8，pep是python的缩写，
proposal. We have so many python enhancement proposals or peps. 提议。我们有这么多的python增强建议或peps。
Pep 8 is a very famous 1, and in this document we have Pep 8是非常有名的1，在本文档中，我们有
all the best practices for formatting our code. So pep 格式化代码的所有最佳做法。如此鼓舞人心
8 says, that after we define our classes we should have 2 lines breaks, we've already done that 8说，在定义了类之后，我们应该有两个换行符，我们已经完成了
so the reason this is complaining is because we had 1 line break before 所以这是抱怨的原因是因为我们之前有1个换行符
the class, so let's add one more line break, now pycharm 该类，所以让我们再添加一个换行符，现在是pycharm
is happy. So basically pycharm is following all the best 很高兴所以基本上pycharm一直在追随一切
practices defined in pep8. Now you don't have to memorize pep8中定义的做法。现在您不必记住
any of these best practices, as you code in pycharm, pycharm gives you a little more 这些最佳实践中的任何一种，当您在pycharm中进行编码时，pycharm都会为您提供更多
warning, and gradually you will learn how to properly format your code, so it's 警告，然后您将逐渐了解如何正确设置代码格式，因此
readable by other people. 被其他人阅读。
In this tutorial, I'm going to show you 在本教程中，我将向您展示
how to work with directories in python. So here in python3, 如何在python中使用目录。所以在python3中，
module index, you can see we have a module called path lib which provides an object 模块索引，您可以看到我们有一个名为path lib的模块，该模块提供了一个对象
oriented file system pact. That basically means it provides 面向文件系统协议。这基本上意味着它提供了
classes that we can use to create objects to work with directories and 我们可以用来创建与目录和目录一起使用的对象的类
files. So, if you click here, you can see how this module 文件。因此，如果您单击此处，您将看到该模块的工作方式
works, we can see all kinds of examples. For example, here on there basic 的作品，我们可以看到各种各样的例子。例如，在这里基本
useage, you can see this is how we import the path 使用情况，您可以看到这是我们导入路径的方式
class from the path lib module. Let me zooming so you can see path lib模块中的class。让我放大，以便您可以看到
clearly. Okay, so look, from path lib, that's 清楚地。好的，所以从路径库看，这就是
our module, import path, note the naming convention. 我们的模块，导入路径，请注意命名约定。
P is capitalized, that means path is a class, so we need to create P是大写的，这意味着path是一个类，因此我们需要创建
an instance of this class as you can see, right here, 您可以在此处看到该类的实例，
now there's so much documentation here, you can read this on your own, but let me quickly show you 现在这里有很多文档，您可以自己阅读，但让我快速向您展示
a few examples to help you get started. So after pycharm 一些示例，可以帮助您入门。所以在pycharm之后
on the top, from the path led module, that's 在最上方，是路径引导模块
import the path class. Now we need to create, 导入路径类。现在我们需要创建
a path object to reference a file or directory 引用文件或目录的路径对象
on our computer. So there are basically to ways to do this we can use an absolute 在我们的计算机上。因此，基本上有一些方法可以使用绝对值
path, or a relative path which basically 路径，或者基本上是相对路径
means a path starting from the current directory. For example, 表示从当前目录开始的路径。例如，
if you wanna reference this ecommerce directory in our project, we can 如果您想在我们的项目中引用此电子商务目录，我们可以
use the relative path. So we start from the current directory and then 使用相对路径。因此，我们从当前目录开始，然后
go somewhere else. With absolute paths we start from the root 去别的地方。使用绝对路径，我们从根开始
of our hard disk. For example, if you're on Windows you might have 我们的硬盘。例如，如果您使用的是Windows，则可能有
an absolute path like this, c drive, backslash, 这样的绝对路径，C驱动器，反斜杠，
program, files, backslash microsoft, 程序，文件，反斜杠Microsoft，
so these are directories in c drive. 因此，这些是c驱动器中的目录。
On Windows we use a backslash to build a path. If you're on 在Windows上，我们使用反斜杠来构建路径。如果你在
Mac or Linux, your paths will look a little bit different, so 在Mac或Linux上，您的路径看起来会有所不同，因此
instead of backslash we have a forward slash lets say user/local 而不是反斜杠，我们有一个正斜杠，可以说用户/本地
/bin. So these are examples of absolute paths. In / bin。因此，这些是绝对路径的示例。在
this tutorial we're going to work with he relative path to work with this ecommerce 在本教程中，我们将与他合作使用此电子商务的相对路径
directory that we have in our project. Now if you didn't create this directory 我们项目中的目录。现在，如果您没有创建此目录
earlier, simply right click on the project and then go to new 之前，只需右键单击该项目，然后转到新
directory. oaky? So, let's close this panel, 目录。橡树？因此，让我们关闭此面板，
we create a path object, now, 我们现在创建一个路径对象，
if you don't pas an argument here, this will reference the current directory 如果您在此处不输入参数，它将引用当前目录
alternatively, we can pass string, in this string we can 或者，我们可以传递字符串，在该字符串中，我们可以
add a file or a directory. let's say the ecommerce 添加文件或目录。假设电子商务
directory. Now this runs a path object, so we store it here, 目录。现在，它运行一个路径对象，因此我们将其存储在此处，
now this path object has a few interesting methods 现在这个路径对象有一些有趣的方法
for example, we can check to see if a path exists by calling 例如，我们可以通过调用以下命令来检查路径是否存在
the exist method. This simply returns a boolean so let's print it on the terminal, 存在方法。这只是返回一个布尔值，所以让我们在终端上打印它，
there you go. So this path exists, 你去。所以这条路存在，
what if it changes to ecommerce 1, and 如果更改为电子商务1，该怎么办？
run our program and get false, we can also create a new directory 运行我们的程序并得到false，我们也可以创建一个新目录
for example, let's change our path to email, now when we 例如，让我们现在更改为电子邮件的路径
run this program, obviously we don't have this directory but we can 运行该程序，显然我们没有此目录，但是我们可以
create it by calling the mk dir method 通过调用mk dir方法创建它
so make directory. Let's run our program 所以做目录。让我们运行程序
alright, this method returns none which basically means 好了，这个方法不返回任何东西，这基本上意味着
it doesn't return any values. Now if you look at the project panel you can see 它不返回任何值。现在，如果您查看项目面板，您将看到
here we have a new directory called emails, we can also delete this directory 在这里，我们有一个名为emails的新目录，我们也可以删除此目录
so, instead of mk dir we call 因此，我们称其为mk dir而不是
rmdir which is short for remove directory, but rmdir是删除目录的缩写，但是
let's go ahead, now we can see that directory is gone. We can also see 让我们继续，现在我们可以看到该目录已消失。我们也可以看到
all the files and directories in a given path, that is, very useful if you want to 给定路径中的所有文件和目录，如果您要
write a little program to automate something. For example, 编写一个小程序来自动化一些东西。例如，
you can iterate over all the spreadsheets in a directory one them and 您可以在一个目录中遍历所有电子表格，然后
process them. Let me show you. First we change the path 处理它们。让我演示给你看。首先，我们改变道路
to the current directory and then we call the glob 到当前目录，然后我们将其称为glob
method. With his method we cans each for files and 方法。使用他的方法，我们可以将每个罐头用于文件和
directories in the current path. So as the first argument we need to pass a string 当前路径中的目录。因此，作为第一个参数，我们需要传递一个字符串
that defines a search pattern. We can type an asterisk 定义搜索模式。我们可以输入一个星号
and that means everything, all files and all directories. 这意味着所有内容，所有文件和所有目录。
We can optionally add an extension, so to get all the files, you 我们可以选择添加扩展名，以便获取所有文件，
need the files you use star.star. With this 需要您使用star.star的文件。有了这个
pattern, we'll only get the files in the current directory. But not the directories. 模式，我们只会在当前目录中获取文件。但目录不行。
We can also search for all the py files, or all the excel 我们还可以搜索所有py文件或所有excel文件
spreadsheets. Anything. So let's search for all the py files 电子表格。任何事物。因此，让我们搜索所有的py文件
in the current directory, now when we run our program 在当前目录中，现在当我们运行程序时
we get this generator object. Generator object 我们得到了这个生成器对象。生成器对象
are kind of an advanced topic, and they are beyond the scope of this beginners 是一个高级主题，超出了这些初学者的讨论范围
python course. But for now all you need to know is we can iterate python课程。但是现在您需要知道的是我们可以迭代
or loop through these generator objects. So instead of 或遍历这些生成器对象。所以代替
printing this generator object, let's just iterate over it using 打印此生成器对象，让我们使用对其进行迭代
a for loop, so, for, file in, for循环，因此，for，文件输入，
the generator object that is returned from the glob method. q 从glob方法返回的生成器对象。 q
Let's print file. 让我们打印文件。
We run our program, there you go. So these are all the 我们运行我们的程序，随您去。这些都是
py files in my current directory, this could be different on your machine 我当前目录中的py文件，这在您的计算机上可能会有所不同
if you didn't follow the exercises I gave you earlier. For example, this 如果您不遵循我之前给您的练习。例如这个
utils.py, we created this as part of one of the exercises earlier in this course. utils.py，我们在本课程前面的练习之一中创建了它。
So don't worry if the files you see here are different on your machine. 因此，请不要担心您在此处看到的文件在计算机上是否有所不同。
So, you can use the glob method to search for files using 因此，您可以使用glob方法使用以下命令搜索文件
a pattern, we can also get all the files and directories in the current 模式，我们还可以获取当前文件中的所有文件和目录
path, so, we just use one asterisk, then 路径，因此，我们只使用一个星号，然后
run our program, take a look, so we have this 运行我们的程序，看看，所以我们有这个
ecommerce directory, we have notes.txt, this is a file I 电子商务目录中，我们有notes.txt，这是我的文件
added earlier just to write notes as part of my presentation so you're not going to have 之前添加只是为了在我的演示文稿中写笔记，所以您不会有
this file. We also have a bunch of directories and files. 这个文件。我们还有一堆目录和文件。
Even though python's standard library is comprehensive and has 即使python的标准库是全面的，并且具有
so many modules for common tasks, it's not complete by any means. 如此多的通用任务模块，无论如何都无法完成。
That's why we have this directory called python package 这就是为什么我们将这个目录称为python package
index. Or pypi. And in this directory you can find hundreds 指数。或pypi。在这个目录中，您可以找到数百个
of packages for doing awesome things. These are packages that people like you 包用于做很棒的事情。这些是像你这样的人的包裹
and I have built as part of our projects, and then they have published it as part of this directory. 并且我已经将其构建为我们项目的一部分，然后他们将其发布为该目录的一部分。
For other people to use. So that's why we have a fantastic community in python, 供其他人使用。这就是为什么我们在python中拥有一个梦幻般的社区，
there are so many python developers out there and there are so many packages 那里有很多python开发人员，而且包太多
right in front of us to reuse in our programs, let's say 就像我们前面所说的，可以在我们的程序中重用
you want to send text messages in your programs, you don't have to build this functionality from scratch, 您想在程序中发送文本消息，而不必从头开始构建此功能，
we can simply come to pypi.org and 我们可以简单地来到pypi.org
search for sms aas you can see there are so many 搜索短信aas，您可以看到有很多东西
projects or apckages that give you this functionality. Of course not every 可以为您提供此功能的项目或应用程序。当然不是每个
package, not every project is complete or bug free, some of them are still 包，不是每个项目都是完整的或没有错误的，其中有些仍然
in development or they have bugs, but if you look around I'm pretty sure 在开发中或存在错误，但是如果您环顾四周，我可以肯定
for any kind of function you can imagine there is a good 对于任何一种功能，您都可以想象有一个很好的
reliable and well documented package for you. In my complete python course, 可靠且文档齐全的软件包为您服务。在我完整的python课程中，
I will show you some of those most useful packages on pypi. For example 我将在pypi上向您展示一些最有用的软件包。例如
you will learn how to access the information on yelp.com in your 您将在自己的网站上了解如何访问yelp.com上的信息
programs. So you can write a program and search for businesses 程式。这样您就可以编写程序并搜索商家
registered on Yelp. Let's say you want to search for the best barber 在Yelp上注册。假设您要搜索最好的理发师
in New York City. I will show you how to do that. You will also learn how to use a technique called 在纽约市。我将向您展示如何做到这一点。您还将学习如何使用一种称为
web scraping, which means you can build an engine and have that engine 网络抓取，这意味着您可以构建一个引擎并拥有该引擎
browse a website, and extract information from HDML files. 浏览网站，然后从HDML文件中提取信息。
This is the same technique that Google does to index various 这与Google为各种索引建立索引的技术相同
websites. So they have several engines, or web crawlers, these web crawlers 网站。因此，他们有几个引擎或网络搜寻器，这些网络搜寻器
are continuously looking at various websites and extracting information 不断浏览各种网站并提取信息
from their pages. When you publish a blog post Google's web crawler 从他们的页面。当您发布博客文章时，Google的网络抓取工具
finds the title of your post, its keywords and so on. So, 查找您的帖子标题，其关键字等。所以，
I'm going to show you how to do that with Python, we'll also look at browser automation, and this is extremely 我将向您展示如何使用Python做到这一点，我们还将研究浏览器的自动化，这是极其重要的。
powerful, because you can automate testing of your web 功能强大，因为您可以自动测试网络
applications. So you might get a job as a test engineer, and 应用程序。因此，您可能会找到测试工程师的工作，并且
your daily job is to browse a website, click here and there, fill out this form, that form, and 您的日常工作是浏览网站，单击此处和此处，填写此表格，该表格，以及
ensure that this website is functioning properly. You can automate all that 确保此网站正常运行。您可以自动化所有
with a powerful python package called selenium, as I have shown in my complete, as I show in my complete 就像我在完整版中所展示的那样，在功能强大的python包中，它被称为selenium
python course. Now in this tutorial, I'm going to show you how to install python课程。现在，在本教程中，我将向您展示如何安装
packages, from pypi.org. So, 包，来自pypi.org。所以，
here on pypi.org let's search for open py 在pypi.org上，让我们搜索打开的py
xl. This is a package that we use for working with excel xl。这是我们用于excel的软件包
spreadsheets. So let's search for this package, there you go, so currently 电子表格。因此，让我们搜索此软件包，就可以了，目前
it's at version 2.5. On the top you can see, 它的版本是2.5。在顶部，您可以看到，
this instruction pip install open pyexcel. 此说明pip安装打开pyexcel。
this is the command that we need to type in the terminal window to 这是我们需要在终端窗口中键入的命令
install this package into our program, so back to pycharm, 将此软件包安装到我们的程序中，然后回到pycharm，
here on the status bar. You can open up a terminal window for executing 在状态栏上。您可以打开一个终端窗口来执行
various commands. So let's open it, now if you're on Windows 各种命令。因此，如果您使用的是Windows，现在就打开它
you're probably going to see something different instead of this dollar sign, don't worry about that 您可能会看到一些不同的东西，而不是这个美元符号，不用担心
just execute this command I'm going to show you. So pip 只需执行此命令，我将向您展示。所以点
install open py xl 安装open py xl
Make sure to spell everything properly. So pip is the tool, 确保正确拼写所有内容。点子就是工具
that comes with a python installation, and we use it to install or uninstall python安装附带的文件，我们使用它来安装或卸载
packages registered on pypi.org. So here, 在pypi.org上注册的软件包。所以在这里，
we're using pip to install this package. open py 我们正在使用pip安装此软件包。打开py
xl. Enter, let's go ahead with that, it's going to take a few xl。进入，让我们继续吧，这需要一些时间
seconds, oaky done, now we can import this package and it's 秒，完成了橡木桶，现在我们可以导入该软件包了
modules just like the built in modules in python, or the modules that we have 就像python中的内置模块一样，或者我们拥有的模块
in our project. Now if you're curious where this package 在我们的项目中。现在，如果您很好奇这个包装在哪里
is stored on disc let me show you. So open up the project panel, 存储在光盘上，让我向您展示。因此，打开项目面板，
and then expand external libraries, next 然后扩展外部库，接下来
expand python 3, and then expand sight packages. 展开python 3，然后展开景象包。
This is where all these packages that we installed with pip are stored. 这是我们通过pip安装的所有这些软件包的存储位置。
So here we have open py xl, you can open this, 所以我们在这里打开了py xl，您可以打开它，
in this folder we have another folder called cell, now 在此文件夹中，我们还有另一个名为cell的文件夹
Now, look what we have here you have this init 现在，看看我们在这里拥有的内容
type, earlier I told you that whenever we add this file to a folder, python treats 类型，之前我曾告诉您，每当我们将此文件添加到文件夹时，python都会
that folder as a package, so sell is a package, and this 该文件夹是一个包装，因此，sell是一个包装，而这个
package we have is modules. Sell, interface, read only and text. 我们拥有的包装是模块。出售，介面，只读和文字。
So as you can see, this package openpyxl has several 如您所见，这个包openpyxl有几个
subpackages like cell, start, chart sheet and so on. 子程序包，如单元格，开始，图表表等。
And in each package we have several modules, in the next tutorial 在下一个教程中，每个包中都有几个模块
I will show you how to work with excel files. 我将向您展示如何使用Excel文件。
So we have covered all the core concepts in Python, I hope you have learned a lot. 因此，我们涵盖了Python的所有核心概念，希望您能学到很多。
please support my hard work by liking this video and sharing it with others. 请喜欢这个视频并与他人分享，以支持我的辛勤工作。
And be sure to subscribe to my channel for more tutorials like this. Next we're 并且一定要订阅我的频道以获取更多类似的教程。接下来我们
going to work on our first python project that involves automation. 将要用于我们第一个涉及自动化的python项目。
You're going to write a python program that can process thousands of spreadsheets 您将要编写一个可以处理数千个电子表格的python程序
in under a second. Are you excited? Let's get started. 一秒钟之内。你兴奋吗？让我们开始吧。
In this tutorial I'm going to show you something really awesome you can do with python. You're going to 在本教程中，我将向您展示使用python可以做的非常棒的事情。你要去
learn how to process spreadsheets, and this is extremely valuable 了解如何处理电子表格，这是非常有价值的
in situation where you have hundreds or thousands of spreadsheets that need to 如果您有成百上千的电子表格需要
be updated. If you want to do this by hand it may take hours or days 被更新。如果您想手动执行此操作，则可能需要数小时或数天的时间
weeks, or even months, you can simply build a python program in less then 几周甚至几个月的时间，您只需在不到十分钟的时间内即可构建python程序
half an hour. And have that python program, automatically process thousands of spreadsheets 半小时。并拥有该python程序，可以自动处理数千个电子表格
in under one second. So, here we're going to work on this 一秒钟之内。因此，在这里我们将对此进行研究
excel spreadsheet. You can download this below this video. Excel电子表格。您可以在此视频下方下载此内容。
In this spreadsheet we have three columns, transaction ID, 在此电子表格中，我们有三列，即交易ID，
product ID, and press. Now don't worry about the fourth column yet. 产品ID，然后按。现在不用担心第四列。
So in this spreadsheet we're going to record all kinds of transactions, but let's say 因此，在此电子表格中，我们将记录各种交易，但假设
due to an error, it could be a human error or a system error. The price that we have 由于错误，可能是人为错误或系统错误。我们有的价格
here is wrong. Let's say we need to decrease this by 10 percent. 这是错的。假设我们需要将其降低10％。
If you want to do this manually, we'll have to come back here and 如果您想手动执行此操作，我们将不得不返回此处，
add a formula, so we typed out equal sign, let's say you want to recalculate 添加一个公式，所以我们键入等号，假设您要重新计算
say you want to recalculate the value of this cell. 说您要重新计算该单元格的值。
have to get that and then multiply it by 0.9 必须得到它，然后乘以0.9
and that is like 90% of the original price, we are reducing the original 就像原始价格的90％一样，我们正在降低原始价格
reducing the price by 10%. Now when you hit enter you can see the updated price. 将价格降低10％。现在，当您按Enter键时，您可以看到更新的价格。
Next we'll have to come back here, select this cell and 接下来，我们必须回到这里，选择该单元格，然后
apply the same formula to all the other rows. Now what if you have thousands of rows 将相同的公式应用于所有其他行。现在，如果您有数千行
here? You'll have to scroll up and down, this is going to be very tedious. 这里？您必须上下滚动，这将非常繁琐。
So we're going to write a python program that will do this for us. It's going to 因此，我们将编写一个python程序来为我们完成此任务。这将
auotmate this process and not only that it will also 支持这个过程，不仅会
add this beautiful chart right here, 在这里添加这张漂亮的图表，
once again if you want to open up hundreds or thousands of spreadsheets 如果您要打开数百或数千个电子表格，请再次单击
and add a chart to each one, this is going to take at least a week or two 并向每个图表添加图表，这至少需要一两个星期的时间
Our python program is going to do all of this in a matter of seconds. 我们的python程序将在几秒钟内完成所有这些操作。
So, let's get started. Alright the first thing I want you to do is 因此，让我们开始吧。好吧，我要你做的第一件事是
to download this transactions file and add it to your project. 下载此交易文件并将其添加到您的项目中。
I put the link below this video for you to download. So if you're wondering 我在此视频下方放置了链接，供您下载。所以如果你想知道
how to put this in this project, you can simply right click the project, 如何将其放入该项目中，您只需右键单击该项目，
and if you're on Mac you have this item where 如果您使用的是Mac，则在以下位置有此项目：
reveal in finder, if you're on Windows you should see something like reveal 在finder中显示，如果您使用的是Windows，则应该会看到诸如揭示
in explorer, or file explorer, or whatever it's called 在资源管理器或文件资源管理器中，或所谓的
when you click this, this opens up the direct 当您单击此按钮时，这将打开直接
on your machine where this is stored. So simply copy paste 在您存储它的计算机上。所以只需复制粘贴
the transactions file right here. Now, 交易文件就在这里。现在，
here on the top, first we need to import the open py excel package. 在顶部，首先，我们需要导入open py excel程序包。
So import open py excel, we can give it a 因此，导入open py excel，我们可以给它一个
an alias to make our code shorter. So asxl. 别名，使我们的代码更短。因此，asxl。
This is not required but it just makes our code a little bit cleaner. 这不是必需的，但是它只会使我们的代码更清晰一些。
Let me show you. So now instead of typing open pyxl. 让我演示给你看。因此，现在不用键入open pyxl。
we type xl. okay so that's an alias for 我们输入xl。好的，那是别名
this package. Now in this package we have a function for loading an xl 这个包。现在，在此程序包中，我们有一个加载xl的功能
workbook. So let's call load workbook, 工作簿。因此，我们将其称为“加载工作簿”，
and as the argument we pass transactions. 作为论据，我们通过交易。
.xlsx. So this we load .xlsx。所以我们加载
our excel workbook and return a workbook object. 我们的excel工作簿并返回一个工作簿对象。
Okay? Now if you open this workbook, you can see you add only 1 好的？现在，如果您打开此工作簿，则可以看到您仅添加了1个
sheet, and that is called sheet 1, so to access that you use 工作表，也称为工作表1，因此您可以使用
square brackets, and specify the name of the sheet, 方括号，并指定工作表的名称，
that is sheet one, make sure to spell this with a capital 这是第一页，请确保使用大写字母将其拼写
S. Because this is case sensitive, if you don't spell it properly S.因为这是区分大小写的，所以如果拼写不正确
you're going to get an error, so this returns a sheet, 您将得到一个错误，因此这将返回一个工作表，
now in this sheet, we have various cells. So 现在在此工作表中，我们有各种单元格。所以
next you need to learn how to access a particular cell, and that is very easy. 接下来，您需要学习如何访问特定的单元，这非常简单。
back to py charm, with this sheet object, you can use 回到py charm，使用此工作表对象，您可以使用
square brackets and give the coordinate of a cell. 方括号，并给出单元格的坐标。
Coordinate is the combination of the column and the row. 坐标是列和行的组合。
For example, this cell it's coordinate is a1. 例如，此单元格的坐标为a1。
So back to pycharm, we can type a1, and this returns 回到pycharm，我们可以输入a1，然后返回
our first cell. Also, there is another approach to getting 我们的第一个牢房。另外，还有另一种方法
a cell, instead of using square brackets with a string, we can 单元格，而不是使用方括号和字符串，我们可以
use the cell method of the sheet object, so, 使用工作表对象的单元格方法，因此，
sheet.cell, you pass the row and the column, so row sheet.cell，您传递行和列，所以行
and column 1 these return the exact same 第1列返回的结果完全相同
cell. Now let's print the value of this cell, cell.value 细胞。现在让我们打印此单元格的值cell.value
and run our program so 然后运行我们的程序
the value is transaction id, beautiful, 值是交易ID，很漂亮，
so now we need to iterate over all these rows and for each row we need to get the value 所以现在我们需要遍历所有这些行，并且对于每一行我们都需要获取值
in the third column. That is the price. We'll get that and then multiply 在第三栏中。那就是价格。我们会得到，然后相乘
by 0.9. So first we need to know how many rows 减0.9。所以首先我们需要知道多少行
we have in this spreadsheet. We can get that from the sheet object so sheet 我们在此电子表格中。我们可以从工作表对象中获取
has an attribute called mx_ 有一个名为mx_的属性
row. Let's print this, so in this sheet, 排。让我们打印一下，所以在此表中，
we have 4 row, and you can verify that here. So we have 我们有4行，您可以在此处进行验证。所以我们有
a total of 4 rows. So we need to add a for loop. 共4行。因此，我们需要添加一个for循环。
that would generate the numbers 1-4. So, 那将产生数字1-4。所以，
let's delete this print statement, nd add a for loop 让我们删除此打印语句，并添加一个for循环
for row in were going to use the range function unction to generate a range of numbers, 对于要使用范围函数功能来生成数字范围的行，
starting from 1, all the way to sheet 从1开始，一直到工作表
.max_grow. Plus 1. The reason we're .max_grow。加号1.我们之所以成为
adding 1 to this, is because as I told you before this range function 加上1，是因为正如我在此范围函数之前告诉您的那样
will generate numbers, starting from this value all the way to this 将从该值开始一直生成数字
value, but it will not include the second value. So currently 值，但不包括第二个值。所以目前
max row returns 4, if you use range of 1-4 this will generate max row返回4，如果您使用1-4的范围，则将生成
the numbers 1, 2, and 3, but not 4. 数字1、2和3，但不是4。
So to include 4, we need to add 1 to it. Let's go over here, 因此，要包括4，我们需要添加1。我们过去吧
so we tied sheet.max underline row plus 1. 因此，我们将sheet.max附加在下划线行加1上。
Now before going any further let's just print row and make 现在，在继续操作之前，我们只打印行并进行
sure our program is working up to this point. So let's run 确保我们的程序到此为止。所以我们开始吧
this, we get the numbers 1-4 beautiful. 这样，我们得到1-4个漂亮的数字。
So now we can easily get the cells in the third column. However 因此，现在我们可以轻松获取第三列中的单元格。然而
we don't really want this first cell, that's the heading. 我们真的不想要第一个单元格，就是标题。
so technically you want to ignore the first row. Back here, you want to change 因此从技术上讲，您想忽略第一行。回到这里，你想改变
our range function, and start from 2. Now, 我们的范围函数，从2开始。现在，
we're going to use sheet.cell to get access to the cell 我们将使用sheet.cell来访问单元格
at this row. And the column should be 3. 在这一行。且该列应为3。
We get a cell object, let's print it's value 我们得到一个单元格对象，让我们打印它的值
and make sure you're on the right track, so run the program 并确保您走在正确的轨道上，因此运行该程序
these are the values we get. 5.95 这些就是我们得到的价值。 5.95
6.95 and 7.95 these are the 这些是6.95和7.95
values of the third column. Next we need to multiply each 第三列的值。接下来，我们需要将每个相乘
value by 0.9 so instead of printing 值乘以0.9，而不是打印
cell.value we multiplied by 0.9 and this is cell.value我们乘以0.9，这是
the corrected underline price, 更正后的底价，
so this is the mistake we're going to make with our program, now 所以这是我们现在要用程序犯的错误
we need to add a new cell to our worksheet, so we want to add all the corrected 我们需要在工作表中添加一个新单元格，因此我们想添加所有已更正的单元格
prices, ia new column, it could also overwrite the values in this column, 价格（在新列中），它也可能会覆盖此列中的值，
but in this tutorial I'm going to show you how to add a new column. 但是在本教程中，我将向您展示如何添加新列。
So using the same method, now we need to get a reference to the cell, to the given 因此，使用相同的方法，现在我们需要获取给定单元格的引用
row, but in the fourth column. So, we call sheet 行，但在第四列中。所以，我们称为工作表
.cell, and pass row and four as the arguments. .cell，并传递第4行作为参数。
Once again, this returns a cell object, let's store that in a 再次返回一个单元格对象，让我们将其存储在
separate variable and call it 分离变量并调用它
price_cell. So note that my variable names are price_cell。因此请注意，我的变量名是
very descriptive. There is no guess work. You have corrected price which holds 非常具有描述性。没有猜测的工作。您已更正所持有的价格
actual value and we have corrected price, which is a cell 实际价值，我们已经更正了价格，这是一个单元格
object in this spreadsheet. Next we have to set the value in this 此电子表格中的对象。接下来，我们必须在其中设置值
cell. So we set corrected price cell. 细胞。因此，我们设置了更正后的价格单元。
value to this corrected price. With these few lines 此校正价格的价值。用这几行
we can easily update our spreadsheet, but first we need to save it. So, 我们可以轻松地更新电子表格，但是首先我们需要保存它。所以，
after our for loop, we call workbook. 在for循环之后，我们调用工作簿。
save. Now let's save this in a new file because we don't want to 保存。现在让我们将其保存在一个新文件中，因为我们不想
accidentally overwrite the original file in case our program has a bug 万一我们的程序有错误，不小心覆盖了原始文件
so, I'm going to call that transactions 2.sms 因此，我将其称为交易2.sms
ex. And finally let's run our program, 前任。最后，让我们运行我们的程序，
so, you can see that happened in a split of a second, now here we have a new file 因此，您可以很快就看到它发生了，现在我们有了一个新文件
tranactions 2. When we open this we get something like this. 交易2.当我们打开它时，我们得到的是这样的东西。
So you can see we have this 4th column with the updated prices. Beautiful. 因此，您可以看到我们具有更新价格的第4列。美丽的。
So half of the problem is solved, now we need to add a chart here. 这样就解决了一半的问题，现在我们需要在此处添加图表。
To add a chart, we need to add a couple classes on the top, so, 要添加图表，我们需要在顶部添加几个类，因此，
after this import statement let's type out from 在此import语句之后，让我们从
open py excel.chart, import, bar chart, 打开py excel.chart，导入，条形图，
comma, reference. 逗号，参考。
So lets see what's going on here. In this package you have a module 因此，让我们看看这里发生了什么。在这个包中，您有一个模块
chart, and from this module we're importing two classes, bar chart, 图表，然后从该模块中导入两个类，条形图，
and reference. Again, look at the naming convention used 和参考。再次，看看使用的命名约定
here. The first letter of e very word is capitalized. Also it's better 这里。 e单词的首字母大写。也更好
to add a line break after our import statements to make our 在导入语句之后添加换行符以使我们
code cleaner. So, before we save our workbook, we need to 代码清理器。因此，在保存工作簿之前，我们需要
add achart to the current sheet. First we need to select a range 将achart添加到当前工作表中。首先我们需要选择一个范围
of values. For this exercise, I'm going to select the values in the fourth column/. 价值。在本练习中，我将选择第四列中的值。
So all the values in rows 2-4 these are 因此，第2-4行中的所有值都是
the values I'm going to use in our chart. Now in this part 2 example it doesn't really 我将在图表中使用的值。现在在第2部分示例中，
make sense to add a chart per transaction, but that doesn't really matter 在每次交易中添加图表很有意义，但这并不重要
we just want a bunch of numbers to create a chart, so after our 我们只想用一堆数字来创建图表，所以在我们之后
for loop, we're going to use the reference class to select a range of for循环，我们将使用引用类选择范围
values. Now the first argument in the constructor is the 价值观。现在，构造函数中的第一个参数是
sheet. So we pass our sheet here, then we add 床单。所以我们在这里传递工作表，然后添加
4 keyword arguments, the first one is min_row, we set this to 4个关键字参数，第一个是min_row，我们将其设置为
2. The second one is max_row we set 2.第二个是我们设置的max_row
this to the maximum row in this sheet. That is sheet, 到此工作表中的最大行。那是床单，
.max_row, so we want to select the cells in row .max_row，所以我们要选择行中的单元格
2-4. kay? Now to make this code a little bit cleaner 2-4。 ？现在使此代码更清晰
I'm going to put this on a new line, so we 我要把它放在新的一行，所以我们
can see clearly, now this is going to select all the cells 可以清楚地看到，现在这将选择所有单元格
in all the columns in these rows. That's not what we want. 在这些行的所有列中。那不是我们想要的。
we only want the values in the fourth column, so back here 我们只需要第四列中的值，所以回到这里
we need to set a couple more key word arguments men_call 我们需要再设置几个关键字参数men_call
or column, we set that to for, and also 或列，我们将其设置为
max underline call, we set that to 4 as well. So we are limiting the range 最大下划线通话次数，我们也将其设置为4。所以我们限制范围
of cells we're selecting to the fourth column. 我们要选择的单元格的第四列
Now, we're creating an instance of the reference class, let's store the 现在，我们正在创建引用类的实例，让我们存储
result in a variable called values, so this values object 结果是一个叫做值的变量，所以这个值对象
will have all these values in the fourth column, now we are ready to create 在第四列中将具有所有这些值，现在我们准备创建
a chart, so we create an instance of the bar chart class 图表，所以我们创建条形图类的实例
and store it in this object. 并将其存储在此对象中。
Next, we call chart.add_date and 接下来，我们调用chart.add_date和
pass our values. That is pretty straight forward finally we need to add this chart 传递我们的价值观。 That is pretty straight forward finally we need to add this chart
to our sheet. So, we call sheet, to our sheet. So, we call sheet,
.add_chart and pass this chart object .add_chart and pass this chart object
We should also specify where we want to add this chart. We should also specify where we want to add this chart.
let's say we want to add it here, on row 2, after the fourth column. let's say we want to add it here, on row 2, after the fourth column.
So the coordinate of this cell is e2, and this is going to be, So the coordinate of this cell is e2, and this is going to be,
the top left corner of our chart. So as the coordinate I'm going to the top left corner of our chart. So as the coordinate I'm going to
pass e2 that's all we had to do, done. Let's run our pass e2 that's all we had to do, done. Let's run our
program one more time, beautiful, let's open up the update program one more time, beautiful, let's open up the update
workbook. And here's the end result, so workbook. And here's the end result, so
right after the fourth column, we have this beautiful chart. Now we could take this to the next level, right after the fourth column, we have this beautiful chart. Now we could take this to the next level,
we could add a legend here, we could change the color of these bars, we could even use a different we could add a legend here, we could change the color of these bars, we could even use a different
kind of chart, it doesn't have to be a bar chart. So to learn more about this we can kind of chart, it doesn't have to be a bar chart. So to learn more about this we can
read the documentation for openpyxl. So read the documentation for openpyxl.所以
our program is complete, for our code is dirty, it's not clean, it's not our program is complete, for our code is dirty, it's not clean, it's not
organized. We don't have any functions here. We have written all the code in app.py. 有条理。 We don't have any functions here. We have written all the code in app.py.
So let's goo ahead and organize this code like a professional software developer. So let's goo ahead and organize this code like a professional software developer.
So, on line 4, we are loading our workbook So, on line 4, we are loading our workbook
then we're getting a reference to the first sheet, but we don't really need these two lines here then we're getting a reference to the first sheet, but we don't really need these two lines here
this is purely for demonstration to show you how to access a cell. So, this is purely for demonstration to show you how to access a cell.所以，
let's delete these unnecessary lines, this is a very important practice let's delete these unnecessary lines, this is a very important practice
as you're coding always look at your code, always review it, see if you have some code that is as you're coding always look at your code, always review it, see if you have some code that is
not used. Always delete those. Okay, next we are iterating over not used. Always delete those. Okay, next we are iterating over
all the rows, fixing the prices, and then all the rows, fixing the prices, and then
we select the values to add a chart, and finally we save the workbook. we select the values to add a chart, and finally we save the workbook.
Now, if you were going to use this to automate the process of updating Now, if you were going to use this to automate the process of updating
thousands of spreadsheets, this program wouldn't work, because it's only thousands of spreadsheets, this program wouldn't work, because it's only
relying on this file. So we want o reorganize this code, and relying on this file. So we want o reorganize this code, and
move it inside of a function. This function should take the name of a function move it inside of a function. This function should take the name of a function
So let's define a function. Let's So let's define a function.让我们
call it process_workbook. call it process_workbook.
It gets a file name. Now, we move all the code inside It gets a file name. Now, we move all the code inside
of this function, so let's select everything, and press of this function, so let's select everything, and press
tab, beautiful, now back tab, beautiful, now back
to our function, instead of loading this transactions file we're going to load to our function, instead of loading this transactions file we're going to load
this file name, that's better, this file name, that's better,
Also, now that our program is working properly, there is really no need to store the Also, now that our program is working properly, there is really no need to store the
result in a separate file. So here we can result in a separate file. So here we can
simply overwrite the same file. So let's pass simply overwrite the same file. So let's pass
file name, that is the end of our function, so, file name, that is the end of our function, so,
now, we have this reusable function, we can simply reuse this now, we have this reusable function, we can simply reuse this
to process thousands of spreadsheets. Earlier in this python course you learned to process thousands of spreadsheets. Earlier in this python course you learned
how to find all the files in a directory, so we can get each file in a directory how to find all the files in a directory, so we can get each file in a directory
and pass the name of the file to this function, this function will go and pass the name of the file to this function, this function will go
ahead and update this spreadsheet in just a second or less. ahead and update this spreadsheet in just a second or less.
So, that was just one example of using python to automate So, that was just one example of using python to automate
repetitive boring task that waste your time. But automation is not repetitive boring task that waste your time. But automation is not
just about processing excel spreadsheets, there are so many things we can automate. just about processing excel spreadsheets, there are so many things we can automate.
Here's a question for you, what do you want to automate, how do you want to use python to make your Here's a question for you, what do you want to automate, how do you want to use python to make your
life easier? Use the comment box below and let me know. I love to life easier? Use the comment box below and let me know. I love to
hear about your ideas. Next we're going to work on project which involves machine learning, which is a hear about your ideas. Next we're going to work on project which involves machine learning, which is a
subset of artificial intelligence. Are you excited? subset of artificial intelligence.你兴奋吗？
Let's get started. 让我们开始吧。
In this section, you're going to learn about machine learning, which is a subset of In this section, you're going to learn about machine learning, which is a subset of
AI or artificial intelligence. It's one of the trending topics in the world, AI or artificial intelligence. It's one of the trending topics in the world,
these days, and it's going to have a lot of applications in the future. Here's an example. these days, and it's going to have a lot of applications in the future. Here's an example.
Imagine I ask you to write a program to scan an image, and Imagine I ask you to write a program to scan an image, and
tell if it's a cat or a dog. If you want to build this program using tell if it's a cat or a dog. If you want to build this program using
traditional programming techniques, your program is going to get overly complex traditional programming techniques, your program is going to get overly complex
You will have to come up with lots of rules to come up with specific curves You will have to come up with lots of rules to come up with specific curves
edges and colors in an image to tell if it's a cat or a dog. edges and colors in an image to tell if it's a cat or a dog.
But if I give you a black and white photo, your rules may not work, they may break. But if I give you a black and white photo, your rules may not work, they may break.
Then you would have to rewrite them. Or I may give you a picture of a cat or a dog from a different Then you would have to rewrite them. Or I may give you a picture of a cat or a dog from a different
angle that we did not predict before. So solving this problem angle that we did not predict before. So solving this problem
using traditional programming techniques is going to get overly complex or using traditional programming techniques is going to get overly complex or
sometimes impossible. Now to make the matter worse. What if I ask you to extend sometimes impossible. Now to make the matter worse. What if I ask you to extend
this program such that it supports 3 kinds of animals. this program such that it supports 3 kinds of animals.
Cats, dogs, and horses, once again you will have to rewrite Cats, dogs, and horses, once again you will have to rewrite
all those rules. That's not going to work. So machine learning is a technique all those rules.那是行不通的。 So machine learning is a technique
to solve these kinds of problems, and this is how it works. We build to solve these kinds of problems, and this is how it works. We build
a model or an engine and give it lots and lots of data. a model or an engine and give it lots and lots of data.
For example, we give it thousands or tens of thousands of pictures of For example, we give it thousands or tens of thousands of pictures of
cats and dogs. Our model will then find and learn patterns and the input cats and dogs. Our model will then find and learn patterns and the input
data, so we can give it a new picture of a cat that we haven't seen before. data, so we can give it a new picture of a cat that we haven't seen before.
And ask it, is it a cat or a dog or a horse And ask it, is it a cat or a dog or a horse
and it will tell us with a certain level of accuracy, the more input data we give it, the more accurate and it will tell us with a certain level of accuracy, the more input data we give it, the more accurate
our model is going to be. So that was a very basic example, our model is going to be. So that was a very basic example,
but machine learning has other applications in self driving cars, but machine learning has other applications in self driving cars,
robotics, language processing, vision processing, robotics, language processing, vision processing,
forecasting things like stock market trends and the weather, games and so on. forecasting things like stock market trends and the weather, games and so on.
So that's the basic idea about machine learning. Next we'll look at machine So that's the basic idea about machine learning. Next we'll look at machine
learning in action. learning in action.
A machine learning project involves A machine learning project involves
a number of steps, the first step is to import our data which a number of steps, the first step is to import our data which
often comes in the form of a csv file. You might have a database with lots of data, often comes in the form of a csv file. You might have a database with lots of data,
we can simply export that data and store it in a csv file for the we can simply export that data and store it in a csv file for the
purpose of our machine learning project. So we import our data, next, purpose of our machine learning project. So we import our data, next,
we need to clean it. And this involves tasks such as duplicated data. we need to clean it. And this involves tasks such as duplicated data.
If you have duplicates in the data, we don't want to feed this to the model, because If you have duplicates in the data, we don't want to feed this to the model, because
otherwise our model will learn bad patterns in our data and will produce the wrong result, otherwise our model will learn bad patterns in our data and will produce the wrong result,
so we should make sure that our input data is in a good, and clean shape. so we should make sure that our input data is in a good, and clean shape.
If there is data that is irrelevant we should remove them, if there are duplicates If there is data that is irrelevant we should remove them, if there are duplicates
or incomplete we can remove or modify them, if our data is or incomplete we can remove or modify them, if our data is
text based, like the name of countries, or genres of music, text based, like the name of countries, or genres of music,
or cats and dogs, we need to convert them to numerical values. or cats and dogs, we need to convert them to numerical values.
So this step really depends on the kinds of data we're working with, every project So this step really depends on the kinds of data we're working with, every project
is different. Now that we have a clean data set, we need to split it is different. Now that we have a clean data set, we need to split it
into two segments. One for training our model, and the other for into two segments. One for training our model, and the other for
testing it, to make sure our model produces the right result. testing it, to make sure our model produces the right result.
For example, if you have 1,000 pictures of cats and dogs, we can reserve For example, if you have 1,000 pictures of cats and dogs, we can reserve
80% for training, and another 20% for testing. 80% for training, and another 20% for testing.
The next step is to create a model, and this involves selecting The next step is to create a model, and this involves selecting
an algorithm to analyze the data. There are so many machine learning algorithms an algorithm to analyze the data. There are so many machine learning algorithms
out there, such as decision trees, neural networks and so on. out there, such as decision trees, neural networks and so on.
Each algorithm have pros and cons in terms of accuracy and performance Each algorithm have pros and cons in terms of accuracy and performance
so the algorithm you use, depends on the kind of problem so the algorithm you use, depends on the kind of problem
you're trying to solve and your input data. Now the good news isnthat we don't have to you're trying to solve and your input data. Now the good news isnthat we don't have to
explicitly program an algorithm, there are libraries out there that provide these explicitly program an algorithm, there are libraries out there that provide these
algorithms, one of the most popular ones, which we are going to look at algorithms, one of the most popular ones, which we are going to look at
in this tutorial, is side kick learn. So we build a model using an algorithm , in this tutorial, is side kick learn. So we build a model using an algorithm ,
next we need to train our model. So we feed it our training data. next we need to train our model. So we feed it our training data.
Our model will then look for the patterns in the data, so enxt Our model will then look for the patterns in the data, so enxt
we can ask it to make predictions. Back to our examples of cats and dogs, we can ask it to make predictions. Back to our examples of cats and dogs,
we can ask our model is this a cat or is this a dog and our model we can ask our model is this a cat or is this a dog and our model
will make a prediction, now the prediction is not always accurate will make a prediction, now the prediction is not always accurate
in fact when you start out, it's very likely your predictions are inaccurate. in fact when you start out, it's very likely your predictions are inaccurate.
So we need to envalue the predictions and measure their accuracy. So we need to envalue the predictions and measure their accuracy.
Then we need to get back to our model and either select a different algorithm Then we need to get back to our model and either select a different algorithm
that is going to produce a more accurate result for the kind of problem that is going to produce a more accurate result for the kind of problem
we're trying to solve. Or fine tune the parameters of our model. we're trying to solve. Or fine tune the parameters of our model.
So each algorithm has parameters that we can modify to optimize the So each algorithm has parameters that we can modify to optimize the
accuracy. So these are the high level steps that you follow in a machine learning 准确性。 So these are the high level steps that you follow in a machine learning
project. Next we'll look at the libraries and tools for machine learning. 项目。 Next we'll look at the libraries and tools for machine learning.
In this lecture we're going too look at the popular python library In this lecture we're going too look at the popular python library
that we use in machine learning projects. The first one is numpy which that we use in machine learning projects. The first one is numpy which
provides a multidimensional array. A very, very, popular library. provides a multidimensional array. A very, very, popular library.
The seconnd one is pandas, which is a data analysis library that The seconnd one is pandas, which is a data analysis library that
provides a concept called data frame. Data frame is a two dimensional provides a concept called data frame. Data frame is a two dimensional
data structure similar to an excel spreadsheet. So we have rows and columns data structure similar to an excel spreadsheet. So we have rows and columns
we can select columns in a row or a column or a range of rows and we can select columns in a row or a column or a range of rows and
columns, again, very very popular in machine learning columns, again, very very popular in machine learning
and data science projects. The third library is mad plot lib which and data science projects. The third library is mad plot lib which
is a two dimensional plotting library for creating graphs on plots. is a two dimensional plotting library for creating graphs on plots.
The next library is sidekick learn, which is one of the most popular machine learning The next library is sidekick learn, which is one of the most popular machine learning
libraries that provides all these common algorithms like decision trees, libraries that provides all these common algorithms like decision trees,
neural networks and so on. Now, when working with machine learning neural networks and so on. Now, when working with machine learning
projects, we use an environment called jupiter for writing our code, technically we can still projects, we use an environment called jupiter for writing our code, technically we can still
use vs code or any other code editor, but these editors use vs code or any other code editor, but these editors
are not ideal for machine learning projects, because we need to frequently are not ideal for machine learning projects, because we need to frequently
inspect the data, and that is really hard in environments like vs code and inspect the data, and that is really hard in environments like vs code and
terminal. If you're working with a table of 10 or 20 columns terminal. If you're working with a table of 10 or 20 columns
visualizing this data in a terminal window is really, really difficult and messy, so thats why we use jupiter. visualizing this data in a terminal window is really, really difficult and messy, so thats why we use jupiter.
So that's why we use jupiter, it makes it really easy to inspect our data. So that's why we use jupiter, it makes it really easy to inspect our data.
Now to install jupiter, we are going to use platform called anaconda. Now to install jupiter, we are going to use platform called anaconda.
So, head over to Anaconda.com/download. So, head over to Anaconda.com/download.
On this page you can download Anaconda distribution for your operating system, On this page you can download Anaconda distribution for your operating system,
so, we have distributions for Windows Mac and so, we have distributions for Windows Mac and
Linux. So let's go ahead and install Linux. So let's go ahead and install
Anaconda for python 3.7. Download, Anaconda for python 3.7. Download,
Alright, so Alright, so
here's Anaconda, download it on my machine, let's double click this. here's Anaconda, download it on my machine, let's double click this.
Alright, first it's going to run a program to determine if the software can be installed. Alright, first it's going to run a program to determine if the software can be installed.
So, let's continue and once again continue, So, let's continue and once again continue,
pretty easy, continue one more time, pretty easy, continue one more time,
I agree with the license agreement, we can use the default I agree with the license agreement, we can use the default
you ca use the default installation location so don't worry about that, just click install, you ca use the default installation location so don't worry about that, just click install,
give it a few second, now the beautiful thing about Anaconda is it will install give it a few second, now the beautiful thing about Anaconda is it will install
jupiter, as well as all those data popular science libraries jupiter, as well as all those data popular science libraries
like numpy, Pandas and so on. So we don't have to manually install this like numpy, Pandas and so on. So we don't have to manually install this
using pip. Alright now as part of using pip. Alright now as part of
the next step Anaconda is suggesting to install Microsoft vs code. We the next step Anaconda is suggesting to install Microsoft vs code.我们
already have this on our machine so we don't have to install it we can go with continue already have this on our machine so we don't have to install it we can go with continue
and close the installation, now finally we can move the and close the installation, now finally we can move the
this to trash because we don't need this installer in the future. this to trash because we don't need this installer in the future.
Alright, now open upa terminal window and type Alright, now open upa terminal window and type
jupiter, with a y, space, notebook. jupiter, with ay, space, notebook.
This will start the notebook server on your machine. So enter This will start the notebook server on your machine. So enter
there you go. This will start the notebook server 你去。 This will start the notebook server
on your machine, we can see these default messages here, don't worry about them, now on your machine, we can see these default messages here, don't worry about them, now
it automatically opens a browser window, pointing to local host it automatically opens a browser window, pointing to local host
port 888. This is what we call port 888. This is what we call
jupiter dashboard. On this dashboard we have a few tabs, the first tab jupiter dashboard. On this dashboard we have a few tabs, the first tab
is the files tab, and by default, this points to your home directory. is the files tab, and by default, this points to your home directory.
So every user on your machine has a home directory, this its my home directory So every user on your machine has a home directory, this its my home directory
on Mac, you can see here we have a desktop folder as well as documents, on Mac, you can see here we have a desktop folder as well as documents,
downloads and so on. On your machine you're going to see different folders, so somewhere downloads and so on. On your machine you're going to see different folders, so somewhere
so somewhere on your machine you need to create a jupiter notebook. I'm going to go to desktop so somewhere on your machine you need to create a jupiter notebook. I'm going to go to desktop
here's my desktop I don't have anything here, and then here's my desktop I don't have anything here, and then
click new, I want to create a notebook for python click new, I want to create a notebook for python
3. In this notebook we can write python code, and execute it line by line. 3. In this notebook we can write python code, and execute it line by line.
We can easily visualize our data as you can see over the next few videos. So, We can easily visualize our data as you can see over the next few videos.所以，
let's go ahead with this, let's go ahead with this,
alright, here's our first notebook, you can see by default it's called alright, here's our first notebook, you can see by default it's called
untitled, let's change that to Hello World so untitled, let's change that to Hello World so
this is going to be the hello world of our machine learning project. Let's this is going to be the hello world of our machine learning project.让我们
rename this now if you look at your desktop you can see this file rename this now if you look at your desktop you can see this file
hello world.ipynb. This is a jupiter hello world.ipynb. This is a jupiter
notebook. It's kind of similar to our py files where we write our 笔记本。 It's kind of similar to our py files where we write our
python code, but it includes additional data that jupiter uses to execute our python code, but it includes additional data that jupiter uses to execute our
code. So back to our notebook, let's code. So back to our notebook, let's
do a print hello world. do a print hello world.
And then, click this run button here And then, click this run button here
and here's the result printed in jupiter, so we don't have to and here's the result printed in jupiter, so we don't have to
navigate back and forth between the terminal window we can see all the result navigate back and forth between the terminal window we can see all the result
right here. Next I'm going to show you how to load a data set from a 就在这儿。 Next I'm going to show you how to load a data set from a
csv file in jupiter. csv file in jupiter.
Alright, in this lecture we're going to download a data set from a very popular website called Alright, in this lecture we're going to download a data set from a very popular website called
caggle.com. Caggle is basically a place to do data science projects. caggle.com. Caggle is basically a place to do data science projects.
So the first thing you need to do is to create an account, you can sign up with Facebook, So the first thing you need to do is to create an account, you can sign up with Facebook,
Google, or using a custom email and password, once you sign up then come back Google, or using a custom email and password, once you sign up then come back
here, on caggle.com, Here one the search bar here, on caggle.com, Here one the search bar
search for video game sales. search for video game sales.
This is the name of a very popular data set that we're going to use in this lecture. So, This is the name of a very popular data set that we're going to use in this lecture.所以，
here in this list you can see the first item with this kind of reddish here in this list you can see the first item with this kind of reddish
icon, so, let's go with that, as you can see this data icon, so, let's go with that, as you can see this data
set includes the sales data for more then 16,000 videos set includes the sales data for more then 16,000 videos
games. On this page you can see the description of various 游戏。 On this page you can see the description of various
columns in this data set, we have rank, name, platform, columns in this data set, we have rank, name, platform,
year, and so on, so here's our data source, it's a csv file year, and so on, so here's our data source, it's a csv file
called vg sales.csv, as you can see there are over 16,000 called vg sales.csv, as you can see there are over 16,000
rows, and 11 columns in this data set. rows, and 11 columns in this data set.
Right below that you can see the first few records of this data set. Right below that you can see the first few records of this data set.
So, here's our first record, the ranking for this game is 1, it's the wi sport So, here's our first record, the ranking for this game is 1, it's the wi sport
game for wii as the platform and it was released in the year 2006, game for wii as the platform and it was released in the year 2006,
now, what I want you to do is go ahead and now, what I want you to do is go ahead and
download the data set, and as I told you before you need to sign in download the data set, and as I told you before you need to sign in
before you can download this. So this will give you a zip file as you can see here, before you can download this. So this will give you a zip file as you can see here,
here's our csv file, now I want you to here's our csv file, now I want you to
put this right next to your jupiter notebook, on my machine that is on my desktop put this right next to your jupiter notebook, on my machine that is on my desktop
so I'm going to drag and drop this onto the desktop folder. so I'm going to drag and drop this onto the desktop folder.
Now, if you look at the desktop you can see here's my Now, if you look at the desktop you can see here's my
jupiter, hello world notebook, and right next to that we have jupiter, hello world notebook, and right next to that we have
vgsales.csv. With that, we go back vgsales.csv. With that, we go back
to our jupiter notebook, let's remove the first line and instead to our jupiter notebook, let's remove the first line and instead
import pandas import pandas
as pd. With his we're importing pandas module as pd. With his we're importing pandas module
and renaming it to pd, so we don't have to type pandas. several times in and renaming it to pd, so we don't have to type pandas. several times in
this code. Now let's type pd. this code. Now let's type pd.
read_csv. And pass the read_csv. And pass the
name of our csv file. That is vgsales. name of our csv file. That is vgsales.
csv. Now because this csv file, is in the current folder right next to our jupiter notebook, csv. Now because this csv file, is in the current folder right next to our jupiter notebook,
we can easily load it, otherwise we have to supply the full path we can easily load it, otherwise we have to supply the full path
to this file. So, this returns a to this file. So, this returns a
data frame object which is like an excel spreadsheet. Let me show you. data frame object which is like an excel spreadsheet.让我演示给你看。
So we store it here, and then we can So we store it here, and then we can
simply type df to inspect it. So one more time let's run this program simply type df to inspect it. So one more time let's run this program
here's our data frame with these rows and these columns so we have here's our data frame with these rows and these columns so we have
frank name platform and so on. Now this data frame object frank name platform and so on. Now this data frame object
has lots of attributes and methods that we're not going to cover in this tutorial, has lots of attributes and methods that we're not going to cover in this tutorial,
that's really beyond the scope of what we're going to do, so I'm going to leave it up to you to that's really beyond the scope of what we're going to do, so I'm going to leave it up to you to
read pandas documentation or follow other tutorials to find out about pandas data frames. read pandas documentation or follow other tutorials to find out about pandas data frames.
But in this lecture, I'm going to show you some of the most useful methods and attributes. But in this lecture, I'm going to show you some of the most useful methods and attributes.
The first one is shape, so shape The first one is shape, so shape
let's run this one more time, so here's the shape of this data set, we have over let's run this one more time, so here's the shape of this data set, we have over
16,000 records and 11 columns. 16,000 records and 11 columns.
Technically this is a 2 dimensional array of 16,000 Technically this is a 2 dimensional array of 16,000
and 11, okay? Now, we can see here we have another and 11, okay? Now, we can see here we have another
segment for writing code. SO we don't have to write all the code in the first segment segment for writing code. SO we don't have to write all the code in the first segment
so here in the second segment we can call one of the methods of the dataframe, so here in the second segment we can call one of the methods of the dataframe,
that is df.describe. that is df.describe.
Now when we run this program, we can see the Now when we run this program, we can see the
output for each segment right next to it. So here's our first output for each segment right next to it. So here's our first
segment, here we have these three lines, and this is the output of segment, here we have these three lines, and this is the output of
the last line. Below that we have our second segment, here we're calling the last line. Below that we have our second segment, here we're calling
the describe method, and right below that we have the output of the describe method, and right below that we have the output of
this segment So this is the beauty of jupiter, you can easily visualize this segment So this is the beauty of jupiter, you can easily visualize
our datsa, doing this with vscode in windows is really tedious and our datsa, doing this with vscode in windows is really tedious and
clunky. So what is the describe method returning? Basically it's clunky. So what is the describe method returning? Basically it's
returning some basic information about each column in this data set, So, returning some basic information about each column in this data set, So,
as you saw earlier we have columns like rank, year and so as you saw earlier we have columns like rank, year and so
on. These are the columns with numerical values. Now for each column we have 上。 These are the columns with numerical values. Now for each column we have
the count which is the number of records in that column, you can se the count which is the number of records in that column, you can se
our rank column has 16,5 our rank column has 16,5
-98 records whereas the year column has 16,3- -98 records whereas the year column has 16,3-
-27 records.. So this shows that some of our records don't -27 records.. So this shows that some of our records don't
have the value for the year column. We have null values. have the value for the year column. We have null values.
So in a real data science or machine learning project we'll have to use some So in a real data science or machine learning project we'll have to use some
techniques to clean up our data set. One option is to remove the records techniques to clean up our data set. One option is to remove the records
that don't have a value for the year column. Or we can assign them a default value. that don't have a value for the year column. Or we can assign them a default value.
That really depends on the project. Now another attribute for each column That really depends on the project. Now another attribute for each column
is mean so this is the average of all the values, now is mean so this is the average of all the values, now
in the case of the rank column, this rank doesn't really matter, but look at the year. in the case of the rank column, this rank doesn't really matter, but look at the year.
So the average year year for all these video games in our dataset is So the average year year for all these video games in our dataset is
2006. And this might be important in the problem we're trying to solve. 2006. And this might be important in the problem we're trying to solve.
We also have standard deviation, which is a We also have standard deviation, which is a
measure to quanitfy the amount of variation in our set of values, below that we have measure to quanitfy the amount of variation in our set of values, below that we have
min, as an example the minimum value for the year column min, as an example the minimum value for the year column
is 1980. So quite often when we work with a new data set, is 1980. So quite often when we work with a new data set,
we call the describe method to get some basic statistics about we call the describe method to get some basic statistics about
our data. Let me show you another useful attribute. our data. Let me show you another useful attribute.
So, in the next segment, let's type df.values. So, in the next segment, let's type df.values.
Let's run this, as you can see this returns Let's run this, as you can see this returns
a two dimensional array, this square bracket indicates the outer array a two dimensional array, this square bracket indicates the outer array
and a second one represents an inner array. and a second one represents an inner array.
So the first element inn our outer array, is an So the first element inn our outer array, is an
array itself, these are the values in this array, which basically array itself, these are the values in this array, which basically
represent the first row in our data set. So the video game we ranking represent the first row in our data set. So the video game we ranking
1, which is called wii sports. So this was a basic 1, which is called wii sports. So this was a basic
overview of pandas data frames, in the next lecture I'm going to show you overview of pandas data frames, in the next lecture I'm going to show you
some of the useful shortcuts of jupiter. some of the useful shortcuts of jupiter.
In this lecture I'm going to show to you some of the most useful shortcuts in Jupiter, In this lecture I'm going to show to you some of the most useful shortcuts in Jupiter,
Now the first thing I want you to pay attention to is this green bar on the left. Now the first thing I want you to pay attention to is this green bar on the left.
This indicates that this cell is currently in the edit mode, so we can This indicates that this cell is currently in the edit mode, so we can
write code here. Now, if we press the write code here. Now, if we press the
escape key, green turns to blue, and that means this cell is escape key, green turns to blue, and that means this cell is
currently in the command mode. So basically the activated cell can either currently in the command mode. So basically the activated cell can either
be in the edit mode or command mode. Depending be in the edit mode or command mode. Depending
on the mode, we have different shortcuts, so here we're in the command mode. on the mode, we have different shortcuts, so here we're in the command mode.
If we press h, we can see the list of all the If we press h, we can see the list of all the
keybord shortcuts, right above this list we can keybord shortcuts, right above this list we can
see, Mac OS modifier keys, these are the see, Mac OS modifier keys, these are the
extra keys on a Mac keyboard. If you're a Windows extra keys on a Mac keyboard. If you're a Windows
user you're not gong to see these. So as an example, here is the shape of the user you're not gong to see these. So as an example, here is the shape of the
command key, this is control, this is option, command key, this is control, this is option,
and so on. With this guideline you can easily understand the shortcut associated with and so on. With this guideline you can easily understand the shortcut associated with
each command. Let me show you. So here we have all each command.让我演示给你看。 So here we have all
the commmands when a cell is in the command mode. For example, we have the commmands when a cell is in the command mode. For example, we have
this command, open the command palette. This is exactly like the this command, open the command palette. This is exactly like the
command palette that we have in vs code. Here is a short cut command palette that we have in vs code. Here is a short cut
to execute this command. That is command shift and F. to execute this command. That is command shift and F.
Okay, so here we have lots of shortcuts, Okay, so here we have lots of shortcuts,
of course you're not going to use all of them all the time, but it's good to have a quick look here to see of course you're not going to use all of them all the time, but it's good to have a quick look here to see
what is available for you. Tis these shortcuts you can write code much faster. what is available for you. Tis these shortcuts you can write code much faster.
So let me show you somme of the most useful ones. I'm going to close this, So let me show you somme of the most useful ones. I'm going to close this,
now with our first cell in the command mode now with our first cell in the command mode
I'm going to press b, and this inserts, a new I'm going to press b, and this inserts, a new
cell below this cell. We can also go cell below this cell. We can also go
back to our first cell, press escape, now the cell is in the command back to our first cell, press escape, now the cell is in the command
mode. We can insert an empty cell above this cell by pressing a. 模式。 We can insert an empty cell above this cell by pressing a.
So either a or b. A for above or So either a or b. A for above or
b for below. Now if you don't want this cell, you can press d b for below. Now if you don't want this cell, you can press d
twice to delete it. Like this. twice to delete it.像这样。
Now in the cell I'm going to print a hello world message. So print Now in the cell I'm going to print a hello world message. So print
hello world. Now, to hello world. Now, to
run the code in this cell, we can click on the run button here, run the code in this cell, we can click on the run button here,
so, here's our print function, and so, here's our print function, and
right below that you can see the output of this function. But note that when you run right below that you can see the output of this function. But note that when you run
a cell, this will only execute the code in that cell. a cell, this will only execute the code in that cell.
In other words, the code in other cells will not be executed. In other words, the code in other cells will not be executed.
Let me show you want I mean, so in the cell below the cell, I'm going to delete the call Let me show you want I mean, so in the cell below the cell, I'm going to delete the call
to a describe method. Instead I'm going to print to a describe method. Instead I'm going to print
ocean. Now, I'm going ocean. Now, I'm going
to put the cursor back in this cell where we print this hello world message to put the cursor back in this cell where we print this hello world message
and run this cell. So we can see hello world and run this cell. So we can see hello world
is displayed here, but the cell below is still displaying is displayed here, but the cell below is still displaying
the describe table, so we don't see the changes here. Now, the describe table, so we don't see the changes here.现在，
to solve this problem, we can go to the cell menu on the top, to solve this problem, we can go to the cell menu on the top,
and run all cells together. This can work for a and run all cells together. This can work for a
small project, but sometimes you're working with a large data small project, but sometimes you're working with a large data
set, so if you want to run all these cells together it's going to take a lot of time. That is set, so if you want to run all these cells together it's going to take a lot of time.那是
the reason jupiter saves the output of each cell, so we don't have to rerun that the reason jupiter saves the output of each cell, so we don't have to rerun that
code if it hasn't changed. So this notebook file that we have here, code if it hasn't changed. So this notebook file that we have here,
includes our source code organized in cells as includes our source code organized in cells as
well as the output for each cell. That is why it's different well as the output for each cell. That is why it's different
from a regular py file where we only have the source code. from a regular py file where we only have the source code.
Here we also have autocompletion and intellisence, so in this cell, Here we also have autocompletion and intellisence, so in this cell,
let's call df data frame let's call df data frame
. now if you press tab you can see all the attributes 。 now if you press tab you can see all the attributes
and methods in this object. So let's call and methods in this object. So let's call
describe, now with the cursor on the name of the method we can describe, now with the cursor on the name of the method we can
press shift and tab, to see this tool tip that describes press shift and tab, to see this tool tip that describes
what this method does and what parameter it takes. So here in front of what this method does and what parameter it takes. So here in front of
so here in front of signature you can see the describe method, these are the paramter so here in front of signature you can see the describe method, these are the paramter
and their default value, and right below that you can see and their default value, and right below that you can see
the description of what that method does. In this case, it describes the description of what that method does. In this case, it describes
generates descriptive statistics, that summarize the central tendency and so on. generates descriptive statistics, that summarize the central tendency and so on.
Similar to vs code, we can also convert a line to comment Similar to vs code, we can also convert a line to comment
by pressing command and slash on mac, or by pressing command and slash on mac, or
control slash on windows. Like this. Now that line is a comment, we can control slash on windows.像这样。 Now that line is a comment, we can
press the same shortcut one more time to remove the comment, press the same shortcut one more time to remove the comment,
so these are some of the most useful shortcuts in jupiter. so these are some of the most useful shortcuts in jupiter.
Now over the next few lectures we're going to work on a real machine learning project, but before we get there, Now over the next few lectures we're going to work on a real machine learning project, but before we get there,
let's delete all the cells here, so we start with only a single let's delete all the cells here, so we start with only a single
empty cell, so here, in this cell, first I'm going to press the empty cell, so here, in this cell, first I'm going to press the
escape button, now the cell is blue, so we're in the command mode, and escape button, now the cell is blue, so we're in the command mode, and
we can delete the cell by pressing d twice. There you go. we can delete the cell by pressing d twice.妳去
Now, the next cell is activated and is in the command mode. Now, the next cell is activated and is in the command mode.
So, let's delete this as well, so we have two more cells to delete So, let's delete this as well, so we have two more cells to delete
there you go, and the last one, like this, there you go, and the last one, like this,
so now we have an empty notebook with a single cell. so now we have an empty notebook with a single cell.
Over the next few lectures, we're going to work on a real machine learning project, Over the next few lectures, we're going to work on a real machine learning project,
imagine we have an online music store, when our users sign up, imagine we have an online music store, when our users sign up,
we asked our age and gender, and based on their profile, we asked our age and gender, and based on their profile,
you recommend various music albums their likely to buy. So in this project, you recommend various music albums their likely to buy. So in this project,
you want to use machine learning to increase sales. you want to use machine learning to increase sales.
So, we want to build a model, we feed this model with some sample data, So, we want to build a model, we feed this model with some sample data,
based on the existing users. Our model will learn the patterns in our data, based on the existing users. Our model will learn the patterns in our data,
so we can ask it to make predictions. When a new user signs up, so we can ask it to make predictions. When a new user signs up,
we tell our model, hey, we have a new user with this profile, what we tell our model, hey, we have a new user with this profile, what
is the kind of music, that this user is interested in, our model will say jazz, or hip hop, is the kind of music, that this user is interested in, our model will say jazz, or hip hop,
or whatever, and baed on that we can make suggestions to the user or whatever, and baed on that we can make suggestions to the user
so, this is the problem we're going to solve, now back to the list of steps in the machine so, this is the problem we're going to solve, now back to the list of steps in the machine
learning projects, first we need to import our data, then, we should learning projects, first we need to import our data, then, we should
prepare or clean it, next we select a machine learning algorithm prepare or clean it, next we select a machine learning algorithm
to build a model, we treat our model and ask it to make predictions. to build a model, we treat our model and ask it to make predictions.
And finally, we evaluate our algorithm to see it's And finally, we evaluate our algorithm to see it's
accuracy. if it's not accurate we either fine tune our model or 准确性。 if it's not accurate we either fine tune our model or
select a different algorithm. So let's focus on the first step. select a different algorithm. So let's focus on the first step.
Head over to bit.ly/music.csv Head over to bit.ly/music.csv
this is a very basic csv that I've created for this project, it's just some random this is a very basic csv that I've created for this project, it's just some random
made up data it's not real. So we have a table with 3 made up data it's not real. So we have a table with 3
columns, age, gender, and genre. Gender columns, age, gender, and genre.性别
can either be one which represents a male, can either be one which represents a male,
or a 0, which represents a female, here I'm making a few assumptions. or a 0, which represents a female, here I'm making a few assumptions.
I'm assuming that men between 20 and 25 like hip hop men between I'm assuming that men between 20 and 25 like hip hop men between
26 and 30 like jazz, and after the age of 30, 26 and 30 like jazz, and after the age of 30,
they like classical music. For women I'm assuming they like classical music. For women I'm assuming
that if they are between 20 and 25 they like dance music, if that if they are between 20 and 25 they like dance music, if
they are between 26 and 30 they like acoustic music, and just like they are between 26 and 30 they like acoustic music, and just like
men, after the age of 30 they like classical music. Once again this is men, after the age of 30 they like classical music. Once again this is
a made up pattern, it's not the representation of the reality, so, a made up pattern, it's not the representation of the reality, so,
let's go ahead and download this csv. Click on this ... icon here let's go ahead and download this csv. Click on this ... icon here
and download this file. and download this file.
In my downloads folder, here we have this music.csv. In my downloads folder, here we have this music.csv.
I'm going to drag and drop this onto the desktop because that's where I've I'm going to drag and drop this onto the desktop because that's where I've
stored this hello world notebook. So I want you to put this csv file stored this hello world notebook. So I want you to put this csv file
right next to your jupiter notebook. right next to your jupiter notebook.
Now, back to our notebook, you need to read the csv file, so just like before Now, back to our notebook, you need to read the csv file, so just like before
first we need to import the pandas module, so import panda first we need to import the pandas module, so import panda
as pd. And then we'll call pd, as pd. And then we'll call pd,
.read_csv and .read_csv and
the name of our file is music.csv. As you saw earlier this the name of our file is music.csv. As you saw earlier this
returns a data frame which is a two dimensional array similar to an xl spreadsheet, returns a data frame which is a two dimensional array similar to an xl spreadsheet,
so let's call that music_ so let's call that music_
data. Now let's inspect data. Now let's inspect
this music_data to make sure we loaded everything properly so this music_data to make sure we loaded everything properly so
run, so here's our data frame, beautiful, next we need run, so here's our data frame, beautiful, next we need
to prepare or clean the data. And that's the topic for the next lecture. to prepare or clean the data. And that's the topic for the next lecture.
next lecture. next lecture.
The second step in a machine learning project, is cleaning, or The second step in a machine learning project, is cleaning, or
preparing the data, and that involves tasks such as removing duplicate preparing the data, and that involves tasks such as removing duplicate
null values and so on. Now on this particular data set we don't have to do anything null values and so on. Now on this particular data set we don't have to do anything
kind of cleaning, because we don't have any duplicates, and as you can see kind of cleaning, because we don't have any duplicates, and as you can see
As you can see, all rows have values for all columns, so we don't have null values. As you can see, all rows have values for all columns, so we don't have null values.
But there is one thing we need to do, But there is one thing we need to do,
we should split this data set into two separate data sets, one into the first we should split this data set into two separate data sets, one into the first
two columns, which we refer to as the input set, and the other two columns, which we refer to as the input set, and the other
with the last column which we refer to as the output set. So when we train a model, with the last column which we refer to as the output set. So when we train a model,
so when we train a model we give it two separate data sets. The input set and the output set. so when we train a model we give it two separate data sets. The input set and the output set.
The output set which is in this case The output set which is in this case
the genre column contains the predictions so we're telling our model that the genre column contains the predictions so we're telling our model that
if we have a user who's 20 years old and a male they like if we have a user who's 20 years old and a male they like
hip hop. Once we train our model then we give it a new hip hop. Once we train our model then we give it a new
input set. For example, we have a new user who is input set. For example, we have a new user who is
21 years old and is a male, what is the genre of the music that this 21 years old and is a male, what is the genre of the music that this
user probably likes. As you can see in our input set, we don't have user probably likes. As you can see in our input set, we don't have
a sample for a 21 year old male, so we're going to ask a sample for a 21 year old male, so we're going to ask
our model to predict that. That is the reason we need to split this data our model to predict that. That is the reason we need to split this data
set into two separate sets. Input and output set into two separate sets. Input and output
So back to our code, this data frame object has a So back to our code, this data frame object has a
method called drop. Now method called drop.现在
if you put the cursor on the method name and press shift if you put the cursor on the method name and press shift
and tab, you can see this tool tip, so this is the signature of and tab, you can see this tool tip, so this is the signature of
this drop method, these are the parameters you can pass here. this drop method, these are the parameters you can pass here.
the parameter we're going to use in this lecture is set to none by default. the parameter we're going to use in this lecture is set to none by default.
Witht his parter we can specify the columns we want to drop, so Witht his parter we can specify the columns we want to drop, so
in this case we set columns in this case we set columns
to an array with one string, genre to an array with one string, genre
now this method doesn't actually modify the original data set. now this method doesn't actually modify the original data set.
In fact it will create a new data set but without thisq In fact it will create a new data set but without thisq
call. So by convention we use a capital X to call. So by convention we use a capital X to
represent that data set, so capital x equals this represent that data set, so capital x equals this
expression. Now, let's inspect x, 表达。 Now, let's inspect x,
so as you can see our input set or x so as you can see our input set or x
includes these two columns, age and gender, it doesn't have the includes these two columns, age and gender, it doesn't have the
output or predictions. Next we need to create our output set so, output or predictions. Next we need to create our output set so,
once again we start with our data frame once again we start with our data frame
using data, using square brackets we can get all the using data, using square brackets we can get all the
values in a given column. In this case, genre. Once again this returns values in a given column. In this case, genre. Once again this returns
a new data set. By convention we use a lower case y a new data set. By convention we use a lower case y
to represent that. So that is our output to represent that. So that is our output
data. Let's inspect that as well. So, data. Let's inspect that as well.所以，
in this data set we only have the predictions or the answers. in this data set we only have the predictions or the answers.
So we have prepared our data, next we want to create a model using an So we have prepared our data, next we want to create a model using an
algorithm. algorithm.
The next step is to build a The next step is to build a
model using a machine learning algorithm. There are so many algorithms out there, each algorithm model using a machine learning algorithm. There are so many algorithms out there, each algorithm
has its pros and cons, in terms of the performance and accuracy. has its pros and cons, in terms of the performance and accuracy.
In this lecture we're going to use a very simple algorithm called decision tree. In this lecture we're going to use a very simple algorithm called decision tree.
Now the good news is we don't have to explicitly Now the good news is we don't have to explicitly
program these algorithms, they're already implemented in a library called side kick program these algorithms, they're already implemented in a library called side kick
learn. So, here on the top, learn. So, here on the top,
from sklearn.tree from sklearn.tree
let's import the decision tree let's import the decision tree
classifier. So sklearn is the package classifier. So sklearn is the package
that comes with sidekick learn library, this is the most popular machine learning library that comes with sidekick learn library, this is the most popular machine learning library
in python. In this package, we have a module called tree. in python. In this package, we have a module called tree.
And in this module we have a class called decision tree classifier. And in this module we have a class called decision tree classifier.
This class implements the decision tree operator, okay? This class implements the decision tree operator, okay?
So, now we need to create a new instance of this class. So, now we need to create a new instance of this class.
So, at the end, let's create So, at the end, let's create
an object called models nd set it to anew instance of decision, an object called models nd set it to anew instance of decision,
tree classifier. Like this. tree classifier.像这样。
So now we have a model, next we need to train it so it learns So now we have a model, next we need to train it so it learns
patterns in the data, and that is pretty easy. You call model, patterns in the data, and that is pretty easy. You call model,
.fit this method takes .fit this method takes
2 data set. The input set and the output set. 2 data set. The input set and the output set.
So they are capital x, y. So they are capital x, y.
Now finally, we need to ask our model to make a prediction, so we can Now finally, we need to ask our model to make a prediction, so we can
ask it, what is the kind of music a 24 year old male likes? Now before ask it, what is the kind of music a 24 year old male likes? Now before
we do that, let's temporarily inspect our initial data set. That is we do that, let's temporarily inspect our initial data set.那是
music data. So, look what music data. So, look what
we got here. As I told you earlier, I've assumed we got here. As I told you earlier, I've assumed
that men between 20 and 25 like hip hop music but that men between 20 and 25 like hip hop music but
here we only have 3 samples for men age here we only have 3 samples for men age
20, 23,and 25. We don't have a sample for 20, 23,and 25. We don't have a sample for
a 21 year old male. So if you ask our model to predict the kind of music a 21 year old male. So if you ask our model to predict the kind of music
that a 21 year old male likes, we expect it to say hip hop. Similarly, that a 21 year old male likes, we expect it to say hip hop.相似地，
I've assumed that women between 20 and 25 like dance music, I've assumed that women between 20 and 25 like dance music,
but we don' have a sample for a 22 year old female. So once again if but we don' have a sample for a 22 year old female. So once again if
you ask our model to predict the kind of music that a 22 year old woman you ask our model to predict the kind of music that a 22 year old woman
likes, we expect it to say dance. likes, we expect it to say dance.
So, with these assumptions let's go ahead and ask our model So, with these assumptions let's go ahead and ask our model
to make predictions. So let's remove to make predictions. So let's remove
the last line, and instead we're going to call model the last line, and instead we're going to call model
.predict. This method takes a .predict. This method takes a
2 dimensional array. So here's the outer array. In this array, each element 2 dimensional array. So here's the outer array. In this array, each element
is an array. So I'm going to pass is an array. So I'm going to pass
another array here, and in this array I'm going to pass a new input set. another array here, and in this array I'm going to pass a new input set.
a 21 year old male. So 21, 1 a 21 year old male. So 21, 1
that is like a new record in this table. Okay? So, that is like a new record in this table.好的？所以，
this is one input set, let's pass another input for a 22 year old this is one input set, let's pass another input for a 22 year old
female. So here's another array, here, female. So here's another array, here,
we add 22 comma 0, so we're asking our model to make 2 predictions we add 22 comma 0, so we're asking our model to make 2 predictions
at the same time. We get the result and store it 同时。 We get the result and store it
in a variable called predictions, and finally in a variable called predictions, and finally
let's inspect that in our notebook. let's inspect that in our notebook.
Run, look what we got, our Run, look what we got, our
model is saying that a 21 year old male likes hip hop, and a 22 year model is saying that a 21 year old male likes hip hop, and a 22 year
old female likes dance music. So our model successfully old female likes dance music. So our model successfully
will make predictions here. But wait a minute, building a model that makes will make predictions here. But wait a minute, building a model that makes
predictions accurately is not always that easy. predictions accurately is not always that easy.
After we build a model we need to measure it's accuracy. After we build a model we need to measure it's accuracy.
And if it's not accurate enough, we should either fine tune it or build a model using a different And if it's not accurate enough, we should either fine tune it or build a model using a different
algorithm. So next lecture I'm going to show you how to measure the accuracy of algorithm. So next lecture I'm going to show you how to measure the accuracy of
a model. a model.
In this lecture I'm going to show you In this lecture I'm going to show you
how to measure the accuracy of your models. Now in order to do so, how to measure the accuracy of your models. Now in order to do so,
first we need to split our data set into two sets. One for training and the other first we need to split our data set into two sets. One for training and the other
for testing, because right now, we are passing the entire data set, for testing, because right now, we are passing the entire data set,
for training the model and we're using 2 samples for for training the model and we're using 2 samples for
making predictions. That is not enough to calculate the making predictions. That is not enough to calculate the
accuracy of a model. A general rule of thumb is to annotate accuracy of a model. A general rule of thumb is to annotate
70-80% of our data to training, and another20-30% 70-80% of our data to training, and another20-30%
for testing, then instead of passing only two samples for for testing, then instead of passing only two samples for
making predictions, we can pass the data set for testing making predictions, we can pass the data set for testing
we'll get the predictions and then compare the predictions with the actual values. we'll get the predictions and then compare the predictions with the actual values.
In the test set. Based on that, we can calculate the In the test set. Based on that, we can calculate the
accuracy. That's really easy, all we have to do is import a couple functions and 准确性。 That's really easy, all we have to do is import a couple functions and
call them in this code. Let me show you. So first on this top call them in this code.让我演示给你看。 So first on this top
from sklearn.model from sklearn.model
underline selection module we import a function called underline selection module we import a function called
train test split. With this function we can easily split our train test split. With this function we can easily split our
data set into two sets. So training and testing, data set into two sets. So training and testing,
now, right here, after we define x and y, now, right here, after we define x and y,
sets, we call this funciton, so train sets, we call this funciton, so train
test split. We give it 3 test split. We give it 3
arguments, x, y, ad a keyword argument that specifies arguments, x, y, ad a keyword argument that specifies
the size of our test dataset. So test the size of our test dataset. So test
_size we set it to 0.2 So we're allocating 20% _size we set it to 0.2 So we're allocating 20%
of our data for testing. Now this functions returns a of our data for testing. Now this functions returns a
tuple, so we can unpack it into 4 variables tuple, so we can unpack it into 4 variables
right here. x_train 就在这儿。 x_train
x_test y_train and y x_test y_train and y
_test. so the first two variables _test. so the first two variables
are the input sets for training and testing. are the input sets for training and testing.
And the other are the output sets for training and testing, And the other are the output sets for training and testing,
now, when training our model, now, when training our model,
instead of passing the entire data set we want to pass only the training data set. instead of passing the entire data set we want to pass only the training data set.
So, x_train, So, x_train,
and y_train. Also, when making predictions and y_train. Also, when making predictions
instead of passing these two samples, we pass instead of passing these two samples, we pass
x_test. So thats the datas set. x_test. So thats the datas set.
That contains input values for testing. Now we get That contains input values for testing. Now we get
the predictions. To calculate the accuracy we simply have to compare these predictions the predictions. To calculate the accuracy we simply have to compare these predictions
with the actual values we have in the output set with the actual values we have in the output set
for testing. That is very easy. First on the top, for testing. That is very easy. First on the top,
we need to import a funciton, so, from sklearn.metric we need to import a funciton, so, from sklearn.metric
.metrics import accuracy .metrics import accuracy
_score. Now at the end. _score. Now at the end.
We call this function, so accuracy score and We call this function, so accuracy score and
give it two arguments y_test. give it two arguments y_test.
Which contains the expected values and Which contains the expected values and
predictions which contains the actual value. predictions which contains the actual value.
Now this functions returns an accuracy score between 0 Now this functions returns an accuracy score between 0
to 1. So we can store it here, to 1. So we can store it here,
and simply display it on the console. So let's go ahead and simply display it on the console. So let's go ahead
and run this program. So, the accuracy score and run this program. So, the accuracy score
is 1 or a 100% but if we run this one more time, we're going to see a different result is 1 or a 100% but if we run this one more time, we're going to see a different result
because every time we split our data set into because every time we split our data set into
training a test sets. We'll have different data sets, because this function training a test sets. We'll have different data sets, because this function
randomly picks data for training and testing. Let me show you, so put the cursor randomly picks data for training and testing. Let me show you, so put the cursor
in the cell, now we can see this is activated in the cell, now we can see this is activated
note that if you click this button here, it will run the cell and also insert a new note that if you click this button here, it will run the cell and also insert a new
cell below this cell. Let me show you. So if I go to this second cell cell below this cell.让我演示给你看。 So if I go to this second cell
press the skip button, now we are in the command mode, press the skip button, now we are in the command mode,
press d twice, okay now it's deleted, if we press d twice, okay now it's deleted, if we
click the run button, we can see, this code was click the run button, we can see, this code was
executed, and now we have a new cell, so if you want to run our cell multiple times executed, and now we have a new cell, so if you want to run our cell multiple times
every time you have to click this and then run every time you have to click this and then run
it, and then click again, and run it, it's a little bit tedious. So I'll show you a shortcut. it, and then click again, and run it, it's a little bit tedious. So I'll show you a shortcut.
Activate the first cell, and press control and enter Activate the first cell, and press control and enter
this runs the current cell without this runs the current cell without
adding a new cell below it. So, back here, lets run it multiple times adding a new cell below it. So, back here, lets run it multiple times
okay, now look the accuracy dropped to 0.75, it's okay, now look the accuracy dropped to 0.75, it's
still good, so the cuuracey scored here, is somewhere still good, so the cuuracey scored here, is somewhere
between 75% to a hundred %. But let me show you something, if I between 75% to a hundred %. But let me show you something, if I
change the test size, from 0.2 to 0. change the test size, from 0.2 to 0.
8, so essentially we're using only 20 percent of our data, 8, so essentially we're using only 20 percent of our data,
for training this model. And you're using the other 80% for training this model. And you're using the other 80%
for testing. Now let's see what happens when we run this cell multiple for testing. Now let's see what happens when we run this cell multiple
times. SO, control and enter, look, the accuracy immediately times. SO, control and enter, look, the accuracy immediately
dropped to 0.4 One more time, now 46% dropped to 0.4 One more time, now 46%
40%, 26% 40%, 26%
it's really, really bad. The reason this is happening is because it's really, really bad. The reason this is happening is because
you are using very little data for training this model. This is one of you are using very little data for training this model. This is one of
the key concepts in machine learning, the more data we give to our model and the cleaner the key concepts in machine learning, the more data we give to our model and the cleaner
the data is, we get the better result, so if you have duplicates, the data is, we get the better result, so if you have duplicates,
irrelevant data, or incomplete values, our irrelevant data, or incomplete values, our
model will learn back patterns in our data. That's why it's really important to clean model will learn back patterns in our data. That's why it's really important to clean
before training our model. Now let's change this back to 0. before training our model. Now let's change this back to 0.
2, run this one more time, okay, now 2, run this one more time, okay, now
the accuracy is 1, 75%, now we drop to 50% the accuracy is 1, 75%, now we drop to 50%
again, the reason this is happening, is because we don't have enough data. again, the reason this is happening, is because we don't have enough data.
Some machine learning problems, require, thousands or even millions Some machine learning problems, require, thousands or even millions
of samples, to train model, the more complex a problem is, of samples, to train model, the more complex a problem is,
the more data we need. For example, here we're only dealing with a table of three the more data we need. For example, here we're only dealing with a table of three
columns, but if you want to build a model to tell if a picture of a cat or a dog or a horse, columns, but if you want to build a model to tell if a picture of a cat or a dog or a horse,
or a lion, we will need millions of pictures, the more animal or a lion, we will need millions of pictures, the more animal
it will support the more pictures we need. In the next lecture, we're going to talk about it will support the more pictures we need. In the next lecture, we're going to talk about
model persistence. model persistence.
So this is a So this is a
very basic implementation of building a training a model to make a prediction. very basic implementation of building a training a model to make a prediction.
Now to simplify things I have removed all the code that you wrote in the last lecture for Now to simplify things I have removed all the code that you wrote in the last lecture for
calculating the accuracy, because in this lecture, you're going to calculating the accuracy, because in this lecture, you're going to
focus on a different topic, So basically we import our data set. focus on a different topic, So basically we import our data set.
Create a model, train it, and then Create a model, train it, and then
ask it to make predictions, now this piece of code that you see here, is not what we ask it to make predictions, now this piece of code that you see here, is not what we
want to run everytime we have a new user or want to run everytime we have a new user or
every time we want to make recommendations to an existing user every time we want to make recommendations to an existing user
sometimes it's really time consuming. In this example, we're dealing with a sometimes it's really time consuming. In this example, we're dealing with a
very small data set that only has 20 records. But in a real application, very small data set that only has 20 records. But in a real application,
you might have a data set with thousands or trillions of examples, training for that you might have a data set with thousands or trillions of examples, training for that
might take seconds or minutes or even hours. might take seconds or minutes or even hours.
And that is wy model persistence is important, once in a while, And that is wy model persistence is important, once in a while,
you build and train our model and then we save it to a file. you build and train our model and then we save it to a file.
Now, next time we want to make predictions, we simply load the model from the file and Now, next time we want to make predictions, we simply load the model from the file and
ask it to make predictions. That model is already trained ask it to make predictions. That model is already trained
you don't need to retrain it, it's like an intelligent person. So let me show you you don't need to retrain it, it's like an intelligent person. So let me show you
how to do this. it's very very easy. On the top, how to do this. it's very very easy. On the top,
from sklearn.externals module from sklearn.externals module
we import joblib. This we import joblib.这
job lib object has methods for saving and loading modules. So, job lib object has methods for saving and loading modules.所以，
after we train our model we'll simply call after we train our model we'll simply call
job lib .dump and give it job lib .dump and give it
two arguments. Our model and the name of the file two arguments. Our model and the name of the file
in which we want to store this model. Let's call this music in which we want to store this model. Let's call this music
-recommender.job lib -recommender.job lib
That's all we have to do. Now temporarily I'm going to comment That's all we have to do. Now temporarily I'm going to comment
out this line, we don't want to make any predictions, we just want to store out this line, we don't want to make any predictions, we just want to store
train model in a file. So let's run this cell with control, train model in a file. So let's run this cell with control,
and slash, okay, look, in the output and slash, okay, look, in the output
we have an array that contains the name of our model file. we have an array that contains the name of our model file.
So this is the return value of the dump method. Now back to our So this is the return value of the dump method. Now back to our
desktop, right next to my notebook we can see our job lib file, this is where our model is stored. desktop, right next to my notebook we can see our job lib file, this is where our model is stored.
It's simply a binary file. Now back to our It's simply a binary file. Now back to our
jupiter notebook. As I told you before in a real application we don't want to jupiter notebook. As I told you before in a real application we don't want to
train model every time. So let's comment out train model every time. So let's comment out
these few lines, on Mac, we can press these few lines, on Mac, we can press
command and slash and on windows control slash. command and slash and on windows control slash.
Okay, these lines are commented out, now this time, instead of dumping Okay, these lines are commented out, now this time, instead of dumping
our model, we're going to load it, so we call the load method, we don't have the model, we simply our model, we're going to load it, so we call the load method, we don't have the model, we simply
pass the name of our model file. This pass the name of our model file.这
returns our trained model. Now with this returns our trained model. Now with this
two lines we can simply make predictions, so, earlier, two lines we can simply make predictions, so, earlier,
we assumed that men between 20-25 like hip hop music. we assumed that men between 20-25 like hip hop music.
let's print predictions and see if our model is behaving let's print predictions and see if our model is behaving
so control so control
so this is how we persist and load models. so this is how we persist and load models.
Earlier in this section, I told you that decision trees are the easiest Earlier in this section, I told you that decision trees are the easiest
to understand. And that's why we started machine learning with decision trees. In this lecture, we're going to to understand. And that's why we started machine learning with decision trees. In this lecture, we're going to
export our model in visual format, so you will see export our model in visual format, so you will see
how this model makes predictions, that is really, really cool. how this model makes predictions, that is really, really cool.
Let me show you. So once again I've simplified this code 让我演示给你看。 So once again I've simplified this code
so we simply import our data set, create so we simply import our data set, create
input and output sets, create a model, and input and output sets, create a model, and
train it, that's all we are doing, now I want you to train it, that's all we are doing, now I want you to
follow along with me, type everything exactly as I show you in this lecture. Don't follow along with me, type everything exactly as I show you in this lecture.别
worry about what everything means we'll come back to it shortly. So on the top, worry about what everything means we'll come back to it shortly. So on the top,
from sklearnimport from sklearnimport
tree, this object has a method for exporting tree, this object has a method for exporting
our decision tree in a graphical format. So after we our decision tree in a graphical format. So after we
train our model, let's call tree train our model, let's call tree
_graph vis. Now here are a few arguments we need _graph vis. Now here are a few arguments we need
to pass. The first argument is our model, to pass. The first argument is our model,
the second is the name oft he output file. So here we're going to use keyword the second is the name oft he output file. So here we're going to use keyword
arguments, because this method takes so many parameters, and we want to selectively pass arguments, because this method takes so many parameters, and we want to selectively pass
keyword arguments without worrying about their order. So, keyword arguments without worrying about their order.所以，
the parameter we're going to set it out_file the parameter we're going to set it out_file
let's set this to music-recommend let's set this to music-recommend
.dot. This is the dot format, which is the .dot. This is the dot format, which is the
graph format, which is a graph description language, you will see that shortly. graph format, which is a graph description language, you will see that shortly.
Now the other parameter you want to set is feature Now the other parameter you want to set is feature
_names. We set this to an array of two strings, _names. We set this to an array of two strings,
age and gender. These are the features age and gender. These are the features
or the columns of our data set. So they are properties or features of or the columns of our data set. So they are properties or features of
our data. Okay? The other parameter our data.好的？ The other parameter
is class names. So class_names is class names. So class_names
we should set this to the list of classes or labels we have we should set this to the list of classes or labels we have
in our output data set, like hip hop, jazz, classical and so on. in our output data set, like hip hop, jazz, classical and so on.
So, this y data set includes all the genre So, this y data set includes all the genre
or all the classes of our data, but they are repeated a few times in this data set. or all the classes of our data, but they are repeated a few times in this data set.
So, here we call y.unit this returns So, here we call y.unit this returns
the unique list of classes, now we should sort this alphabetically. the unique list of classes, now we should sort this alphabetically.
So, we call the sorted function, and pass the So, we call the sorted function, and pass the
result a y.unique. result a y.unique.
The next parameter is labeled, we set The next parameter is labeled, we set
this to a string, all, once again don't worry, this to a string, all, once again don't worry,
about the details of these parameters, we're going to come back to these shortly. So, about the details of these parameters, we're going to come back to these shortly.所以，
set label to all, then round it, set label to all, then round it,
to true, and finally field to true. So, to true, and finally field to true.所以，
so this is the end result, now let's run this sound so this is the end result, now let's run this sound
using control and enter, okay, using control and enter, okay,
here we have a nw file music recommender .. that's a little here we have a nw file music recommender .. that's a little
bit funny. So we want to open this file with vs code. bit funny. So we want to open this file with vs code.
So drag and drop this into a vs code window. So drag and drop this into a vs code window.
Okay, here's a dot format, it's Okay, here's a dot format, it's
a textural language for describing graphs a textural language for describing graphs
Now to visualize this graph we need to install an extension in vs code. Now to visualize this graph we need to install an extension in vs code.
So on the left side, click extensions panel and search So on the left side, click extensions panel and search
for dot, dot. Look at this second extension here. for dot, dot. Look at this second extension here.
graphvis or .language graphvis or .language
by stephon vs. Go ahead and install this extension by stephon vs. Go ahead and install this extension
and then reload vs code. Once you do that, you can visualize and then reload vs code. Once you do that, you can visualize
this dot file. So let me close this tab. this dot file. So let me close this tab.
Alright, look at this ... on the right side. Click this, Alright, look at this ... on the right side. Click this,
you should have a new menu, open preview to the side. So like that you should have a new menu, open preview to the side. So like that
alright, here's the visualization of our decision tree, alright, here's the visualization of our decision tree,
let's close the dot file, there you go. This is exactly let's close the dot file, there you go. This is exactly
how our model makes predictions. So we have this how our model makes predictions. So we have this
binary tree, which means every node can have a maximum of two children. binary tree, which means every node can have a maximum of two children.
On top of each note we have a condition On top of each note we have a condition
if this condition is true we go to the child node on the left side. Otherwise we if this condition is true we go to the child node on the left side. Otherwise we
go to the child node on the right side. So let's see what's happening here, the first condition go to the child node on the right side. So let's see what's happening here, the first condition
is age less then or equal to 30 is age less then or equal to 30
.5. If this condition is false, that means that user is 30 years .5. If this condition is false, that means that user is 30 years
or older, so the genre of the music that their interested in is classical. or older, so the genre of the music that their interested in is classical.
So here we're classifying people based So here we're classifying people based
on their profile. That is the reason we have the word class here, on their profile. That is the reason we have the word class here,
so a user who is 30 years or older, belongs to the class of so a user who is 30 years or older, belongs to the class of
classical. Or people who like classical music. Now what if this condition classical. Or people who like classical music. Now what if this condition
is true. That means that user is younger then is true. That means that user is younger then
30, so, now we check the gender, if it's less then 0.5, 30, so, now we check the gender, if it's less then 0.5,
which basically means it equals to 0, then which basically means it equals to 0, then
we're dealing with a female. So we go to the child node here, we're dealing with a female. So we go to the child node here,
now once again we have another condition, so we are dealing with a female now once again we have another condition, so we are dealing with a female
who is younger than 30. Once again we ned to check their age so who is younger than 30. Once again we ned to check their age so
is the age less then 25.5? If that's the case is the age less then 25.5?如果是这样的话
then that user likes dance music, otherwise they like acoustic music. then that user likes dance music, otherwise they like acoustic music.
So this is a decision tree that our model uses to make predictions So this is a decision tree that our model uses to make predictions
Now if you're wondering why we have these floating point numbers Now if you're wondering why we have these floating point numbers
like 25.5 These are basically the rules like 25.5 These are basically the rules
that our model generates, based on the patterns in our dataset. that our model generates, based on the patterns in our dataset.
As we give our model more data, these rules will change so they are not always the same. As we give our model more data, these rules will change so they are not always the same.
So they are not always the same, also the more columns or the more features So they are not always the same, also the more columns or the more features
we have, our decision tree is going to get more complex. we have, our decision tree is going to get more complex.
We only have two features, age, and gender. Now back to our code We only have two features, age, and gender. Now back to our code
let me quickly explain the meaning of all these parameters, we set field to true let me quickly explain the meaning of all these parameters, we set field to true
so each box or each node is filled with a color. We set so each box or each node is filled with a color.我们设置
rounded to true, so they have rounded corners. We set label to all rounded to true, so they have rounded corners. We set label to all
so every node has labels that we can read. so every node has labels that we can read.
We set class names to the unique list of genres We set class names to the unique list of genres
and that's for displaying the class for each note, right here, and we set and that's for displaying the class for each note, right here, and we set
feature names to age and gender, sow e can see the rules feature names to age and gender, sow e can see the rules
in our notes. So that was a short and in our notes. So that was a short and
sweet introduction to machien learning. Now you can use the materials that you learn in this section sweet introduction to machien learning. Now you can use the materials that you learn in this section
and apply them to solve a different set of problems. Now here's a question for you: and apply them to solve a different set of problems. Now here's a question for you:
What ideas do you have for machine learning? What kind of problems do you want to solve What ideas do you have for machine learning? What kind of problems do you want to solve
with machine learning? Use the comments box below and let me know. I love to with machine learning? Use the comments box below and let me know. I love to
hear about your ideas! Next we're going to use python and a popular framework called hear about your ideas! Next we're going to use python and a popular framework called
django. To build a web application. Are you ready, let's get started django. To build a web application. Are you ready, let's get started
In this turorial, I'm going to show you how to create your first website with python, and A In this turorial, I'm going to show you how to create your first website with python, and A
and a very popular framework called django. So it's spelled with a silent D, and a very popular framework called django. So it's spelled with a silent D,
and is pronounced django. it's a web framework for and is pronounced django. it's a web framework for
perfectionists with deadlines. So if you're a perfectionist and you want to quickly put together perfectionists with deadlines. So if you're a perfectionist and you want to quickly put together
a website that is fast, scaleable and secure, a website that is fast, scaleable and secure,
django is your best friend. And here are the popular websites django is your best friend. And here are the popular websites
built with Django. Like Instagram, Spotify built with Django. Like Instagram, Spotify
YouTube, Washington Post, and so on. Now you might say YouTube, Washington Post, and so on. Now you might say
what is a framework, and why do we need a framework to build a web application or a web site? what is a framework, and why do we need a framework to build a web application or a web site?
Well, the framework is essentially a library of reusable modules Well, the framework is essentially a library of reusable modules
these modules provide functionality for common tasks these modules provide functionality for common tasks
for example, in the case of a web framework like django we have modules to work with http requests for example, in the case of a web framework like django we have modules to work with http requests
url's, sessions, cookies and so on. url's, sessions, cookies and so on.
These are the concerns of pretty much every website or These are the concerns of pretty much every website or
application out there. So all this functionality is baked into django, we don't have to application out there. So all this functionality is baked into django, we don't have to
code it from scratch, that is why we use a framework like django. Now, code it from scratch, that is why we use a framework like django.现在，
django. Now technically a framework is more then a library, django. Now technically a framework is more then a library,
apart from providing these modules it also provides a structure for each application apart from providing these modules it also provides a structure for each application
It tells us what folders or files we should have in our project. So this It tells us what folders or files we should have in our project.所以这
provides a consistency among various django projects. So as you provides a consistency among various django projects. So as you
move from one company to another and work on different projects, you can easily transition from one move from one company to another and work on different projects, you can easily transition from one
project to another, because all these applications follow the same structure project to another, because all these applications follow the same structure
now, with that interaction, let's create our first now, with that interaction, let's create our first
django project. So back to pycharm, close the hello world django project. So back to pycharm, close the hello world
project, and create a new project, create a new project, project, and create a new project, create a new project,
let's call this new project pyshop let's call this new project pyshop
go ahead, alright, now down at the bottom let's go ahead, alright, now down at the bottom let's
open up a terminal window, in this window we're going to open up a terminal window, in this window we're going to
install django. So we use pip to install install django. So we use pip to install
django. But be sure to add two equal signs here followed by django. But be sure to add two equal signs here followed by
2.1 With this we are telling pip that we want to install django version 2.1 With this we are telling pip that we want to install django version
2.1. The reason I'm doing this, is because in the future when you're watching this video, 2.1。 The reason I'm doing this, is because in the future when you're watching this video,
chances are there is a newer version django out there. I chances are there is a newer version django out there.一世
want to make sure that you can easily follow these tutorials, even though what I'm going to show you want to make sure that you can easily follow these tutorials, even though what I'm going to show you
in these tutorials will most likely work with the latest version of django. I just want to in these tutorials will most likely work with the latest version of django. I just want to
be on the safe side. So let's go ahead be on the safe side. So let's go ahead
alright, django is installed, alright, django is installed,
next we need to create a django project, so here press control and L next we need to create a django project, so here press control and L
this cleans up our terminal window, you don't have to do it, but it's just this cleans up our terminal window, you don't have to do it, but it's just
easier to see. To create a django project, we need to execute this command, django, easier to see. To create a django project, we need to execute this command, django,
-admin space -admin space
start project space, you're going to call this start project space, you're going to call this
project pyshop space period. project pyshop space period.
So when we install django, django brings a So when we install django, django brings a
command line utility called django admin so this is a utility or program command line utility called django admin so this is a utility or program
that we can execute form the command line or terminal, right here. that we can execute form the command line or terminal, right here.
Now, this program takes various arguments, in this case Now, this program takes various arguments, in this case
we want to use this argument start project, with this we're going to create we want to use this argument start project, with this we're going to create
a project called pushup in the current folder. a project called pushup in the current folder.
So this period is imported here, that means the current folder, if So this period is imported here, that means the current folder, if
you don't add this period, this utility is going to create an extra folder and that you don't add this period, this utility is going to create an extra folder and that
looks a little bit repetitive, so let's go ahead with this, looks a little bit repetitive, so let's go ahead with this,
alright, now, back to the project panel, if you expand py alright, now, back to the project panel, if you expand py
shop we can see that this is our project that we created in pycharm shop we can see that this is our project that we created in pycharm
and in this folder we have these files. and in this folder we have these files.
So, init.py, you have seen this before, that means So, init.py, you have seen this before, that means
this folder is package, so we can import various modules, this folder is package, so we can import various modules,
of this package into other modules, and in this module, of this package into other modules, and in this module,
we define various settings for our application, you're going to see this later in we define various settings for our application, you're going to see this later in
this course. You also have this url's module, and with this module this course. You also have this url's module, and with this module
we define what should the user see when they see slash we define what should the user see when they see slash
about/contact/products/shopping cart about/contact/products/shopping cart
again, we're going to work with this only. And finally we have this module, again, we're going to work with this only. And finally we have this module,
that wsgi, that is short for web server gateway that wsgi, that is short for web server gateway
interface. The purpose of this module is to provide a standard interface interface. The purpose of this module is to provide a standard interface
between applications built with django and web servers. This is between applications built with django and web servers.这是
an advanced topic, so for now, don't worry about it. Now, outside of this folder, an advanced topic, so for now, don't worry about it. Now, outside of this folder,
of this folder you also have this new folder in our project of this folder you also have this new folder in our project
manage.py. As the name implies, we use this to manage manage.py. As the name implies, we use this to manage
this django project. With this we can start our web server, this django project. With this we can start our web server,
we can work with our data base, again, we're going to work with this soon, we can work with our data base, again, we're going to work with this soon,
let's open up the terminal window one more time, now, let's open up the terminal window one more time, now,
type out this command, python if you're on windows or python type out this command, python if you're on windows or python
3 if you're on Mac, because as I told you at the beginning of the course, Mac by 3 if you're on Mac, because as I told you at the beginning of the course, Mac by
default comes with an installation of python, that is python 2. But that is default comes with an installation of python, that is python 2. But that is
this course is python 3. So python 3 space manage this course is python 3. So python 3 space manage
.py space run .py space run
server. What is going on here? So with python interpreter 服务器。这里发生了什么？ So with python interpreter
we are running this program manage.py and passing run server we are running this program manage.py and passing run server
as an argument. This manage.py is essentially the same program as an argument. This manage.py is essentially the same program
that we worked with here, django admin. that we worked with here, django admin.
But we use django admin before creating a django project, now we have a django project, so now But we use django admin before creating a django project, now we have a django project, so now
in this project we work with manage.py this in this project we work with manage.py this
is a module that contains some python code, so we use this module to manage is a module that contains some python code, so we use this module to manage
our django project. So let's go ahead and our django project. So let's go ahead and