你究竟能用Python作什麼?

中英文模式閱讀 中文模式閱讀 英文模式閱讀html

What exactly can you do with Python? Here are Python's 3 main applications.前端

你究竟能用Python作什麼?這是Python的3個主要應用程序。python

If you're thinking of learning Python --- or if you recently started learning it --- you may be asking yourself:
若是您正在考慮學習Python ---或者若是您最近開始學習它 - 您可能會問本身:web

"What exactly can I use Python for?"

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有三個主要的流行應用程序:數據庫

  • Web Development
  • Data Science --- including machine learning, data analysis, and data visualization
  • Scripting

Let's talk about each of them in turn.
讓咱們依次談談它們中的每個。django

Web Development

Web frameworks that are based on Python like
基於Python的Web框架 Django and
and Flask have recently become very popular for web development.
最近變得很是流行的Web開發。flask

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中建立服務器端代碼(後端代碼)。這是在您的服務器上運行的代碼,而不是用戶的設備和瀏覽器(前端代碼)。若是您不熟悉後端代碼和前端代碼之間的區別,請參閱下面的腳註。小程序

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文件。後端

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 Web框架。若是你剛入門,我建議你使用其中一個。

What's the difference between Django and Flask?

There's an
There's an excellent article about this topic by Gareth Dwyer, so let me quote it here:
關於Gareth Dwyer的這個話題,讓我在這裏引用它:

<begin quote>

Main contrasts:
Main contrasts:

  • Flask provides simplicity, flexibility and fine-grained control. It is unopinionated (it lets you decide how you want to implement things).
  • Django provides an all-inclusive experience: you get an admin panel, database interfaces, an ORM [object-relational mapping], and directory structure for your apps and projects out of the box.

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).
  • 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.

</end quote>

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 for Beginners的書。你能夠找到它here.
.

You can also find the free sample chapters of that book
您還能夠找到該書的免費樣本章節here.
.

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.
你能夠給機器學習算法給1000張狗的照片和1000張桌子的照片。而後,它將學習狗和桌子之間的區別。當你給它一張狗或桌子的新圖片時,它將可以識別它是哪個。

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)
  • 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 for machine learning

There are popular machine learning libraries and frameworks for Python.
有流行的機器學習庫和Python框架。

Two of the most popular ones are
兩個最受歡迎的是 scikit-learn and
and TensorFlow .
.

  • scikit-learn comes with some of the more popular machine learning algorithms built-in. I mentioned some of them above.
  • TensorFlow is more of a low-level library that allows you to build custom machine learning algorithms.

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
要學習機器學習基礎知識,我建議Stanford's or
or Caltech's 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
而後,我會練習你從其中一門課程中學到的東西Kaggle. 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.
而後,做爲數據分析師,您能夠繪製這樣的條形圖。


Bar Chart 1 --- generated with Python
條形圖1 ---用Python生成

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.
要了解哪些解釋是正確的,您可能會繪製另外一個這樣的圖表。


Line Chart 1 --- generated with Python
折線圖1 ---用Python生成


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?
另外一方面,若是你看到像這樣的圖表怎麼辦?


Line Chart 2 --- also generated with Python
折線圖2 ---也是用Python生成的

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.
我在谷歌和微軟工做時所作的數據分析工做與這個例子很是類似 - 只是更復雜。我實際上在谷歌使用Python進行這種分析,而我在微軟使用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(在谷歌)或JavaScript和D3.js(在微軟)來可視化和分析這些數據。

Data analysis / visualization with Python

One of the most popular libraries for data visualization is
最受歡迎的數據可視化庫之一是Matplotlib.
.

It's a good library to get started with because:
這是一個很好的庫,由於:

  • It's easy to get started with
  • Some other libraries such as seaborn is based on it. So, learning Matplotlib will help you learn these other libraries later on.

How should I learn data analysis / visualization with 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視頻:


Intro to Data Analysis / Visualization with Python and Matplotlib
使用Python和Matplotlib介紹數據分析/可視化

I also ended up making a
我也最終作了一個full course on this topic on Pluralsight, 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.
相反,我建議開始使用Unity與C#,這是最受歡迎的遊戲引擎之一。它容許您爲許多平臺構建遊戲,包括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
相反,它彷佛像語言Java, C#, and C++ are more popular for this.
對此更受歡迎。

Recently, some companies have started using JavaScript to create Desktop applications, too.
最近,一些公司也開始使用JavaScript來建立桌面應用程序。

For example, Slack's desktop app was built with something called Electron. 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 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
  • Java for Android
  • JavaScript for web browsers

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並非編寫後端/服務器端代碼的惟一好選擇。還有許多其餘流行的選擇,包括Node.js,它基於JavaScript。

Anyway, thanks a lot for reading my article!

中英文模式閱讀
中文模式閱讀
英文模式閱讀


查看英文原文

查看更多文章

公衆號:銀河系1號

聯繫郵箱:public@space-explore.com

(未經贊成,請勿轉載)

相關文章
相關標籤/搜索