博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python能写应用程序_Python到底能做什么? 这是Python的3个主要应用程序。
阅读量:2527 次
发布时间:2019-05-11

本文共 17493 字,大约阅读时间需要 58 分钟。

python能写应用程序

by YK Sugi

由YK Sugi

If you’re thinking of learning Python — or if you recently started learning it — you may be asking yourself:

如果您正在考虑学习Python(或者您最近开始学习它),那么您可能会问自己:

“What exactly can I use Python for?”

“我到底可以使用Python做什么?”

Well that’s a tricky question to answer, because there are so many applications for Python.

嗯,这是一个棘手的问题,因为Python的应用程序太多了。

But over time, I have observed that there are 3 main popular applications for Python:

但是随着时间的推移,我发现Python有3种主要的流行应用程序:

  • Web Development

    Web开发
  • Data Science — including machine learning, data analysis, and data visualization

    数据科学-包括机器学习,数据分析和数据可视化
  • Scripting

    脚本编写

Let’s talk about each of them in turn.

让我们依次讨论它们。

Web开发 (Web Development)

Web frameworks that are based on Python like Django and Flask have recently become very popular for web development.

最近,基于Python的Web框架(如DjangoFlask)在Web开发中非常流行。

These web frameworks help you create server-side code (backend code) in Python. That’s the code that runs on your server, as opposed to on users’ devices and browsers (front-end code). If you’re not familiar with the difference between backend code and front-end code, please see my footnote below.

这些Web框架可帮助您使用Python创建服务器端代码(后端代码)。 那是在服务器上运行的代码,而不是在用户的设备和浏览器上运行的代码(前端代码)。 如果您不熟悉后端代码和前端代码之间的区别,请参见下面的脚注。

但是,等等,为什么我需要一个Web框架? (But wait, why do I need a web framework?)

That’s because a web framework makes it easier to build common backend logic. This includes mapping different URLs to chunks of Python code, dealing with databases, and generating HTML files users see on their browsers.

这是因为Web框架使构建通用后端逻辑更加容易。 这包括将不同的URL映射到Python代码块,处理数据库以及生成用户在浏览器中看到HTML文件。

我应该使用哪个Python Web框架? (Which Python web framework should I use?)

Django and Flask are two of the most popular Python web frameworks. I’d recommend using one of them if you’re just getting started.

Django和Flask是两个最受欢迎的Python网络框架。 如果您刚刚入门,建议您使用其中之一。

Django和Flask有什么区别? (What’s the difference between Django and Flask?)

There’s an about this topic by Gareth Dwyer, so let me quote it here:

Gareth Dwyer 有关该主题的 ,因此在这里引用一下:

<begin quote>

<开始 >

Main contrasts:

主要对比:

  • Flask provides simplicity, flexibility and fine-grained control. It is unopinionated (it lets you decide how you want to implement things).

    Flask提供了简单,灵活和细粒度的控制。 它是不受限制的(它使您可以决定如何实现事物)。
  • Django provides an all-inclusive experience: you get an admin panel, database interfaces, an , and directory structure for your apps and projects out of the box.

    Django提供了全方位的体验:您可以立即获得管理面板,数据库界面, 以及应用程序和项目的目录结构。

You should probably choose:

您可能应该选择:

  • Flask, if you’re focused on the experience and learning opportunities, or if you want more control about which components to use (such as what databases you want to use and how you want to interact with them).

    Flask,如果您专注于体验和学习机会,或者想要更多地控制要使用哪些组件(例如,要使用哪些数据库以及如何与之交互)。
  • Django, if you’re focused on the final product. Especially if you’re working on a straight-forward application such as a news site, an e-store, or blog, and you want there to always be a single, obvious way of doing things.

    Django,如果您专注于最终产品。 尤其是如果您正在开发简单的应用程序(例如新闻站点,电子商店或博客),并且希望始终有一种单一且显而易见的处理方式。

</end quote>

</ end quo >

In other words, If you’re a beginner, Flask is probably a better choice because it has fewer components to deal with. Also, Flask is a better choice if you want more customization.

换句话说,如果您是初学者,则Flask可能是一个更好的选择,因为它需要处理的组件更少。 另外,如果您想进行更多定制,则Flask是更好的选择。

On the other hand, if you’re looking to build something straight-forward, Django will probably let you get there faster.

另一方面,如果您想直接构建一些东西,Django可能会让您更快地到达那里。

Now, if you’re looking to learn Django, I recommend the book called Django for Beginners. You can find it .

