Placeholder Image

字幕列表 影片播放

  • Hi, my name is Mosh, and I'm going to be your instructor in this Python course.

  • In this course, you're going to learn everything you need to get started programming in Python.

  • Python is one of the most popular programming languages, and every day people use it to do

  • cool things like automation, they use it in AI, as well as

  • building applications and websites like Instagram and Dropbox. So if you're looking

  • for a job, Python is for you. In this course I'm going to teach you everything

  • you need to get started with Python. We're going to talk about all the core concepts

  • in Python, and then we're going to build three Python projects together.

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

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

  • 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

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

  • You will write a Python program that will process thousands of spreadsheets

  • in under a second. I've designed this Python course for anyone who wants to learn

  • Python. If you're a beginner, don't worry, I will hold your hand through this entire course.

  • You're not too old or too young, and Python is super easy to learn. You can write your first

  • Python program in literally seconds. Plus I'm going to give you plenty

  • of exercises to help you build your confidence writing cool Python programs.

  • My name is Mosh, I'm a software engineer with two decades of experience

  • and I've taught over 3 million people how to code. I'm super excited to be teaching you

  • Python in this course. So I hope you stick around and learn this beautiful

  • 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,

  • is open up your browser and head over to Python

  • .org. On this page click on downloads,

  • here you can see the latest version of Python currently, at the time of recording this video

  • the latest version is 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

  • will apply to the latest version of Python as well. So let's go ahead

  • and download Python 3, alright now,

  • look at your downloads folder, here, we should have Python 3 installer

  • simply double click that, if you're on Windows

  • you're going to see this check box here, add Python to

  • python, this is really important, make sure to tick this box, otherwise you're not going to be able to

  • follow this tutorial. If you're on a Mac,

  • you're going to see an installer like this, with this setup wizard we're going to install 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.

  • 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

  • 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

  • for writing Python code. You can get it from jetbrains.com

  • /pycharm. Now more accurately pycharm

  • is considered an IDE, which is short for integrated development

  • 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

  • download page, you can see two versions of PyCharm, one is the professional addition

  • 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

  • so double click this, now if you're

  • in Windows you're going to see an installation wizard, simply click next, next, next

  • until you install pycharm. If you're on Mac you need to drag and drop this icon

  • 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

  • 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

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

  • So here's the main page of PyCharm every time you open

  • it, click on create new project,

  • this is the location for our project, let's call our project Hello

  • World. Now before click and create, expand

  • this item here, make sure that base interpreter is set to Python

  • 3. Python interpreter is basically a program

  • that knows how to execute Python code, it will know how to interpret

  • or translate Python instructions into instructions a computer can understand.

  • Now, Mac computers, by default come with an older

  • installation of Python, that's Python 2, it's considered legacy

  • 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

  • from this list, select 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

  • Python file, call this file app.py.

  • So by convention, all Python files should have this

  • py extension. Alright, let's go ahead,

  • now let's collapse this project panel by clicking here and write our

  • first python program. Simply type print, pr

  • int, all in lowercase, open and close parenthesis,

  • 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

  • here, so this is your first Python programming. With these piece of code

  • 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

  • R. On Windows it's different. So let's do that, now

  • 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

  • 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

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

  • 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

  • about a few programming terms. So press enter, and

  • on line 2 write another print statement, so print, open and close

  • 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

  • 4 hyphens. So this is the body.

  • 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,

  • 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

  • from the top. So earlier I told you about Python interpreter

  • that is the program that knows how to translate or interpret

  • our Python code into instructions that a computer can understand.

  • So when we run this program by clicking this program here,

  • python interpreter starts executing or running our program

  • line by line from the top. So first it executes line 1,

  • then, moves onto line 2, and so on. So this is how 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,

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

  • Now here, we're multiplying the string by

  • number 10. So this is the multiplication operator, just like the multiplication

  • 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

  • program one more time, there you go. So we have 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

  • tries to execute line 4, first it will evaluate

  • the code that we put in between parenthesis, so we could evaluate our expressions

  • Our expression will produce 10 asterisks and then

  • 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

  • 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

  • consistently, after about 3 months you should be able to write

  • basic python programs, but quite honestly, that doesn't get you a job.

  • 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

  • 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

  • Python, you should also learn about html, some css, some

  • JavaScript and Django which is a popular Python framework

  • for building web applications. Learning all these things would take you another

  • 6 months, so in total you need 9-12 months to become

  • 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

  • as you do more Python projects, your resume starts to build and

  • you can ask for $100,000 a year, or 120,000 dollars

  • 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

  • to make a commitment and spend 2 hours every day practicing

  • python. And use the comment box below and let me know why you are learning

  • Python, what do you want to do with it? What's your dream job? I would love to hear your story.

  • In this Python tutorial, you're going to learn about variables, which are one of the most fundamental

  • concepts in programming, they're not specific to Python, they exist

  • 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

  • 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

  • price label in that memory location. As a metahor

  • imagine we have a box. In that box, we have number 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,

  • 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

  • get converted to this binary for presentation. So this number 10,

  • is in the decimal system which has all the digits from 0 to 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

  • 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

  • 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,

  • we should see 20, because as I told you before Python interpreter executes our

  • code line by line from the top. So first we set

  • the price to 10, then we reset it to 20, and finally we

  • print it on the terminal, let's run the terminal, there you go, so,

  • we see 20 here, okay? Now these

  • 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