现在,如果您想学习Django,我推荐一本名为Django的新手书籍。 你可以在找到它。

You can also find the free sample chapters of that book .

您还可以在找到该书的免费示例章节。

Okay, let’s go to the next topic!

好的,让我们转到下一个主题!

数据科学-包括机器学习,数据分析和数据可视化 (Data Science — including machine learning, data analysis, and data visualization)

首先,让我们来回顾一下机器学习 (First of all, let’s review what machine learning is.)

I think the best way to explain what machine learning is would be to give you a simple example.

我认为解释什么是机器学习的最好方法是给您一个简单的例子。

Let’s say you want to develop a program that automatically detects what’s in a picture.

假设您要开发一个程序来自动检测图片中的内容。

So, given this picture below (Picture 1), you want your program to recognize that it’s a dog.

因此,鉴于下面的图片(图片1),您希望程序识别出它是狗。

Given this other one below (Picture 2), you want your program to recognize that it’s a table.

鉴于下面的其他内容(图2),您希望程序识别出它是一个表。

You might say, well, I can just write some code to do that. For example, maybe if there are a lot of light brown pixels in the picture, then we can say that it’s a dog.

您可能会说,嗯,我可以编写一些代码来做到这一点。 例如,如果图片中有很多浅棕色像素,那么我们可以说它是一只狗。

Or maybe, you can figure out how to detect edges in a picture. Then, you might say, if there are many straight edges, then it’s a table.

或者,您可以弄清楚如何检测图片的边缘。 然后,您可能会说,如果有很多直边,那就是一张桌子。

However, this kind of approach gets tricky pretty quickly. What if there’s a white dog in the picture with no brown hair? What if the picture shows only the round parts of the table?

但是,这种方法很快就会变得棘手。 如果图片中有只白狗没有棕色头发怎么办? 如果图片仅显示桌子的圆形部分怎么办?

This is where machine learning comes in.

这就是机器学习的用武之地。

Machine learning typically implements an algorithm that automatically detects a pattern in the given input.

机器学习通常实现一种算法,该算法可自动检测给定输入中的模式。

You can give, say, 1,000 pictures of a dog and 1,000 pictures of a table to a machine learning algorithm. Then, it will learn the difference between a dog and a table. When you give it a new picture of either a dog or a table, it will be able to recognize which one it is.

例如,您可以将1,000张狗的照片和1,000张桌子的照片提供给机器学习算法。 然后,它将了解狗和桌子之间的区别。 当给它一张新的狗或桌子的图片时,它将能够识别出它是哪只。

I think this is somewhat similar to how a baby learns new things. How does a baby learn that one thing looks like a dog and another a table? Probably from a bunch of examples.

我认为这有点类似于婴儿学习新事物的方式。 婴儿如何学会一件事看起来像狗,而另一件事看起来像桌子? 大概有很多例子。

You probably don’t explicitly tell a baby, “If something is furry and has light brown hair, then it’s probably a dog.”

您可能没有明确地告诉婴儿:“如果东西很毛茸茸,头发浅棕色,那可能就是狗。”

You would probably just say, “That’s a dog. This is also a dog. And this one is a table. That one is also a table.”

您可能会说:“那是一条狗。 这也是一条狗。 这是一张桌子。 那也是一张桌子。”

Machine learning algorithms work much the same way.

机器学习算法的工作方式大致相同。

You can apply the same idea to:

您可以将相同的想法应用于:

  • recommendation systems (think YouTube, Amazon, and Netflix)

    推荐系统(例如YouTube,Amazon和Netflix)
  • face recognition

    人脸识别
  • voice recognition

    语音识别

among other applications.

在其他应用程序中。

Popular machine learning algorithms you might have heard about include:

您可能听说过的流行机器学习算法包括:

  • Neural networks

    神经网络
  • Deep learning

    深度学习
  • Support vector machines

    支持向量机
  • Random forest

    随机森林

You can use any of the above algorithms to solve the picture-labeling problem I explained earlier.

您可以使用上述任何一种算法来解决我之前解释的图片标记问题。

适用于机器学习的Python (Python for machine learning)

There are popular machine learning libraries and frameworks for Python.

有流行的Python机器学习库和框架。

Two of the most popular ones are scikit-learn and TensorFlow.

最受欢迎的两个是scikit-learnTensorFlow

  • scikit-learn comes with some of the more popular machine learning algorithms built-in. I mentioned some of them above.

    scikit-learn内置了一些更流行的机器学习算法。 我在上面提到了其中一些。
  • TensorFlow is more of a low-level library that allows you to build custom machine learning algorithms.

    TensorFlow更像是一个低级库,可让您构建自定义机器学习算法。

If you’re just getting started with a machine learning project, I would recommend that you first start with scikit-learn. If you start running into efficiency issues, then I would start looking into TensorFlow.

如果您刚刚开始学习机器学习项目,建议您先从scikit-learn开始。 如果您开始遇到效率问题,那么我将开始研究TensorFlow。

我应该如何学习机器学习? (How should I learn machine learning?)

To learn machine learning fundamentals, I would recommend either or machine learning course.

要学习机器学习基础知识,我会推荐或机器学习课程。

Please note that you need basic knowledge of calculus and linear algebra to understand some of the materials in those courses.

请注意,您需要微积分和线性代数的基本知识才能理解这些课程中的某些材料。

Then, I would practice what you’ve learned from one of those courses with . It’s a website where people compete to build the best machine learning algorithm for a given problem. They have nice tutorials for beginners, too.

然后,我将使用练习您从其中一门课程中学到的知识。 在这个网站上,人们可以竞争为给定的问题构建最佳的机器学习算法。 他们也为初学者提供了不错的教程。

数据分析和数据可视化如何? (What about data analysis and data visualization?)

To help you understand what these might look like, let me give you a simple example here.

为了帮助您理解这些内容,让我在这里给您一个简单的例子。

Let’s say you’re working for a company that sells some products online.

假设您在一家在线销售某些产品的公司工作。

Then, as a data analyst, you might draw a bar graph like this.

然后,作为数据分析员,您可以绘制这样的条形图。

From this graph, we can tell that men bought over 400 units of this product and women bought about 350 units of this product this particular Sunday.

从该图可以看出,在这个特定的星期日,男性购买了400多种产品,女性购买了350多种产品。

As a data analyst, you might come up with a few possible explanations for this difference.

作为数据分析师,您可能会针对这种差异提出一些可能的解释。

One obvious possible explanation is that this product is more popular with men than with women. Another possible explanation might be that the sample size is too small and this difference was caused just by chance. And yet another possible explanation might be that men tend to buy this product more only on Sunday for some reason.

一个明显的可能解释是,与男性相比,该产品在男性中更受欢迎。 另一个可能的解释可能是样本数量太小,而这种差异是偶然造成的。 还有另一种可能的解释是,由于某种原因,男人倾向于只在星期日购买更多该产品。

To understand which of these explanations is correct, you might draw another graph like this one.

为了理解这些解释中的哪一个是正确的,您可以绘制另一张这样的图表。

Instead of showing the data for Sunday only, we’re looking at the data for a full week. As you can see, from this graph, we can see that this difference is pretty consistent over different days.

我们不仅仅显示星期日的数据,而是查看整周的数据。 如您所见,从该图可以看出,这一差异在不同的日子是相当一致的。

From this little analysis, you might conclude that the most convincing explanation for this difference is that this product is simply more popular with men than with women.

从这个小小的分析中,您可能会得出结论,对此差异最有说服力的解释是,与男性相比,该产品在男性中更受欢迎。

On the other hand, what if you see a graph like this one instead?

另一方面,如果您看到类似这样的图怎么办?

Then, what explains the difference on Sunday?

那么,什么解释星期天的不同呢?

You might say, perhaps men tend to buy more of this product only on Sunday for some reason. Or, perhaps it was just a coincidence that men bought more of it on Sunday.

您可能会说,也许出于某种原因,男人往往只会在星期日购买更多这种产品。 或者,也许是偶然的,人们在星期天买了更多。

So, this is a simplified example of what data analysis might look like in the real world.

因此,这是数据分析在现实世界中可能看起来像的简化示例。

The data analysis work I did when I was working at Google and Microsoft was very similar to this example — only more complex. I actually used Python at Google for this kind of analysis, while I used JavaScript at Microsoft.

我在Google和Microsoft工作时所做的数据分析工作与该示例非常相似,只是更为复杂。 实际上,我在Google上使用Python进行了这种分析,而在Microsoft上使用了JavaScript。

I used SQL at both of those companies to pull data from our databases. Then, I would use either Python and Matplotlib (at Google) or JavaScript and D3.js (at Microsoft) to visualize and analyze this data.

我在两家公司都使用SQL从数据库中提取数据。 然后,我将使用Python和Matplotlib(在Google)或JavaScript和D3.js(在Microsoft)来可视化和分析这些数据。

使用Python进行数据分析/可视化 (Data analysis / visualization with Python)

One of the most popular libraries for data visualization is .

是用于数据可视化的最受欢迎的库 。

It’s a good library to get started with because:

这是一个很好的入门库,因为:

  • It’s easy to get started with

    很容易上手
  • Some other libraries such as is based on it. So, learning Matplotlib will help you learn these other libraries later on.

    诸如类的其他一些库也为基础。 因此,学习Matplotlib将帮助您稍后学习这些其他库。

How should I learn data analysis / visualization with Python?

如何使用Python学习数据分析/可视化?

You should first learn the fundamentals of data analysis and visualization. When I looked for good resources for this online, I couldn’t find any. So, I ended up making a YouTube video on this topic:

您应该首先学习数据分析和可视化的基础知识。 当我在网上寻找好的资源时,找不到任何资源。 因此,我最终制作了有关此主题的YouTube视频:

I also ended up making a , which you can take for free by signing up to their 10-day free trial.

我还最终上完成了的 ,您可以通过注册10天免费试用版来免费学习。

I’d recommend both of them.

我建议他们两个。

After learning the fundamentals of data analysis and visualization, learning fundamentals of statistics from websites like Coursera and Khan Academy will be helpful, as well.

在学习了数据分析和可视化的基础知识之后,从Coursera和Khan Academy等网站学习统计基础知识也将有所帮助。

脚本编写 (Scripting)

什么是脚本? (What is scripting?)

Scripting usually refers to writing small programs that are designed to automate simple tasks.

脚本编写通常是指编写旨在自动化简单任务的小型程序。

So, let me give you an example from my personal experience here.

所以,让我在这里给我一个例子。

I used to work at a small startup in Japan where we had an email support system. It was a system for us to respond to questions customers sent us via email.

我曾经在日本的一家小型初创公司工作,那里有一个电子邮件支持系统。 这是我们用来回应客户通过电子邮件发送给我们的问题的系统。

When I was working there, I had the task of counting the numbers of emails containing certain keywords so we could analyze the emails we received.

在那儿工作时,我的任务是计算包含某些关键字的电子邮件的数量,以便我们可以分析收到的电子邮件。

We could have done it manually, but instead, I wrote a simple program / simple script to automate this task.

我们本可以手动完成的,但我写了一个简单的程序/简单的脚本来自动完成此任务。

Actually, we used Ruby for this back then, but Python is also a good language for this kind of task. Python is suited for this type of task mainly because it has relatively simple syntax and is easy to write. It’s also quick to write something small with it and test it.

实际上,那时我们使用Ruby来完成此工作,但是Python还是执行此类任务的好语言。 Python之所以适合此类任务,主要是因为它具有相对简单的语法并且易于编写。 用它编写一些小的东西并对其进行测试也很快。

嵌入式应用程序呢? (What about embedded applications?)

I’m not an expert on embedded applications, but I know that Python works with Rasberry Pi. It seems like a popular application among hardware hobbyists.

我不是嵌入式应用程序专家,但是我知道Python可与Rasberry Pi一起使用。 它似乎在硬件爱好者中很流行。

那游戏呢? (What about gaming?)

You could use the library called PyGame to develop games, but it’s not the most popular gaming engine out there. You could use it to build a hobby project, but I personally wouldn’t choose it if you’re serious about game development.

您可以使用名为PyGame的库来开发游戏,但是它不是那里最受欢迎的游戏引擎。 您可以使用它来构建一个爱好项目,但是如果您对游戏开发很认真,我个人不会选择它。

Rather, I would recommend getting started with Unity with C#, which is one of the most popular gaming engines. It allows you to build a game for many platforms, including Mac, Windows, iOS, and Android.

相反,我建议您使用C#(这是最受欢迎的游戏引擎之一)入门Unity。 它允许您为许多平台(包括Mac,Windows,iOS和Android)构建游戏。

桌面应用程序呢? (What about desktop applications?)

You could make one with Python using Tkinter, but it doesn’t seem like the most popular choice either.

您可以使用Tkinter用Python制作一个,但这似乎也不是最受欢迎的选择。

Instead, it seems like languages like are more popular for this.

相反,似乎对此更受欢迎。

Recently, some companies have started using JavaScript to create Desktop applications, too.

最近,一些公司也开始使用JavaScript创建桌面应用程序。

. It allows you to build desktop applications with JavaScript.

。 它允许您使用JavaScript构建桌面应用程序。

Personally, if I was building a desktop application, I would go with a JavaScript option. It allows you to reuse some of the code from a web version if you have it.

就个人而言,如果要构建桌面应用程序,则可以使用JavaScript选项。 如果有的话,它允许您重用Web版本中的某些代码。

However, I’m not an expert on desktop applications either, so please let me know in a comment if you disagree or agree with me on this.

但是,我也不是桌面应用程序方面的专家,因此如果您不同意或同意我,请在评论中告知我。

Python 3还是Python 2? (Python 3 or Python 2?)

I would recommend Python 3 since it’s more modern and it’s a more popular option at this point.

我建议使用Python 3,因为它更现代,并且是目前比较流行的选择。

脚注:有关后端代码与前端代码的注释(以防您不熟悉这些术语): (Footnote: A note about back-end code vs front-end code (just in case you are not familiar with the terms):)

Let’s say you want to make something like Instagram.

假设您想制作类似Instagram产品。

Then, you’d need to create front-end code for each type of device you want to support.

然后,您需要为要支持的每种类型的设备创建前端代码。

You might use, for example:

您可能使用例如:

  • Swift for iOS

    适用于iOS的Swift
  • Java for Android

    适用于Android的Java
  • JavaScript for web browsers

    Web浏览器JavaScript

Each set of code will run on each type of device / browser. This will be the set of code that determines what the layout of the app will be like, what the buttons should look like when you click them, etc.

每组代码将在每种类型的设备/浏览器上运行。 这是一组代码,用于确定应用程序的布局,单击时的按钮外观等。

However, you will still need the ability to store users’ info and photos. You will want to store them on your server and not just on your users’ devices so each user’s followers can view his/her photos.

但是,您仍然需要能够存储用户的信息和照片。 您将希望将它们存储在服务器上,而不仅仅是存储在用户的设备上,以便每个用户的关注者都可以查看他/她的照片。

This is where the backend code / server-side code comes in. You’ll need to write some backend code to do things like:

这是后端代码/服务器端代码的来源。您需要编写一些后端代码来执行以下操作:

  • Keep track of who’s following who

    跟踪谁在关注谁
  • Compress photos so they don’t take up so much storage space

    压缩照片,以免占用太多存储空间
  • Recommend photos and new accounts to each user in the discovery feature

    发现功能中将照片和新帐户推荐给每个用户

So, this is the difference between backend code and front-end code.

因此,这就是后端代码和前端代码之间的区别。

By the way, Python is not the only good choice for writing backend / server-side code. There are many other popular choices, including Node.js, which is based on JavaScript.

顺便说一句,Python并不是编写后端/服务器端代码的唯一好选择。 还有许多其他流行的选择,包括基于JavaScript的Node.js。

喜欢这篇文章吗? 然后,您可能也喜欢我的YouTube频道。 (Liked this article? Then, you might also like my YouTube channel.)

I have a programming education YouTube channel called with 440,000+ subscribers, where I produce more content like this article.

我有一个名为的编程教育YouTube频道,有440,000多名订阅者,在这里我可以产生更多类似本文的内容。

For example, you might like these videos:

例如,您可能喜欢这些视频:

无论如何,非常感谢您阅读我的文章! (Anyway, thanks a lot for reading my article!)

翻译自:

python能写应用程序

转载地址:http://nikzd.baihongyu.com/

你可能感兴趣的文章
面向对象编程思想概览(四)多线程
查看>>
二十三种设计模式及其python实现
查看>>
Math类、Random类、System类、BigInteger类、BigDecimal类、Date类、SimpleDateFormat、Calendar类...
查看>>
【设计模式】 访问者模式
查看>>
关于FFMPEG 中I帧、B帧、P帧、PTS、DTS
查看>>
request和response的知识
查看>>
bootstrap 表单类
查看>>
20165332第四周学习总结
查看>>
Codeforces Round #200 (Div. 1)D. Water Tree dfs序
查看>>
linux安全设置
查看>>
Myflight航班查询系统
查看>>
团队-团队编程项目爬取豆瓣电影top250-代码设计规范
查看>>
表头固定内容可滚动表格的3种实现方法
查看>>
想对你说
查看>>
day5 面向对象
查看>>
{算法}Young司机带你轻松KMP
查看>>
不同方法获得视差图比较
查看>>
jQuery笔记(二)
查看>>
Velocity模版进行shiro验证
查看>>
新生舞会
查看>>