Python for AI - Full Beginner Course — Transcript
Full transcript
- 0:00If you want to learn the Python
- 0:01programming language specifically to
- 0:03build AI applications, then this video
- 0:05is for you. We're going from absolute
- 0:07beginner to writing real Python code for
- 0:08AI applications all in one video. And
- 0:11right now, Python is the language for
- 0:13artificial intelligence. So whether you
- 0:14want to build your own AI apps, get into
- 0:16data science, or simply become more
- 0:18valuable in your career, this is one of
- 0:20the most in demand skills you can learn
- 0:22right now. And now there are already a
- 0:24ton of learned Python tutorials and
- 0:26courses out there, right? You're
- 0:27probably wondering which one should I
- 0:29follow and why should I watch this
- 0:30video? Well, most of the videos out
- 0:32there actually waste your time on a lot
- 0:34of stuff that you actually don't need to
- 0:36know if you want to use Python
- 0:38specifically for AI. So, this video is
- 0:40different. We'll start from the basics
- 0:42and I'll make sure to explain everything
- 0:43step by step so you can follow along.
- 0:45Then, I'll teach you all the core
- 0:47concepts you need to understand in order
- 0:49to learn Python fast. We'll build up in
- 0:51complexity, work with data, and create
- 0:53reports. And as a final exercise, you're
- 0:55going to build your own AI chat
- 0:56assistant that can chat with your data.
- 0:58My name is Dave Ealar. I'm the founder
- 1:00of Datal Lumina, an AI development
- 1:01company where we built custom AI
- 1:03solutions for clients across many
- 1:05industries now. I've been using Python
- 1:06almost every single day for over a
- 1:08decade, and I already taught this
- 1:10language to more than 35,000 students
- 1:12worldwide. So, if you're looking to
- 1:14learn Python from a professor who only
- 1:15teaches, this is not the course for you.
- 1:17Everything that we'll be doing in this
- 1:18course is practical, battle tested, and
- 1:21it's based on real work in the AI field.
- 1:23The stuff companies and clients are
- 1:25paying for right now. And look, it
- 1:27doesn't matter what your background is.
- 1:28You're never too young, too old, or too
- 1:30late to start. If you can follow simple
- 1:33explanations and have a bit of
- 1:34curiosity, that's important. You can do
- 1:36this. So, grab a coffee and take out
- 1:38your notes. This is Python for AAI, the
- 1:40course I wish I had when I started.
- 1:43Let's dive in. All right, so let's get
- 1:45started. I am super excited to go
- 1:47through this entire course with you and
- 1:48to teach you everything that you need to
- 1:50know about Python to build AI
- 1:51applications. Before getting started and
- 1:53installing Python, let me give you a
- 1:55quick overview in 30 seconds how to get
- 1:57the most out of this course. What you
- 1:58are looking at right now is the handbook
- 2:00which I will make available for you link
- 2:03in the description. It's hosted under
- 2:04python.dataluminina.com.
- 2:06All of the other information, links,
- 2:07codelocks that you need will be in here.
- 2:10So use that to your advantage. Now,
- 2:12whenever I go too fast, you can go back
- 2:14here, find more information. And
- 2:16whenever you feel like I'm going too
- 2:17slow, use the chapters below this video
- 2:19to skip ahead or use the speed controls
- 2:21below this video to increase the speed
- 2:23of the video. And now, what's going to
- 2:24make this course different from a lot of
- 2:26other Python courses out there beyond
- 2:28just the focus on AI. In the beginning,
- 2:30we're going to spend a lot of time on
- 2:31setting up a professional work
- 2:33environment for you. You see, most
- 2:35Python tutorials and courses go through
- 2:37the Python setup and then they
- 2:38immediately jump into writing out
- 2:40isolated Python code examples. But what
- 2:42I found over the years teaching
- 2:44thousands of students this language is
- 2:46that in the beginning, writing the code
- 2:48itself isn't the hardest. And especially
- 2:50nowadays with AI, you can literally ask
- 2:52JPT to come up with anything and you can
- 2:55plug it into your code editor. What you
- 2:56need to focus on in the beginning is
- 2:58having a solid understanding of the
- 3:00tools you use, how to set up your
- 3:02environment, how to manage package and
- 3:03dependencies and how you can create
- 3:05projects so that whenever you go out in
- 3:07the real world beyond this course and
- 3:09you want to build something or follow a
- 3:10course or tutorial, you know exactly
- 3:12what it is that you need to do and
- 3:13you'll have a professional coding setup
- 3:15exactly the same as what I am using
- 3:17right now and what you would actually
- 3:19use when you get a job and work with
- 3:20Python in the real world. So just know
- 3:22that we're going to spend quite some
- 3:24time there in the beginning. That's the
- 3:25whole getting started chapter and it's
- 3:27there in the beginning for a reason. You
- 3:29don't want to skip this if you're not
- 3:30familiar with these concepts. So, we'll
- 3:32get into all of the installations,
- 3:34setups, and configurations that you need
- 3:36in order to work professionally with
- 3:37Python. Then, in the Python basics,
- 3:39that's where we actually get into the
- 3:41programming language. And now, even if
- 3:42you already have some coding skills or
- 3:44you're coming from a different
- 3:45programming language, I still highly
- 3:46recommend to go through this entire
- 3:48getting started chapter with me because
- 3:50I will show you the exact setup that I
- 3:52am using right now so that if you follow
- 3:53through with the course, everything that
- 3:55you see will be exactly the same on my
- 3:57screen as well as on your screen. All
- 3:58right, so let's get started. The first
- 4:01thing that we are going to do is install
- 4:04Python on your machine. So following the
- 4:06handbook, I am here in the section
- 4:08installing Python to get it up and
- 4:10running on your computer. So, I'm first
- 4:12going to walk through the Windows setup.
- 4:13If you're on Mac, you can use the
- 4:15timestamps below to skip ahead. So, the
- 4:17first thing that you need to do is you
- 4:19can go to python.org/d downloads or
- 4:22follow the link over here. Then you will
- 4:24find this page where you can simply
- 4:27click on download python. And then once
- 4:29that's uh completely done, you can
- 4:31doubleclick on it to start the
- 4:33installer. Now, here is a very important
- 4:36thing. When you go through the
- 4:37installer, you should check the
- 4:39following box. When it asks, should you
- 4:41add Python to the path? You should check
- 4:43mark that. It will look somewhat like
- 4:46this. So, you can see it over here. Let
- 4:47me add a little bit smaller for you.
- 4:48Now, this is an older version of Python,
- 4:50but the setup will look something like
- 4:52this. And you should add Python to your
- 4:54path. Then, you can just follow through
- 4:56with the installer. Do not customize
- 4:58anything unless you know what you're
- 5:00doing. All right. And that's it for the
- 5:01quick installation. Super easy to
- 5:03follow. So now next in this video I will
- 5:04show you how to do this on Mac but
- 5:05you're on Windows. So make sure to skip
- 5:07to the next chapter where we're going to
- 5:08install your code editor. All right. So
- 5:10now I'll show you how you can install
- 5:12Python if you are on Mac. And the first
- 5:14thing that we need to check here is
- 5:16check whether Python is maybe already
- 5:17installed on your system because for a
- 5:19lot of Mac systems this is already the
- 5:21case. So what we are going to do is
- 5:23we're going to open up the terminal. And
- 5:25don't worry if you've never used the
- 5:26terminal. We just use it to type in a
- 5:28command and it's not that scary. So what
- 5:30we can do is we can open up Spotlight.
- 5:32And you can do that by hitting command
- 5:34and spacebar. Then this will show up and
- 5:37you can type in terminal. So if I open
- 5:39that up, you'll see this console coming
- 5:42up over here. This is a terminal where
- 5:45we can run commands. And all you need to
- 5:47do right now is come over here to the
- 5:49documentation and you should type in
- 5:50Python 3 space- version. So you can type
- 5:54it out or you can copy paste it like I
- 5:56do over here. Come to the terminal and
- 5:58then I'm going to paste that in with
- 6:00command V. And what I can now do is I
- 6:02can hit enter. Now you can see on my Mac
- 6:04it is already installed because it's
- 6:06showing me a Python version meaning it's
- 6:08installed. If you also see a version
- 6:11over here that also means Python is
- 6:13installed. If you get an error over here
- 6:15mentioning like look Python is not
- 6:16available or it's not recognized then
- 6:18you still need to install Python and you
- 6:20can continue with the rest of the
- 6:21instructions in here. So in case you do
- 6:23need to install it you can scroll down
- 6:24over here on this install Mac page and
- 6:26you can go to python.org/d downloads
- 6:28which we have open over here. You can
- 6:30click the big download button. It
- 6:32doesn't matter if it's a different
- 6:33version. If you watch this in the
- 6:35future, it will be different. So, you
- 6:36click the download button and then over
- 6:38here it will start to download. So, then
- 6:41while you wait for that to finish, you
- 6:43can go to your download folders. Simply
- 6:45doubleclick on it and install Python
- 6:48like any other app. All right.
- 6:49Congratulations on installing Python on
- 6:52your machine. Now, the next step is to
- 6:54install an application that actually
- 6:56allows us to work with the Python
- 6:57programming language. So, we are going
- 6:59to install my favorite code editor to
- 7:01work with the Python programming
- 7:02language, and that is Visual Studio
- 7:04Code. And that is really all you need.
- 7:07I've been using this application for the
- 7:08past 5 years already. I love it. It's
- 7:11completely free. It's super extensible,
- 7:12and it's really it got it's got
- 7:14everything that you need to
- 7:15professionally work with the Python
- 7:17programming language. And nowadays,
- 7:19there are, of course, a lot of AI
- 7:20assisted code editors out there. Cursor
- 7:22being one of the most popular ones right
- 7:24now. The good thing is that everything
- 7:25that you do in setup within Visual
- 7:27Studio Code can also be done exactly the
- 7:29same and imported within Cursor because
- 7:31cursor is built on top of VS Code. So
- 7:34let's get into how to set up Visual
- 7:36Studio Code. So I come over here to the
- 7:38install VS Code tab and again depending
- 7:40on whether you're on Windows or Mac OS,
- 7:43it's a little bit different, but you can
- 7:44just go to the website and this big
- 7:46download button over here, it will be
- 7:48dynamic for the operating system that
- 7:50you're that you're on. So for me, it
- 7:51will say Mac. for you. If you're on
- 7:53Windows, it will say Windows. So again,
- 7:55download it. It will go to your download
- 7:57folder. Click on it and follow the
- 7:59installation in there. One more time.
- 8:02It's important that you add it to your
- 8:04path on Windows. And then you just click
- 8:06install, finish when done. Process is
- 8:08exactly the same for Mac OS. You can
- 8:11keep it in your doc. There might be some
- 8:13security questions that pop up where you
- 8:15need to give it permission. So just
- 8:17follow that. It's completely safe. The
- 8:18application is for Microsoft. And then
- 8:21we can go and verify the installation.
- 8:24So what we can do right now is we're
- 8:26going to open it. And there we go. So
- 8:28this is the first screen that I see
- 8:30right now with versions updates, a
- 8:32welcome screen, and now since Visual
- 8:35Studio Code is so extensible and it it
- 8:37can work with a lot of programming
- 8:38languages out of the box, there's not
- 8:40much there. So, what we're going to do
- 8:42right now is I'm going to share my exact
- 8:45setup with all the extensions and
- 8:47settings that I use to work on all of my
- 8:50Python projects that I've been doing for
- 8:52the past 5 years. This is really a
- 8:54professionalgrade environment that we're
- 8:56going to set up. And this is so so
- 8:58crucial to spend a little bit of time
- 8:59here to understand this tool because
- 9:02what you'll find on this journey of
- 9:05learning Python is that actually the act
- 9:08of writing code, writing out the like
- 9:11line by line sentences and the
- 9:12characters like you will quickly get a
- 9:14hang of that and AI can work really well
- 9:17with that. AI can help you as well, but
- 9:19you need to be able to know where to
- 9:20find it, how to set it up, how to create
- 9:22a new project, how to add new things to
- 9:24it, how to run code, how to debug code.
- 9:27So, that's also going to be a a big
- 9:29difference between a lot of the other
- 9:31Python tutorials and courses that you'll
- 9:33find out there. And I know that in the
- 9:35beginning when I was learning Python,
- 9:36this was so annoying to me where always,
- 9:38yeah, I would get it on like a single
- 9:40file. I could follow a tutorial, but
- 9:42then when I was on my own project,
- 9:44things looked different and I just
- 9:45didn't have the full system and it just
- 9:47didn't understand the full process. So
- 9:49that's what we're going to spend some
- 9:50time on right now. Okay. And the first
- 9:51thing that we're going to do is we're
- 9:52going to install the Python extension.
- 9:54So I can click on the link over here to
- 9:57see where this is going. But we can also
- 9:59do this directly from Visual Studio
- 10:01Code. So what I'm going to do is we're
- 10:03going to the extensions tab and then
- 10:05we're going to search for Python. So let
- 10:07me walk you through that. Here is Visual
- 10:09Studio Code completely empty. You can
- 10:11see the extensions over here. So, it's
- 10:13this little icon. There's also a
- 10:15keyboard shortcut to it. And you can see
- 10:17it's already recommending something to
- 10:19me. Python over here. But in case this
- 10:21is not there for you, you can type in
- 10:23Python. And then it should show you
- 10:25exactly what's over here. Python. It
- 10:27should be from Microsoft. You see the
- 10:29blue check mark over here. You can click
- 10:31on it or directly install here or over
- 10:33here. So what this is going to do, this
- 10:35is going to behind the scenes install
- 10:37the Python extension so that when we
- 10:39work with Python files, our editor, our
- 10:42code editor can recognize it. So this is
- 10:44an essential extension that we need.
- 10:46Okay, so that was the Python extension
- 10:48and now we're going to change a quick
- 10:50setting. We're going to use this later.
- 10:52Don't worry about it for now. All you
- 10:53need to do is go to the settings of
- 10:56Visual Studio Code and you should copy
- 10:58paste this or search for this. So Python
- 11:00terminal execute in file directory. This
- 11:02is really useful for later down the
- 11:04line. So I can come in here. I go to
- 11:06settings. And then you can search for
- 11:08this. And you want to make sure that
- 11:09this is checked on a fresh new install.
- 11:12It's like this. And you want to click
- 11:13this. And that's it. You can just X out
- 11:15of it. It will automatically save. So
- 11:17this will make sure that later when
- 11:18we're going to execute Python files, the
- 11:20editor will execute the file from the
- 11:22directory instead of the workspace
- 11:23route. So when we're going to reference
- 11:25files, it will be a lot easier. All
- 11:26right. Then next, there are two more
- 11:28extensions that I recommend to install.
- 11:30The first one is pylance and the other
- 11:32one is Jupiter. So let's start with P
- 11:34lens first. We do exactly the same
- 11:36process. We come in here. We search for
- 11:37pilance. We see it pop up over here also
- 11:40from Microsoft. And you can see it's
- 11:42it's actually already installed by
- 11:44installing Python. But you can double
- 11:46check this. So make sure that if you go
- 11:48to Pilance it it if it says install you
- 11:51should click it. And then we go to
- 11:53Jupiter which is something we are going
- 11:55to heavily use throughout this course
- 11:57but I will show that later. For now, we
- 11:59can just click install and then we
- 12:02should be good. This takes a couple of
- 12:04seconds. Now, coming back to the
- 12:07instructions over here. What we're going
- 12:09to do right now is we're going to
- 12:10customize the code editor. And this is
- 12:13completely optional. This is not going
- 12:15to change anything about how the code
- 12:17editor works, but I like to set up uh my
- 12:19environment in a specific way. So, for
- 12:22the past years, I've been using this uh
- 12:25theme and I really like it, the Atom one
- 12:27dark. So, let me show you how to install
- 12:28that and what that looks like. And you
- 12:30can also search for other teams that you
- 12:32like. So, this is really just like the
- 12:34coloring, the fonts. You'll see it in a
- 12:36bit. So, I can search for Atom one dark
- 12:38team. Hit install. Trust publisher and
- 12:40install. There we go. And it
- 12:42automatically right now it already sets
- 12:44the coloring. You saw it, right? So,
- 12:46yeah, you can see right over here it now
- 12:48asked, do you want dark modern or Adam
- 12:51one dark? So, I set this over here. You
- 12:53can also click on set the color team. So
- 12:55that's now installed. You can also at
- 12:58any point come all the way to the bottom
- 13:01over here where you see the little gear
- 13:03icon and you can see themes over here
- 13:05and there you can see the color theme
- 13:07and the file icon. So if I click on this
- 13:09the color theme you can see everything
- 13:11that is currently installed. So if you
- 13:14for example let's click on the Kimi dark
- 13:16you can see this is a very different
- 13:18look to what we had right. So this is
- 13:20for you a way to go through it and to
- 13:23pick a theme that you like. All right.
- 13:24Now, there's one more setting, the three
- 13:26indentation, but we'll actually get back
- 13:27to that in a couple of minutes because
- 13:29then I can actually show you what it
- 13:31does. So, for now, we are going to go to
- 13:33the next section, and that is creating
- 13:35projects. One of the most important
- 13:38things in the beginning to fully
- 13:40understand because this is really the
- 13:43point where look, you see examples
- 13:45online, you see me go through this
- 13:47tutorial, but now you're in the real
- 13:48world and you have an idea, you want to
- 13:50try some. Where do you start? Right? We
- 13:52have Python installed. We have a code
- 13:54editor, but how does it work? How where
- 13:56are the projects? So, let's set that up
- 13:58right now. So, what I recommend you to
- 14:01do is creating a folder somewhere on
- 14:04your computer. Doesn't matter if it's in
- 14:06your documents, in your home directory,
- 14:08any type of place where we are going to
- 14:10store all of our Python projects. So,
- 14:12for the sake of demonstration, I'm going
- 14:14to create one on our data luminina drive
- 14:16over here. So, I'm going to call it
- 14:18Python projects. All right. And now what
- 14:21I want you to do next is inside this
- 14:23folder. So this will be the master
- 14:24folder. And in here we can do we can
- 14:26create all kinds of folders for all the
- 14:28projects. So first we're going to create
- 14:30a folder for this course and we're going
- 14:32to call it Python for AI. But whenever
- 14:34you have another ID you want to try
- 14:36something else I invite you to do that
- 14:39in that same folder and follow a similar
- 14:41structure and a similar setup so that
- 14:43you work very organized and you always
- 14:45know where all of your Python projects
- 14:47are. Now for the main folder, it doesn't
- 14:50really matter what type of naming
- 14:51convention you use, whether you use
- 14:53capital letters or not. But for the
- 14:55project folders itself, I recommend to
- 14:57use all lowercase and dashes. And why
- 15:00this is the case, this is actually
- 15:01called kebab case. And this is going to
- 15:04match how projects are going to appear
- 15:06on GitHub. This is something we'll cover
- 15:08later. But this is just a best practice
- 15:10that I always do and I recommend you to
- 15:12do as well. So what it then looks like
- 15:14if I come in here Python projects I'm
- 15:16going to create a new folder and I'm
- 15:18going to plug in Python for AI all
- 15:20lowerase and dashes using the kebab
- 15:23case. So now we have that created. What
- 15:25we can do right now is now from Visual
- 15:28Studio Code we can open up this folder.
- 15:30So let me come back over here. This is
- 15:32what your Visual Studio Code should look
- 15:34like right now. If you go over here to
- 15:36the explorer. So before we were
- 15:38installing all of the extensions. Now we
- 15:40can go to the explorer and you can see
- 15:42this is empty. You have not opened a
- 15:44folder yet. So we can click on that
- 15:46click on open a folder and then we go to
- 15:48the place where we just created our
- 15:50Python projects and then Python 4AI. So
- 15:52depending whether you're on Mac, Windows
- 15:54is a little bit different but make sure
- 15:55to navigate through the explorer or the
- 15:58finder to this folder. And then what you
- 16:00can do right here is you can click on
- 16:01open. And now what you can see is now
- 16:05this folder is opening. And the first
- 16:07time you do this, Visual Studio Code
- 16:09will ask, do you trust the outers of
- 16:10this file? We created it. So yes, should
- 16:12be good. Okay. So now we have this empty
- 16:15screen over here. And now there's one
- 16:17more important step that you need to do
- 16:19for every project that a lot of
- 16:20beginners forget. And that is creating a
- 16:23workspace in Visual Studio Code. Because
- 16:26what we do right now, we open up a
- 16:28folder and now we need to save that
- 16:30folder and everything in there as a
- 16:31workspace. A workspace is Visual Studios
- 16:34Code way of defining projects. And why
- 16:36we want to do that is in this way we
- 16:38create a single file that we can
- 16:40doubleclick it will open and everything
- 16:42will be there. So when you're working on
- 16:44something, you hit X, you shut down your
- 16:47computer, you restart it, you can
- 16:48doubleclick on one file and everything
- 16:51will be there exactly how you left it.
- 16:54That's what the workspace is about. It's
- 16:56like a bookmark. It remembers
- 16:57everything. So now what you want to do
- 16:58is you want to save the workspace. So
- 17:01within Visual Studio Code, we go over
- 17:03here, we go to file and then over here
- 17:05you should see save workspace as. So we
- 17:08can click on this and it will by default
- 17:10open up the the explorer or the finder
- 17:13in the same folder that you are
- 17:15currently in and it will also give it a
- 17:17default name. It will say save as
- 17:19Python4i.code
- 17:21test-workspace. This is the VS code file
- 17:24extension that you need. So if you set
- 17:26it up like this, there's no need to
- 17:28change anything about this. So this
- 17:29folder is already selected and I can
- 17:31just hit save. So what you now see is
- 17:33you should now see this workspace folder
- 17:36show up over here and we can also
- 17:38confirm that by going over to the finder
- 17:41or explorer and in the folder we now see
- 17:44the following workspace. Right. So now
- 17:45we can test this if this works correctly
- 17:48because what we can do is we can close
- 17:49out of video code. So now it's gone. We
- 17:51can even quit it. And now we can go to
- 17:53the finder Python projects Python for
- 17:54AAI and then we double click it. And
- 17:57there we go. We are back in our folder
- 17:59now with the workspace file in here. All
- 18:01right. So now with the workspace set up,
- 18:03it's time to create your first Python
- 18:05file. What we're going to do is we're
- 18:07going to create a new file and call it
- 18:08hello.py. So let's come back to Visual
- 18:12Studio Code. And what we can do over
- 18:13here is we can either use the buttons
- 18:16over here. So you can click a new file
- 18:17over here, but I can also rightclick and
- 18:19say new file. So let's come in here and
- 18:22let's type in hello.py. Now please be
- 18:24mindful of the extension that you have
- 18:26over here. So right now you can see that
- 18:29here if I type in hello.py you will see
- 18:31that Visual Studio Code displays the
- 18:33Python logo over here. So it recognizes
- 18:36that this is a Python file. Now this is
- 18:39very important. It doesn't matter what
- 18:41name you give it in here. That doesn't
- 18:43matter. But the extension should be.py
- 18:45if you want to work with Python files.
- 18:48Now you can also uh for example do a txt
- 18:50to do a text file or you can do a
- 18:52markdown file or you could do a
- 18:55JavaScript file. Visual Studio Code is
- 18:57flexible enough to understand that based
- 19:00on the file extension. So for now do
- 19:02hello.py and hit enter. Now we can open
- 19:05up this file in our editor and see it
- 19:07pop up over here. So on the left you
- 19:09have your files and now you can see the
- 19:10file over here hello.py. So this is
- 19:13where we can now actually start to write
- 19:15Python code. And the first thing that I
- 19:16want you to do is write a simple print
- 19:19statement similar to how we did that in
- 19:21the terminal at the beginning of this
- 19:23tutorial. Right? Remember? So we do
- 19:25print and then we do an opening bracket
- 19:28and Visual Studio Code will
- 19:30automatically just by hitting the
- 19:31opening bracket will already create the
- 19:33closing bracket. You can also see how we
- 19:35have different colors in there. This is
- 19:37all possible because of the Python
- 19:38extension and pyance that we have
- 19:40installed. Then we can do double quotes
- 19:42and we type in hello world and an
- 19:44exclamation mark. So we now have pretty
- 19:46much the most basic Python script that
- 19:48you can think of only with a simple
- 19:51print statement. So let's actually see
- 19:53how we can run this because in the
- 19:55terminal we would type this out and we
- 19:57would hit enter right but if I hit enter
- 19:59right now I will simply go to the next
- 20:01line similar to what you have in word or
- 20:04any other text setter and I can write
- 20:06more print statements. So now let's
- 20:08cover how we can run this file over
- 20:10here. And before running your Python
- 20:12file, there's one thing that you should
- 20:14always do at the beginning of every
- 20:15project. And this is also one of those
- 20:17things that in the beginning you often
- 20:19forget it. You just have to double check
- 20:20it. But don't worry throughout this
- 20:21course. We will cover it lots of times
- 20:23so you'll remember. And that is setting
- 20:26the correct Python installation because
- 20:28we have installed Python on our machine.
- 20:31But we also need to tell Visual Studio
- 20:33Code which Python version to use. Now
- 20:36out of the box generally nine out of 10
- 20:38times this in right now automatically
- 20:41goes correct because you can see right
- 20:44now here in the bottom screen you can
- 20:45see 3.13.5.
- 20:48So right now you can see it is using
- 20:50this Python installation on my machine.
- 20:52If I click on this you can see I have
- 20:54more Python installations over here. If
- 20:57you use virtual environments, something
- 20:59we will cover later in this program,
- 21:00which is a core skill that you need to
- 21:02understand, you'll end up with multiple
- 21:05Python versions that you can select. So,
- 21:07for now, it's important that we select
- 21:10the default one. If you've just
- 21:11installed Python, there's likely only
- 21:13just one version here, but make sure
- 21:15that you refer to the Python
- 21:17installation that you installed at the
- 21:19beginning of this session. So I click on
- 21:21this and now Visual Studio Code knows
- 21:23okay if I want to run this this Python
- 21:25file here is the installation that I
- 21:27need to use. And now in order to
- 21:29actually run the Python file and execute
- 21:31the code what you need to do is you go
- 21:32to the top right corner over here and
- 21:34click on the play button. So what this
- 21:35will do is this will open up the
- 21:37terminal window within Visual Studio
- 21:39Code and it will point to the file on
- 21:42our system. So you can see the full pot
- 21:44over here and then it will use your
- 21:46Python installation to run this. And you
- 21:48can now see that when we run this, you
- 21:50first see the line over here. Where is
- 21:52the Python file located? And then you
- 21:54can see hello world over here. Now I can
- 21:56simply close this out. I can also click
- 21:58in here and I can do run Python file in
- 22:00dedicated terminal. You'll find that
- 22:02this is exactly the same. It create it
- 22:04will create a new terminal session. The
- 22:06easiest way for now is just to remember
- 22:08when I want to run the script, I can
- 22:10click on this. And now what is actually
- 22:12going on here behind the scenes is
- 22:13something I want to explain. Because
- 22:15when we click on this play button, what
- 22:17our editor does for us, it executes a
- 22:20command. But if we were to not use an
- 22:23editor like this and simply run this
- 22:24file via the terminal, how would we do
- 22:26it? So let's show uh let's have a look
- 22:29at what what is actually happening. So
- 22:31right now we can also execute this file
- 22:34by saying look we want to use Python and
- 22:37then we point to our hello.py pi file
- 22:39and we simply run that. So you can see
- 22:42that right now this is also executing
- 22:44this file and it's printing this hello
- 22:46world in here. So if we now close this
- 22:49out and one more time click on this. So
- 22:51let's have a look at what's going on
- 22:52here in the terminal because it's a lot
- 22:53of information but all that there is to
- 22:55it is first of all it says look we're in
- 22:58this current folder. So we go within our
- 23:00terminal, we go into this folder where
- 23:02we were currently at. Then we point to
- 23:04the specific Python location and before
- 23:07in the example I just did Python, right?
- 23:09But in the terminal when we do this via
- 23:11editor, it's explicit. So it completely
- 23:13says, look, we're using this version of
- 23:15Python. And then we point to the Python
- 23:17path. So here you can see even though
- 23:19let's see, it's cut off a little bit,
- 23:20but you can see it's pointing to this
- 23:22hello.py file over here. So that is just
- 23:26what you should know about what's going
- 23:28on behind the scenes when you click on
- 23:29that play button because you could also
- 23:32do this within the terminal without
- 23:34needing Visual Studio Code and you can
- 23:36do it by simply checking look I have the
- 23:39Python command this is available I can
- 23:41do that and I can quit out of that and I
- 23:43can use that Python command to reference
- 23:45certain files you need to write out the
- 23:47entire file path and now because we're
- 23:49in this folder already we can execute
- 23:52it. So as you are learning the Python
- 23:54programming language, this is really a
- 23:55fundamental skill and an idea that you
- 23:57need to understand. But luckily when we
- 23:58are using an editor, we can just hit the
- 24:00play button. So we don't have to do it,
- 24:02but we need to understand what's going
- 24:04on behind the scenes. There's also a
- 24:05default keyboard shortcut that you can
- 24:07use and that's Ctrl F5 or CMD F5 on Mac.
- 24:11I actually like to change this. So let's
- 24:14do that right now to see. You can set it
- 24:16to anything you want. So if I come over
- 24:17here to the settings and then go to
- 24:19keyart keyboard shortcuts and then type
- 24:22in run python you can find the python
- 24:24run python file over here and then under
- 24:26the key binding column if I click in
- 24:28here I can now plug in any keyboard
- 24:29combination that I want. I actually like
- 24:31to do cmd enter and then overwrite that.
- 24:34There are already commands in Visual
- 24:36Studio Code that have that as well but I
- 24:38find if that you have it like this I can
- 24:40simply now hit cmd enter or control
- 24:43enter if you're on Windows and I can now
- 24:45run this. If this is causing any issues
- 24:47for you or you want another shortcut,
- 24:49feel free to change it or just use the
- 24:51play button over here. One more thing
- 24:52that you should also know right now is
- 24:55that if you click on this play button or
- 24:56run the code, this terminal will open up
- 24:59over here. And this terminal that we're
- 25:01seeing right here is exactly the same as
- 25:04the terminal we used before, right? So
- 25:06here on Mac you have the terminal, on
- 25:08Windows you have the Windows terminal.
- 25:09So I can do here python- version and it
- 25:13will show the Python version that I'm
- 25:14using. In a similar way, I can do that
- 25:16here as well. So I can do python-
- 25:18version and I can also run that here. So
- 25:21that's something important to keep in
- 25:22mind. Whenever we're working with Python
- 25:24code over here and we send it to the
- 25:26terminal, all the things that we can do
- 25:28in a regular terminal, we can also do
- 25:31that here in here right from Visual
- 25:33Studio Code. So we don't have to leave
- 25:35it when later we have to install certain
- 25:38things. So generally, especially in the
- 25:39beginning, you actually don't have to
- 25:41deal a lot with the terminal. you just
- 25:43close it, delete it and then whenever we
- 25:45need to run something, it will open and
- 25:48then occasionally we need to install
- 25:50some things or tweak some settings and
- 25:52that's where the terminal will come into
- 25:53play. And whenever the terminal is gone,
- 25:55so for example, you X out of it or you
- 25:57lose it. You can also go always go to
- 25:59the top uh menu bar, click on terminal
- 26:01and then for example do new terminal.
- 26:03Now it will show up again. There's also
- 26:05a default command. It's either cmd or
- 26:08controll J. So I can hit that and that
- 26:10will just like it will not close it but
- 26:11it will hide it. So now if I come in
- 26:13here and I do python d- version one more
- 26:16time I show it I do uh command j I can
- 26:19hide it and then here you see I have the
- 26:21exact same terminal session still open.
- 26:24All right so now as an exercise you can
- 26:26give this a try and experiment with some
- 26:28different print statements just to get a
- 26:30feel for what it's like writing code
- 26:32hitting command or control enter and
- 26:35sending it to the terminal. So coming
- 26:37back over here every print line that we
- 26:39have in here will be a new print. So I
- 26:41can come in here and I say print and
- 26:43then I say I am learning AI. And now
- 26:47when I run this you'll find that first
- 26:49you see hello world and then you see I
- 26:51am learning AI. So whenever you are
- 26:53writing Python scripts you should
- 26:55remember that code gets executed from
- 26:57top to bottom and from left to right.
- 27:00It's pretty much exactly the same to how
- 27:01you read a book. All right. So you can
- 27:03play with it, get a feel for it, and
- 27:05just know that a simple print statement
- 27:07like this isn't really programming, but
- 27:10it's the first time that you executed a
- 27:12Python file, send it to the terminal,
- 27:14and everything is running. So if you
- 27:16made it to this point in the course
- 27:17already, that is already a huge
- 27:19milestone because if we actually come
- 27:21back to the handbook and see what we've
- 27:23learned and say always save your work,
- 27:25this is important as well. So come in
- 27:27here, I can hit command controls or you
- 27:29can go to file save. What this will do,
- 27:32it will save everything, all the files,
- 27:34all your work. Uh we have the workspace
- 27:36in here. So now I can simply close this
- 27:38out and then remember right, I can come
- 27:40to my Python projects, Python for AAI
- 27:42and now I can open up the workspace over
- 27:44here. So this is already such a big
- 27:47milestone because by now we have
- 27:48installed Python on your system. You
- 27:50created your first Python file, selected
- 27:52the interpreter. So we know we have the
- 27:54installation, we have the app, we know
- 27:56how to sync them and how to point them
- 27:57into the right direction. We created a
- 27:59Python program. Remember, we do
- 28:01hello.py. The pi extension tells us that
- 28:03it's a Python file. And now we
- 28:05understand how to run it and send it to
- 28:07the terminal as well. All right. And now
- 28:08there's one more quick setting that I
- 28:11want to do with you. And that is the
- 28:13following. If we go to settings over
- 28:15here and then search for tree indent. So
- 28:19you'll find this setting over here. The
- 28:20default is eight. I like I personally uh
- 28:24recommend I like to set this to 20. So
- 28:26look at what's happening over here in
- 28:28the uh explorer over here. If I set this
- 28:30to 20, you'll find that you have a
- 28:33little bit more indentation in here. Now
- 28:34you might be wondering Dave like what is
- 28:36this about? But is this is primarily if
- 28:38we're going to work with different
- 28:39folders. So let me actually uh if we
- 28:42have a folder in here and let's say I
- 28:43put this in here and I move it and now I
- 28:46want to see what's in this folder. Look,
- 28:48you can see there is a tree structure in
- 28:50here where you can clearly see the
- 28:52hierarchy. All right, so that was a lot
- 28:53of setup, right? and you are doing
- 28:55awesome and the good thing is that this
- 28:56is just stuff that we have to do once
- 28:58but I fully understand that as you are
- 29:00going through this with me you might be
- 29:01wondering like Dave I get all of this
- 29:03but how does it all fit together trust
- 29:05me I felt exactly the same way when I
- 29:07was learning all these new things in the
- 29:09beginning but trust me it will get
- 29:11better we just need to set up a few more
- 29:13things cover some core concepts and then
- 29:15you are actually fully prepared to
- 29:16actually start writing code which from
- 29:18there will actually become a lot easier
- 29:21all right so we're making great progress
- 29:23now the next tab. What I have for you,
- 29:25this is really cool. I have some
- 29:27resources on a resource hub that I
- 29:29created for this course that I want you
- 29:32to download right now because we will
- 29:33use most of them later. So, if you
- 29:35follow the handbook, you have the
- 29:37resources in the course resources. And
- 29:38now then, if you click on here, you will
- 29:40go to this page. You'll see Python fori
- 29:42resource hub and community access. Now,
- 29:44this is important because this is where
- 29:45you can access all the resources. So,
- 29:46the templates, files, and cheat sheets
- 29:48that you will need for this course. And
- 29:49don't worry, this is all completely for
- 29:51free. And on top of that, you'll also
- 29:53get exclusive community access to the
- 29:55data luminina academy where you'll find
- 29:57bonus lessons, advanced tutorials, and
- 29:59also free follow-up courses to continue
- 30:01your AI learning journey. Now, I am
- 30:03hosting this on Gumroad, which made it
- 30:04really easy for me to host these
- 30:06resources, and I can also update them,
- 30:08and then you will get a notification.
- 30:09Now, the only thing is I couldn't select
- 30:11free. I can just do zero. So, don't
- 30:13worry, you don't have to pay anything.
- 30:14You can just put in zero or any tip you
- 30:16want. If you want to give me a tip or a
- 30:17coffee, that's totally welcome. But also
- 30:19if you want to do zero that's totally
- 30:20fine. You click on I want this and then
- 30:23here you see the Pyth resource hub and
- 30:25community. You'll see an overview and
- 30:26then you just need to plug in your email
- 30:28address and you can get access. So
- 30:29throughout this course I will sometimes
- 30:31refer to files from the resource hub. So
- 30:33make sure you download that right now.
- 30:35And then the first thing you can check
- 30:36out is this Visual Studio Code cheat
- 30:38sheet with all of the keyboard
- 30:40shortcuts. There's one for Mac OS and
- 30:41for Windows. And in here are all the
- 30:44default keyboard shortcuts. But this
- 30:46will also give you an ID into all of the
- 30:48actions that are available within the
- 30:50code editor and that you can also
- 30:52change. This is really fun to play
- 30:54around with and you can really like make
- 30:56it your own. All right. And with the
- 30:58resources downloaded, we can now
- 31:00continue. And now before we get into the
- 31:01Python basics, which you can see over
- 31:03here is the next chapter within this
- 31:05course where we're actually going to
- 31:06write code, execute it, build cool
- 31:08things, and see how all of this come is
- 31:10coming together. On the getting started
- 31:12page, there's one more section over here
- 31:14called Python environment. And I want to
- 31:16go through this first because it's so so
- 31:18important and it will really help you to
- 31:21better understand what's to come and how
- 31:23it would also translate to other videos
- 31:25and tutorials you see. So I know that
- 31:27this this is a lot of setup but it is so
- 31:30so crucial and it's that is really what
- 31:33makes all the difference in my opinion
- 31:34from just a a basic Python course that
- 31:37shows you look here's how you can write
- 31:38Python. Yes, we know chatbt can do that
- 31:41as well, but how does everything work
- 31:43together? And virtual environments is a
- 31:46key component of that. So what we've
- 31:49seen right now, right, we installed
- 31:50Python, we then opened up Visual Studio
- 31:53Code and we selected the Python
- 31:55interpreter that we wanted to use,
- 31:56right? So remember when we were working
- 31:58in our project over here, you have this
- 32:00whole I have this list over here. You
- 32:02probably have one or two and we selected
- 32:04a a Python version in there. What you
- 32:06should know is that when you are working
- 32:08with Python in the real world, you're
- 32:10often working on multiple projects side
- 32:13by side. And next to Python having a
- 32:17version like 3.13 within the Python
- 32:21programming language, what we also do is
- 32:23we work with a lot of packages. We can
- 32:26use packages code that someone else has
- 32:28written written and we take that and we
- 32:30import it into our project and then we
- 32:32can use that. These packages also have
- 32:34version. So now we have our Python
- 32:36installation and we have our packages.
- 32:38Now what happens if you're working on
- 32:40project A and it needs version 1.0 of a
- 32:43tool and you're working in project B and
- 32:46that needs version 2.0 of a certain
- 32:48package. If you now install version two
- 32:50for project B, you just broke project A.
- 32:53So now you might be working on
- 32:55something. You run your code, everything
- 32:58works. then you like end of the day the
- 33:01next the next day you open up another
- 33:03project you try to run it and now you
- 33:04get an error we don't want that of
- 33:06course so that's where virtual
- 33:08environments come in so these are
- 33:12separated private copies for each
- 33:14project now before getting into that you
- 33:17need to understand uh packages and what
- 33:20they are about so I already gave a
- 33:22little bit of an introduction right
- 33:23these are uh literally pieces of code
- 33:25code snippets and files that other
- 33:27people created where we now don't have
- 33:30to start from scratch and that is one of
- 33:32the most amazing things about Python is
- 33:35its like developer ecosystem and all the
- 33:37packages that we can already use out of
- 33:39the box where now with typically just a
- 33:42few lines of Python we can do incredibly
- 33:45powerful things and we can create in
- 33:47incredibly powerful automations. So a
- 33:50very common one is the request library
- 33:52which we'll be using in this course the
- 33:54pandas library for working with data or
- 33:56the openi library to work with the
- 33:58models from openai. So to create your
- 34:00first virtual environment in our own
- 34:03project that we're currently working on.
- 34:05What we can do is we can use two
- 34:07methods. I'm going to show both of them
- 34:09to you. We have an easier method and we
- 34:10can do it via the terminal. So let's do
- 34:12the easy method first and this is
- 34:15through the command pallet. So within
- 34:17Visual Studio Code, if you do cmd or
- 34:19control shift +b, you'll open up the
- 34:22command pallet. Let's see what that
- 34:23looks like. If I now do cmd shiftp,
- 34:26you'll see the command pallet pop up. So
- 34:29if I now do python create environment,
- 34:32you can see this one over here, create
- 34:33environment, right? And then I get two
- 34:35options over here. So fanf or cond. If
- 34:37you don't have cond installed, you will
- 34:39probably only see f for now. Don't worry
- 34:41about what is and just click on fanf.
- 34:43And now what you can see over here is
- 34:45here you can see all of the Python
- 34:47versions that I have installed on my
- 34:48system. So you can even see that there
- 34:50are some more some older versions 3.9 in
- 34:53here. What I'm going to do is I'm going
- 34:54to select the latest version. And for
- 34:57you there will probably only be one or
- 35:00two. I recommend just picking the
- 35:01highest version. So we click on that.
- 35:03And now what's going to happen is Visual
- 35:06Studio Code is going to create a virtual
- 35:08environment for us. So you can see it
- 35:09happening over here. We now have this
- 35:11folder. It's called Fenf. And if I open
- 35:14this up, you can see files and folders
- 35:16in here. And what we've we've now done
- 35:18is we created a local copy of the Python
- 35:22installation. And if I now come back to
- 35:26hello.py, what I can now do, you can see
- 35:28it's already selected over here. Visual
- 35:30Studio Code does an excellent job at
- 35:33autodetecting the environment when it's
- 35:35uh within your project. But you can see
- 35:37that we now have the ven over here and
- 35:40which stands for virtual environment.
- 35:41And you can select that and what we can
- 35:43do right now if we now click on the play
- 35:46button one more time we will execute the
- 35:48code and we will execute it using our
- 35:50own environment. So I get it this is
- 35:52again this is abstract right at this
- 35:54point but think of it like this when
- 35:56you're working on different projects you
- 35:57really want to isolate everything and
- 35:59this is a way to get Python within our
- 36:01project in that folder in that folder
- 36:03that we could just created defense and
- 36:06we can make all the changes and all the
- 36:08updates just there. And this is also one
- 36:11of those things that's the nice things.
- 36:13This is like set it forget it once on a
- 36:15new project. And because we save it in
- 36:17the workspace right now the virtual
- 36:19environment is there. We've selected it.
- 36:21Now if I come back to uh the project
- 36:24over here I save this and I just close
- 36:27out of this. I can come to the folder
- 36:28over here. Open up the project and then
- 36:31you can see that it correctly selected
- 36:33the virtual environment and I can just
- 36:34come in here and run it without a
- 36:37problem. It is now using our virtual
- 36:39environment that we just created. All
- 36:40right. So that was method number one to
- 36:42create a virtual environment. The easy
- 36:44method. Now I'm going to show you the
- 36:45second method which is through the
- 36:47terminal. And I'm going to show you this
- 36:49so you understand it that whenever you
- 36:51see a tutorial you understand, oh
- 36:53they're creating a virtual environment
- 36:54using the terminal, but I never use
- 36:56this. So I'm just going to come over
- 36:58here and I'm going to copy this line. So
- 36:59python- mf and then the name of the
- 37:02folder. And let's close all of this out.
- 37:04I'm going to completely remove the
- 37:05folder again. Now I'm going to open up a
- 37:08new terminal and I'm going to paste the
- 37:10command in here and run it. And what
- 37:13you'll find is that right now you can
- 37:15see we have created a similar folder. So
- 37:17this is what h what's happening behind
- 37:18the scenes when you do the command
- 37:20pallet python create environment. And
- 37:23now because we have created the new
- 37:24folder in here we should select it one
- 37:27more time just to make sure that we
- 37:29refresh it and we should be good to go
- 37:31again. So that's another way to set up a
- 37:33virtual environment. All right. Now then
- 37:35a quick note about Anaconda because I
- 37:36want this to be a complete course and
- 37:38whenever you encounter it maybe in
- 37:40another tutorial I want you to be aware
- 37:42of it. So Anaconda is another way of
- 37:44managing Python distributions and
- 37:46virtual environments on your machine.
- 37:48It's very popular in the data science
- 37:50world and right now I would say I
- 37:52actually don't recommend using it. So I
- 37:54used this earlier on in my career but
- 37:56now when you want to focus on AI there's
- 37:59actually a much better way to manage
- 38:01Python environments and packages. So
- 38:03later on I'm going to introduce you to
- 38:05UV. Don't worry about that for now, but
- 38:07that's now my go-to. So Anaconda is a
- 38:09whole other application that you need to
- 38:11download and install on your system.
- 38:12It's free, but for now you just need to
- 38:14be aware of it. So whenever you
- 38:15encounter it and someone mentions using
- 38:17Anaconda, you can literally just replace
- 38:20that with using a virtual environment
- 38:21and just install the packages in there.
- 38:23It's exactly the same. You can so you
- 38:25can still follow along with that
- 38:26tutorial or course wherever they're
- 38:28using Anaconda. All right. And with
- 38:30virtual environments covered, let's get
- 38:32into Python packages. Another very
- 38:34important concept to understand because
- 38:36out in the world, whatever tutorial or
- 38:39course you'll follow, there is a high
- 38:42chance that at the beginning of the
- 38:44file, they will do some kind of imports
- 38:46and use some kind of packages and I can
- 38:48explain you everything about Python and
- 38:49how it works and how to write and what
- 38:51it means. If you don't understand this,
- 38:53you will run your code and you will
- 38:55still get an error. That's why I want to
- 38:57start here. So I already gave the
- 38:59introduction, right? Packages are
- 39:00collections of Python code that solve
- 39:02specific problems that other people
- 39:05created and that we can now very easily
- 39:07download and use for free. It's really
- 39:10awesome. And in order to get those
- 39:12packages and get them into our project,
- 39:15we can use pip. And pip installs these
- 39:18Python packages. It can manage all of
- 39:20that. So we don't have to go to a
- 39:21website. We don't need to do uh go
- 39:23through an install menu. We can simply
- 39:25run commands from the terminal and it
- 39:28will pull it straight into our project
- 39:30and specifically into our virtual
- 39:33environment. So pip is a command that
- 39:35you need to be f familiar with. So now
- 39:38let's install your first Python package.
- 39:42And to do that we're going to go through
- 39:44the terminal again. So open up the
- 39:46project and let's see. You can open up a
- 39:48new terminal or I can also do command J
- 39:51to pull up the one that I have active
- 39:53over here. So you can see I have
- 39:54previous sessions. You can close and
- 39:56manage them over here. And if I want to
- 39:58clear it out, I can do clear on Mac or
- 40:00cls on Windows which is not recognized
- 40:03over here. This is the starting point.
- 40:06This is now going to be the input for
- 40:09which we're going to use pip in order to
- 40:11pull those packages from the internet.
- 40:13So let's continue. So we understand the
- 40:16terminal right now and we are we want to
- 40:19make sure this is important that we are
- 40:21in our virtual environment. So let me
- 40:23actually check if I did that correctly
- 40:24as I am uh walking you through this and
- 40:27no I did not because I used a terminal
- 40:29session that was already open and later
- 40:32we installed the environment. So let me
- 40:34show you what I mean with this because
- 40:35this is a very common uh mistake. I just
- 40:38like click on the trash bin icon and now
- 40:40I go to new terminal. I open it up. This
- 40:42will activate it. Look what you can see
- 40:45right now over here. This means that we
- 40:48have a terminal open and it signals that
- 40:51it's using this virtual environment
- 40:53because remember right we have all of
- 40:55the different isolations. Whenever we
- 40:57want to install something we need to
- 40:59tell our terminal it needs to be in this
- 41:01particular folder. So Visual Studio Code
- 41:03will handle all of that automatically
- 41:05for us. So right now whenever this is
- 41:07available, this is active, it will show
- 41:09up using the virtual environment. One of
- 41:11the most common errors that you run into
- 41:13if you install packages and if it
- 41:15doesn't work if this wasn't correctly
- 41:17configured. So then you just need to go
- 41:19to okay which is the environment make
- 41:21sure to close it out and then create a
- 41:23new terminal. I'm being a little bit
- 41:25redundant over here but these are the
- 41:26things that will actually give you a lot
- 41:28of headaches when you are working in the
- 41:31real world. So make sure to take notes
- 41:32and refer back to this video and then
- 41:34you can say ah they've already told me
- 41:36this is exactly because you will make
- 41:38the these mistakes trust me. Now let's
- 41:40install your first package. And we're
- 41:42going to install the requests library.
- 41:44And the how to do that is really simple.
- 41:46It's pip install and then the name of
- 41:49the package. And in this case, we're
- 41:50going to install the requests library.
- 41:52Let's come over here. Let's clear this
- 41:54out. We do pip install requests. And
- 41:57then we hit enter. It doesn't take that
- 41:59long. Now we have downloaded the
- 42:00package. What just happened? Well,
- 42:02through the terminal and through the pip
- 42:04command, we connected to the Python
- 42:06package index, which is a huge websites
- 42:08where developers share their code. Then
- 42:10we downloaded a package, which are
- 42:12really just a bunch of Python files that
- 42:14someone else wrote, and we saved it to
- 42:16your virtual environment. So, let me
- 42:18also show you what's going on behind the
- 42:19scenes because now if we go into our
- 42:22virtual environment folder over here, we
- 42:24can come in here and we go to library
- 42:27and then we scroll down, you can see
- 42:29requests. So, this is the folder. So
- 42:31this is the package that we installed.
- 42:32And now you can see this is what we just
- 42:35pulled in here. Really just a bunch of
- 42:37Python files that someone else wrote
- 42:39that we can now use. You never have to
- 42:42like look in here. You rarely touch
- 42:44this, but just know that that's where
- 42:46it's installed and that's where it's on
- 42:48your system. And now then in order to
- 42:50use a package, what you can do in any
- 42:52Python file, you can start with an
- 42:54import statement. And later in this
- 42:56course, we'll go much deeper into this.
- 42:58Right now it's just about like showing
- 43:00you how to do it. So you've seen it once
- 43:03and later like comes the understanding.
- 43:05So right now we can simply copy paste
- 43:08this whole snippet over here to import
- 43:09the request library and try to download
- 43:12the content of a web page. So if I now
- 43:15come back to my project let's see
- 43:16hello.py. So this is the same file that
- 43:18you should have in here. We can remove
- 43:20everything here and plug this in. And
- 43:22now you can see it is still giving
- 43:23squiggly lines. Uh, and that can
- 43:26sometimes happen in the beginning. If
- 43:27you selected the right environment and
- 43:29you installed it correctly, this should
- 43:31all work. So now if I run this, we
- 43:34should see that this is now going to
- 43:36run. And there we should get a 200 back.
- 43:39So this is just a status code. So we're
- 43:40just literally like pinging the website.
- 43:42Again, doesn't matter what that means.
- 43:44You can now see we've imported the
- 43:46request library and it works. So the
- 43:49squiggly lines tells you that there is
- 43:52potentially an import error. And how to
- 43:54usually fix this is if I now close out
- 43:57this project and I open it up one more
- 43:59time. So come in here and let's open up
- 44:01the workspace. You can see that now it's
- 44:02gone. So sometimes this is a little bit
- 44:04of a bug where it tells you it's not
- 44:06installed correctly. Just reopen your
- 44:08Visual Studio Code. It should be gone.
- 44:09And let's see. We can run it one more
- 44:11time and everything still works. All
- 44:13right. And that's all you need to know
- 44:14for now about using Python packages. If
- 44:17you look into the handbook, there's more
- 44:19information on this list, but don't
- 44:21worry about it for now. We'll get back
- 44:22to that later. So now the final thing
- 44:24that I want to walk you through as part
- 44:26of the getting started section is
- 44:28interactive Python. And this is going to
- 44:31be really cool. This is actually one of
- 44:32my favorite ways to work with Python.
- 44:35And when I discovered this, I pretty
- 44:37much never went back. And to this day,
- 44:40almost every day, someone on my YouTube
- 44:42channel, like in in one of the comments
- 44:44on one of the many videos that I have,
- 44:46someone asked me, "How do you do that?"
- 44:48I have multiple videos on this already,
- 44:50but like this really changed the game
- 44:52for me and how fast I can work and how
- 44:55much fun it is to work with the Python
- 44:56programming language. So, let's set it
- 44:58up. Right now, I've shown you how you
- 45:01can execute Python code using the
- 45:03terminal. Right, we have this over here.
- 45:04We hit command enter or we do run Python
- 45:08file and it runs. But to me, this always
- 45:11really bothered me a lot because pretty
- 45:14much look at it right now. What's all
- 45:15this mess going on right here? Right, we
- 45:18get a 200 as an output. But there's just
- 45:20so much stuff uh going on. And there's
- 45:24actually in my opinion a much easier way
- 45:26to work with Python and that is using
- 45:28interactive mode. So let's first set it
- 45:30up and then I'll explain what it is. So
- 45:32there's one prerequisite and we need to
- 45:34install a package and that's why I
- 45:36wanted to share how you can install
- 45:38packages because you need this one. So
- 45:41what you can do is right now you can
- 45:42simply click on copy or like follow the
- 45:44command pip install IPI kernel. That's
- 45:46the one we need. So coming back to our
- 45:48editor to a terminal session. All right,
- 45:51let's come in here and do pip install
- 45:53ipi kernel. So this will install
- 45:55everything in there. Takes a couple of
- 45:57seconds. And this will also work with
- 45:59the Jupiter extension that we have
- 46:00installed in Visual Studio Code as well.
- 46:02So we have that and we have the IPI
- 46:04kernel. And now what we can do, we need
- 46:07to change a setting to make this super
- 46:09easy. So the easiest way to do this is
- 46:11simply copy this whole line because
- 46:14there are a lot of settings in Visual
- 46:15Studio Code. So Jupyter inter so copy
- 46:17this whole line and then come over here
- 46:19to the gear icon to the settings and
- 46:21then I just plug that in there and then
- 46:23you should see this Jupyter interactive
- 46:25window text editor execution selection.
- 46:27So here you can see when pressing shift
- 46:29enter send selected code in Python file
- 46:32to the Jupiter interactive window as
- 46:34opposed to the Python terminal and we
- 46:36select that. That's it. Now if I close
- 46:39out on this. So we have the same script
- 46:42over here. And now what I can do is
- 46:44instead of hitting command and enter to
- 46:47like run it in the terminal, right?
- 46:48That's the uh hotkey that I set in the
- 46:50beginning. What I can also do is I can
- 46:53select a certain section of the code. It
- 46:55can either be everything or a single
- 46:57line. And then I do shift enter and a
- 47:00window to the right will open. And now
- 47:02you can see the 200 status over here as
- 47:04well. So the difference is is that
- 47:07instead of like taking the entire file
- 47:09and sending it to the terminal and then
- 47:11all of the outputs showing up in my
- 47:13opinion in kind of like a messy way with
- 47:15a lot of like noise in there, now we
- 47:17have this very clean window here on the
- 47:19right where we can see the output. But
- 47:21it even gets better because instead of
- 47:22just running the entire file from like
- 47:25top to bottom, what we can also do is we
- 47:27can also execute certain sections or
- 47:29certain lines or pieces of the code
- 47:32itself. So I can come in here and when I
- 47:34am on a single line, so I'm now on line
- 47:36one and I do shift enter. You can see
- 47:38that we only run import request. So now
- 47:40we import the library and I can for
- 47:43example also just run the request over
- 47:46here. So just do that. So I just get the
- 47:48response and then finally I do the print
- 47:51statement. So, not only does it allow us
- 47:54to have a cleaner interface on the
- 47:56right, it also allows us to go through
- 47:58our code more in a more granular fashion
- 48:01and highlight certain section of this.
- 48:03So, as we go through this course and as
- 48:06we start to actually work with the
- 48:07Python programming language, this will
- 48:09really become apparent to you as to why
- 48:11this is nice and why this is so useful
- 48:13because we can check back and we can
- 48:15actually go here and say, look, we can
- 48:17even select partial lines. So, not even
- 48:19a full line, but I can do a selection
- 48:21and I can use the shift and the uh alt
- 48:23and option keys to go through this and
- 48:25even look at specific variables in here.
- 48:28All right, so that was the getting
- 48:29started section. Congratulations. We
- 48:31already covered a lot. Now, this would
- 48:33also be a good moment to take a break
- 48:35and to really think about what we've
- 48:38learned so far. So, let me quickly walk
- 48:39you through it. Right. So, when you
- 48:42started with this course, you did not
- 48:44have a Python installation. So, we got
- 48:46that onto your system. We got Visual
- 48:48Studio Code. You have the application.
- 48:50You now know how to create projects in
- 48:52there. Save them as a workspace and then
- 48:54you also understand the importance of
- 48:56virtual environments to create isolated
- 48:59in instances of the Python programming
- 49:01languages so that we can install the
- 49:03packages. You've seen how to work with
- 49:05the basics of Visual Studio Code, the
- 49:07extensions, how to style it. You know
- 49:09how to run Python files either using the
- 49:12terminal or using the interactive window
- 49:14which I am a big fan of. So right now
- 49:17you really have all the tools to start
- 49:19to get to work and you are so much
- 49:22better prepared than pretty much anyone
- 49:25else trying to learn Python because this
- 49:27really is a cheat code. Everything that
- 49:29I shared in here and that I boiled down
- 49:31into this step-by-step format, this all
- 49:33really took me years to learn. And I
- 49:35really wish someone in the beginning of
- 49:37my Python programming journey like
- 49:38literally over 12 years ago, I wish
- 49:40someone would have shown me this
- 49:42approach because it's a complete
- 49:45gamecher. And now if you're up for an
- 49:47exercise to really check if you
- 49:49understand this, here's what you can do.
- 49:51And I in the beginning this is tricky
- 49:53because I've given so many Python
- 49:55trainings already and students follow
- 49:57along up until this point. But then when
- 50:00they start again from scratch and they
- 50:02have to do it on their own with without
- 50:04essentially me like holding their hands
- 50:05and showing everything step by step, it
- 50:07can get tricky. So here's what I want
- 50:09you to do. Go to your Python projects
- 50:11folder and create a new project. So in
- 50:13there, create a new folder, give it a
- 50:15name, and then I want you to open it up
- 50:17in Visual Studio Code and go through the
- 50:19entire process. Everything that you need
- 50:21to do in order to set up to create a
- 50:23file, put some Python code in there. You
- 50:25can do a simple print statement similar
- 50:26to what we already did. use a virtual
- 50:28environment. Make sure you select it and
- 50:30make sure that you can run it both in
- 50:32the terminal and in the Jupyter
- 50:34interactive session. Make sure you save
- 50:36everything to a workspace and then close
- 50:38it out to see if you can open it up
- 50:39again. If you can follow along with
- 50:41that, you pass this first section of the
- 50:43course and you're ready for the next
- 50:44stage. All right, so welcome to the
- 50:47Python basics chapter. We are now
- 50:50actually going to start writing Python
- 50:53code and learning the language, learning
- 50:55what this is all about and how we can
- 50:56use it. So now with our environment set
- 50:59up, VS Code ready, our everything
- 51:02installed, we can use our Hello Pi file.
- 51:04And this is going to be the file that
- 51:06I'm going to continuously to work in.
- 51:08You can use this as a scratch pad,
- 51:10right? You so you can be sloppy in here.
- 51:12You can put some code in there. We can
- 51:14run it and then the next example, we can
- 51:16get back to this and we can keep using
- 51:19this. So we don't have to worry about
- 51:21managing all of the files. So what I'm
- 51:23going to do for now is I'm also going to
- 51:24close the sidebar over here to create a
- 51:27little bit more real estate on the
- 51:29screen here. And the command for that is
- 51:31command or control D to show the
- 51:33explorer. But for now, this is what we
- 51:35need to do. Okay. So coming back to the
- 51:39foundations, we're going to start with
- 51:41really the very basic building blocks of
- 51:43the Python programming language like
- 51:45variables, data types, operators. But
- 51:47before getting into that, I want to give
- 51:49you a little bit of an understanding
- 51:51like to understand the bigger picture of
- 51:53what programming is all about. Now, if
- 51:55you're coming from a different language,
- 51:57you can skip this part because you're
- 51:58already fully aware with this. But if
- 52:00you're completely new to programming, I
- 52:03this is a great moment to take a step
- 52:05back and to explain you what we're
- 52:07fundamentally doing. Because when you
- 52:08are following this program like step by
- 52:11step, action by action, you are so
- 52:13zoomed in into following exactly what I
- 52:16do, right? Installation, I get it. The
- 52:18app, I get it. An environment and but
- 52:20you need to understand what's the goal
- 52:23of all of this. What are we trying to
- 52:25do? And programming is all about writing
- 52:28instructions for computers. And
- 52:31computers are very literal. So you need
- 52:34to tell them exactly what it is that you
- 52:37want them to do. So if you for example
- 52:39tell a friend of yours like hey go make
- 52:41a coffee like internally they understand
- 52:44that they need to get a cup add coffee
- 52:46grounds pour hot water wait a couple of
- 52:48minutes the whole process right a
- 52:50computer doesn't understand this so when
- 52:52we want to try and accomplish something
- 52:54when we are trying to automate something
- 52:56where where when we try to create an AI
- 52:58agent or build a model we need to be
- 53:00very specific and we need to instruct
- 53:02the computer in such a way to follow the
- 53:05exact order of operations in order to
- 53:07accomplish our goal and there are many
- 53:10ways to do that and many ways and many
- 53:12programming languages to accomplish that
- 53:14and Python is one of them. So that's the
- 53:16first thing that you keep in mind. We
- 53:18are working on all of these isolated
- 53:20bits and pieces that in isolation don't
- 53:23mean a thing and are pretty useless. But
- 53:25when once we start to understand all of
- 53:27these building blocks and we start to
- 53:29combine them in different ways like Lego
- 53:31blocks, we can now all of a sudden
- 53:34create an AI chatbot. We create an AI
- 53:36agent. we can uh create a simple script
- 53:39that can take a document, extract
- 53:41information, give a summary and put it
- 53:42into a CRM. It open up opens up a whole
- 53:45world of possibilities which we can all
- 53:47do through the Python programming
- 53:49language. So that's what I want you to
- 53:51keep in mind as we start with these
- 53:53really really fundamental concepts.
- 53:56They're isolated. They're small. On
- 53:57their own, they mean nothing. And you're
- 54:00probably wondering like what can I
- 54:01automate this? What does this have to do
- 54:03with AI? But once we start to layer
- 54:05them, that's where everything starts to
- 54:07click. And with all programming
- 54:09languages, there are only a handful of
- 54:12basic operations that we do over and
- 54:15over again. So here the first one, a
- 54:17very common one is storing information.
- 54:19We want to get some type of data and we
- 54:20want to store that information so that
- 54:22we can process it. Let's say we have an
- 54:24age 25, a name is Sarah. Now later we
- 54:28can use that. We can reference Sarah by
- 54:30using the name variable. We can also
- 54:32make decisions. we can use if and else
- 54:34statements. So if this happens, we do
- 54:36that. But if that is the case, we do
- 54:38that. This allows us to make smart
- 54:41programs that don't only do just one
- 54:43thing, but based on the data and the
- 54:45information that is coming in, we can
- 54:47make decisions. Programs can also repeat
- 54:50actions. So they can repeat things 10
- 54:52times. So when a document is coming in
- 54:55maybe it has like 10 pages and for every
- 54:57page we want to do something maybe
- 55:00scrape the data extract it and then
- 55:02calculate things. So what's the total
- 55:04price? We have numbers. We want to add
- 55:05them, subtract, sub subtract them, apply
- 55:07any kind of math. And through this
- 55:10storing information, making the
- 55:12decisions, repeating the action and
- 55:13calculating things, we can solve a lot
- 55:16of problems actually using a programming
- 55:18language. All right. And then now let's
- 55:20get to the next section which is called
- 55:22Python syntax. This is all about how we
- 55:25properly write Python code. And similar
- 55:27to the English language where we have
- 55:30grammar, Python and every other
- 55:32programming language for that matter
- 55:34also follows follows certain rules. And
- 55:36instead of grammar, we call it syntax.
- 55:39So this is an important topic to
- 55:42understand. Even though Python is known
- 55:43for being very clean and readable,
- 55:46right? We saw that in the beginning. It
- 55:47pretty much just reads like plain
- 55:49English, there are still rules that we
- 55:51need to follow. And this is good of
- 55:53course because otherwise all the code
- 55:55from everyone would look different and
- 55:56it would all be messy. So throughout all
- 55:59of the following examples I will refer
- 56:01to the specific syntax and just know
- 56:04that if you ever run into an error there
- 56:06is a high chance that you will have some
- 56:08type of syntax error. Maybe it's a
- 56:10bracket that did not close. Maybe there
- 56:12is a quote missing. Maybe the
- 56:14indentation and the spaces are off. It's
- 56:16literally that tricky. So remember that
- 56:18for now. Syntax is all about how you
- 56:20write Python code and the rules you need
- 56:22to follow. And now as you go through
- 56:23this course, syntax is something I will
- 56:25bring up all the time because whenever I
- 56:27introduce a new concept, we will start
- 56:29with the syntax first. How to write it
- 56:31and what are the rules. And one of the
- 56:33most important things there which is
- 56:34also unique to Python is the indentation
- 56:37which is the spacing that we use to
- 56:39separate blocks of code and to bundle
- 56:41pieces of code together. So if you for
- 56:44example look at a JavaScript language
- 56:45you can for example use curly brackets
- 56:47and that signals look everything between
- 56:49these curly bracket belongs together.
- 56:51With Python we solely do that through
- 56:53indentation. So we'll go through
- 56:55indentation rules which we will
- 56:56constantly use and our editor will also
- 56:58help us with this because whenever we go
- 57:00to a new line where we need an
- 57:02indentation VS code will automatically
- 57:04do this for us. Now don't just worry
- 57:05about that right now. It will all become
- 57:07more clear as we go through the
- 57:08examples. But just know that indentation
- 57:10rules and using those four spaces is
- 57:12important in Python. Now, beyond just
- 57:14syntax rules that make your code run,
- 57:16Python also has style guidelines that
- 57:18make code more readable. And we as
- 57:20developers have agreed to a certain
- 57:22standard and these this is called PEP 8
- 57:24or the Python enhancement proposal 8.
- 57:26This is the official style guide for
- 57:28Python code. It covers things like that.
- 57:30We use four spaces instead of taps. We
- 57:32limit lines to 79 characters, naming
- 57:35conventions like using underscores
- 57:37lowercase instead of using camelc case
- 57:39and where to put spaces around
- 57:41separators. And now as we go through
- 57:43this course, I will follow these PEP 8
- 57:44style guidelines so you don't have to
- 57:46worry about them right now. But just
- 57:48know that there are rules for
- 57:49indentation for how we work with spaces,
- 57:51blank lines, and even line length. And
- 57:54at the end of this course, I'm even
- 57:55going to introduce you to a tool that
- 57:56can automatically take care of that. All
- 57:59right. So now let's have a look at what
- 58:00happens when you don't follow the syntax
- 58:03and you break your code. So let's say we
- 58:05do another print statement. Then we type
- 58:07hello world but then we remove the final
- 58:11quote over here. And you can already see
- 58:13that our editor is giving us these red
- 58:15squiggly lines indicating that something
- 58:17is wrong. So the string literal is
- 58:19unterminated meaning it is opened but
- 58:21it's not closed. But for the sake of
- 58:23demonstration I am going to run this
- 58:24code. So what I'm going to do in this
- 58:26case I'm going forward. You will see me
- 58:28do this over and over again. My cursor
- 58:30is here on this line and I am
- 58:31controlling that with the arrow keys
- 58:33left and right. And now on this line I
- 58:35simply press shift enter. And what this
- 58:37will do is it will open up the
- 58:39interactive window over here. And now
- 58:41here you can see the error. So you can
- 58:42see the line on which the error
- 58:44occurred. You can see it starts here. We
- 58:46opened up a string and then you see this
- 58:48syntax error. So now you know what
- 58:49syntax means and where this is coming
- 58:51from. So it says unterminated string
- 58:53literal detected which is just Python's
- 58:56way of explaining you opened up the
- 58:58string but you're missing a closing
- 59:00quote. So if we plug that in here and
- 59:03run it one more time, you'll find that
- 59:05the code will now run without any errors
- 59:07and we will get the hello world
- 59:09statement. And now reading errors is
- 59:12something you have to become good at
- 59:14because errors do not only happen when
- 59:16you're a beginner. Trust me, making
- 59:19errors is literally part of programming.
- 59:21even like the best programmers in the
- 59:23world, you build programs by trying
- 59:25things out, breaking things, and then
- 59:26fixing the bugs. So, it's a core part of
- 59:28the development process. So, how you
- 59:31read Python errors is something you get
- 59:34more and more used to, but there is a
- 59:36general principle that you can follow
- 59:37and it's in the documentation over here
- 59:39as well. So, first you'll see where the
- 59:41error happened. So, here you can see
- 59:42this is in line one. We're running the
- 59:44interactive session with this file. So,
- 59:46this is where it happened. Then, next
- 59:48you can also see what went wrong. So all
- 59:51the way at the bottom of the error and
- 59:53this is right now in this example this
- 59:55is a pretty short error. There can be a
- 59:57lot of information all the way at the
- 59:59bottom the final line you'll see in this
- 1:00:01case the syntax error. So Python will
- 1:00:03tell you what went wrong. And then the
- 1:00:05third component is the arrow pointing
- 1:00:07exactly to the spot where it happened.
- 1:00:09So following this three-step process to
- 1:00:12debug your code whenever something goes
- 1:00:14wrong. Look at what happened. Syntax
- 1:00:16error. Okay. Where line one and then you
- 1:00:18can see the exact snippet. Oh, it is
- 1:00:20something to do with a string. Now, in
- 1:00:22the beginning, all of these syntax
- 1:00:24errors right now, they will seem very
- 1:00:26alien to you. Unterminated string
- 1:00:29literal detected at line one. Pretty
- 1:00:32abstract, right? This is a great spot.
- 1:00:35This is a great time to plug that into
- 1:00:38your AI assistant or just plug it into
- 1:00:40chat GPT and ask, look, I'm writing a
- 1:00:42Python program and I get this error.
- 1:00:45What does this mean? And if you show
- 1:00:47your code even better, it will tell you
- 1:00:49exactly what went wrong and how to solve
- 1:00:52it. And over time, you'll get a much
- 1:00:53better feel for quickly spotting errors
- 1:00:56and what went wrong. And your IDE will
- 1:00:58also help with that. And in this case,
- 1:01:00we could have easily prevented the error
- 1:01:02because our IDE already signals that we
- 1:01:04need to close the string. And now
- 1:01:06throughout this course, if you follow
- 1:01:07along, you're going to make a lot of
- 1:01:09errors. And that's the goal, right?
- 1:01:11Because with that, you'll become more
- 1:01:12and more used to it. That's also why I
- 1:01:14keep hammering on make sure to write
- 1:01:17everything out and not just simply hit
- 1:01:19copy paste on all of the examples in
- 1:01:21there because then out of the box they
- 1:01:22will be good but you need to train
- 1:01:24yourself in order to spot the
- 1:01:26differences to spot the spaces to spot
- 1:01:28the quotes. So make sure to type it out
- 1:01:30on the keyboard make those errors
- 1:01:32correct them and continue. All right now
- 1:01:34it's time to get into one of the most
- 1:01:36fundamental concepts in all of
- 1:01:38programming not just the Python
- 1:01:39programming language but in general and
- 1:01:41that's variables. And variables allow
- 1:01:43you to store and name your data. So
- 1:01:46coming over to the hello.py file over
- 1:01:49here. Let's say you're building a
- 1:01:50program where you want to take in some
- 1:01:52user information. So you want a name and
- 1:01:55let's say we set that to Alice. This is
- 1:01:58Python's way of setting a variable
- 1:02:01called name and we set that equal to
- 1:02:03Alice which in this case is a string. We
- 1:02:07can now run this program and if we now
- 1:02:10come over here and we make a reference
- 1:02:12to name under the hood Python now
- 1:02:14understands that name is equal to Alice
- 1:02:18and similar I can for example set H to
- 1:02:21let's say 25. So now if I go in here and
- 1:02:24I just run H which I do here with the
- 1:02:26interactive session which I can do by
- 1:02:28putting it on another line hitting shift
- 1:02:30enter but I can also do it by taking the
- 1:02:32cursor and just selecting this part. So
- 1:02:35again I'm using this with the arrow keys
- 1:02:37and then I'm holding in shift. I select
- 1:02:39this and I do shift enter to see under
- 1:02:41the hood what the variable is that is
- 1:02:44assigned over here. So we can set age to
- 1:02:4625 and we can also overwrite things
- 1:02:49that's why they are called variables. So
- 1:02:51if I for example now say name equals and
- 1:02:54now I for example say Dave and I run
- 1:02:57this shift enter we can now check and
- 1:02:59now Python understands that name is
- 1:03:01equal to Dave. So this is how we can
- 1:03:04pass data around and we can do that with
- 1:03:06all kinds of data. We can do that with
- 1:03:08strings which you see over here. We can
- 1:03:10do that with numbers and we can even do
- 1:03:12it with uh true or false values. So we
- 1:03:15can for example set is student and then
- 1:03:17we set that equal to true which is also
- 1:03:20something we can do in Python. So the
- 1:03:22things to keep in mind here about the
- 1:03:23syntax about working with variables is
- 1:03:25that on the left you have the variable
- 1:03:27name. Then you use the equal sign which
- 1:03:30means you store the value on the right
- 1:03:32in the variable on the left. We store
- 1:03:35Alice on the variable name and Alice is
- 1:03:39the value that we're storing. Now there
- 1:03:41are also some rules that you should keep
- 1:03:42in mind when working with variables. So
- 1:03:45here you see all kinds of variable and
- 1:03:47variable names that are allowed. So we
- 1:03:49can use an underscore, we can use a
- 1:03:50capital letter, we can use a number in
- 1:03:52here, we can even use an underscore over
- 1:03:54here. But there are also some things
- 1:03:55that are not allowed. So for example, a
- 1:03:57variable name can start with a number.
- 1:03:59It cannot use a hyphen or it cannot use
- 1:04:01a space. And you can also not use
- 1:04:03certain Python keywords. And we can
- 1:04:05validate that by coming over here,
- 1:04:07getting rid of this, and then say to age
- 1:04:10is 30. When I run this, you'll get a
- 1:04:13syntax error. So we get an invalid decim
- 1:04:16decimal literal. This is not possible.
- 1:04:19We can also do new age is 30. This will
- 1:04:24also not work. So here is an example.
- 1:04:26Things that are allowed, things that are
- 1:04:28not allowed. And to make that even
- 1:04:30simpler for you, in the Python naming
- 1:04:32conventions, we use lowercase letters
- 1:04:34with underscores between words. This is
- 1:04:37also called snake case. So when we for
- 1:04:39example want to spell out a first name
- 1:04:41is Alice or a user age you can see that
- 1:04:44instead of doing a space or a hyphen we
- 1:04:46use an underscore. So if I do first
- 1:04:48underscore name and then I set that to
- 1:04:51Alice I can run this and it will be no
- 1:04:54problem. We can just store this similar
- 1:04:56to user age equals 25. That's all fine.
- 1:05:01So the important thing to keep in mind
- 1:05:02here is that there is a difference
- 1:05:04between the strict rules of Python. So
- 1:05:06when it will actually throw an error
- 1:05:08versus the style guides because within
- 1:05:11Python it's totally fine to use capital
- 1:05:13letters here in the middle of a variable
- 1:05:14which is called camel case. I can do
- 1:05:17that right now. So first name with
- 1:05:19capital N equals Alice. I can run that
- 1:05:23and it will not throw an error. But this
- 1:05:26is just a style thing. This is not
- 1:05:28something we do in Python. So to make
- 1:05:30that simple when we talk about variables
- 1:05:32lowerase and when you need to create a
- 1:05:34space use an underscore. And now, as we
- 1:05:36go through all of these examples, I want
- 1:05:38you to know that in the handbook,
- 1:05:40there's almost always a little bit more
- 1:05:41information that we don't cover in the
- 1:05:43video. So, common mistakes, things that
- 1:05:45go wrong, more examples, but otherwise,
- 1:05:47it would be a 10-hour long video. So, I
- 1:05:49cover the basics in here, what you need
- 1:05:51to know. But if you're still like, hm,
- 1:05:52variables, I don't still quite get it.
- 1:05:55Make sure to go through the handbook and
- 1:05:57then ask follow-up questions to ChatBT
- 1:06:00or your favorite AI assistant if you
- 1:06:02still need additional help. Next, let's
- 1:06:04get into comments. So, what are they and
- 1:06:06how do we use them? So, if we come back
- 1:06:09to our script over here, you can see
- 1:06:11that in here we have the first name, we
- 1:06:12have the username. This is code that we
- 1:06:14execute. But Python also allows us to
- 1:06:17put human readable comments in our
- 1:06:20scripts that Python will simply ignore.
- 1:06:23It will not do anything with what we put
- 1:06:25in there. We can put anything we want in
- 1:06:27that case. And we can use descriptions.
- 1:06:29We can explain certain bits and pieces.
- 1:06:31We can add to-dos or reminders. And this
- 1:06:34is a way for us as developers to not
- 1:06:36only uh help our future selves, but also
- 1:06:39potentially other people with which we
- 1:06:42work on the same project. And the way we
- 1:06:44do that within Python is by doing a
- 1:06:46hashtag. So if you type a hashtag,
- 1:06:49you'll see that on that whole line
- 1:06:51starting with the hashtag, it will be
- 1:06:53grayed out. So I can start typing in
- 1:06:55here and I can say this is a comment in
- 1:06:59Python. So you can see it is grayed out.
- 1:07:01And if I now select all of this and I
- 1:07:04run this, nothing will happen with this.
- 1:07:06It won't output anything similar to what
- 1:07:09we have with Alice and the user age. I
- 1:07:11can for example put a print statement
- 1:07:13over here to actually show you. If we do
- 1:07:16the user age and add that to it as well,
- 1:07:19I can execute this whole line and it
- 1:07:21will print 25 because we have instructed
- 1:07:24Python to print this. Similar to this,
- 1:07:27we can also run this in the terminal and
- 1:07:29you'll find that the output of this
- 1:07:31script will just be 25. So there will be
- 1:07:34no trace of this comment whatsoever. So
- 1:07:37we can do that on a whole line like
- 1:07:39this. But we can also do it after uh at
- 1:07:42the end of a line. So if I'm here and I
- 1:07:44want to write a comment saying this is
- 1:07:46the first name, which in this case
- 1:07:49doesn't really add a lot of value, but
- 1:07:51let's say you wanted to give a little
- 1:07:52bit more clarification. This also
- 1:07:54totally works. We can also do multiple
- 1:07:58lines by coming over here saying this is
- 1:08:00another comment. This all works. No
- 1:08:03problem. Now, if you want to write
- 1:08:05comments over multiple lines, there's
- 1:08:07actually one other way that you can do
- 1:08:09this and that is by using triple quotes.
- 1:08:11So, another way to write a comment is
- 1:08:13doing it like this. You'll see three
- 1:08:15opening quotes and then I can go over
- 1:08:17here and I do three closing quotes. and
- 1:08:20anything that I write in between here.
- 1:08:22For example, this is a multi-line quote
- 1:08:26that can go on and on and on. And in
- 1:08:29this case, you don't have to start every
- 1:08:31line with a hashtag. And this helps for
- 1:08:34readability. You'll also find that this
- 1:08:36is green instead of the grade out
- 1:08:39version in here. So, typically, if you
- 1:08:41want to do short and snappy comments to
- 1:08:43just give a little bit of instruction or
- 1:08:45clarification, you use the hashtags. If
- 1:08:47you want to have more explanatory
- 1:08:50paragraphs to later also describe
- 1:08:52functions and classes and what they do
- 1:08:54and what kind of data you need to put in
- 1:08:56there, then you'll use multi-line
- 1:08:58comments with the triple quotes. And as
- 1:09:00a rule of thumb, you want to use
- 1:09:01comments to explain the why, not the
- 1:09:04what. Because since Python is relatively
- 1:09:07easy to read and it usually reads like
- 1:09:09plain English, you for example, here's
- 1:09:11here's a bad example. So let's say you
- 1:09:13have you want to calculate a total and
- 1:09:14you take the subtotal and you m you
- 1:09:17multiply it to calculate the text and
- 1:09:19then a comment here is multiply subtotal
- 1:09:22by 1.6
- 1:09:23like we can already tell that by reading
- 1:09:25this line. But over here in the top
- 1:09:27example, we for example have a tax
- 1:09:29calculation. And if if people are from
- 1:09:31California, I I don't think I think this
- 1:09:33is off. But let's assume this was
- 1:09:35correct. You explain the the calculation
- 1:09:37why you're doing this. So someone
- 1:09:39looking into this code might might be
- 1:09:41like, okay, what's this number? Oh, it's
- 1:09:42to calculate the sales tax. So that's a
- 1:09:45good reason why instead of explaining
- 1:09:47what. Okay. And up next, we're going to
- 1:09:50talk about data types. So these are the
- 1:09:52different kinds of information that we
- 1:09:55can store in Python and when we were
- 1:09:58experimenting with the variables right I
- 1:10:00already brief briefly mentioned like
- 1:10:02look it can be a string which is text it
- 1:10:04can be a number it can be a true or
- 1:10:05false so let's cover all of the options
- 1:10:07that are there because that's also a
- 1:10:10fundamental concept that you need to
- 1:10:12understand and let's start with numbers
- 1:10:15so under the hood there are actually two
- 1:10:17types of numbers when you are working
- 1:10:19with Python and with most programming
- 1:10:21languages If you're new to programming,
- 1:10:22this is always a little bit weird like
- 1:10:24why why is it different? There is a
- 1:10:26difference between what we call integers
- 1:10:27and floats. And integers are simply
- 1:10:30whole numbers without decimals. So 25.
- 1:10:33And we could set h equals 25. And this
- 1:10:36would be considered an integer or floats
- 1:10:38which have decimal points. So 19.99
- 1:10:43that's a float. Now in the real world in
- 1:10:45practice, Python is so flexible that you
- 1:10:48often don't really have to think about
- 1:10:50this. and you can just write your
- 1:10:52programs as is and Python will
- 1:10:54seamlessly convert one into the other.
- 1:10:56But under the hood there is a difference
- 1:10:58in how they are stored in memory. Uh why
- 1:11:01is this? It simply has to do with
- 1:11:03efficiency about how the computer like
- 1:11:05can process it. But that's all you need
- 1:11:07to know for now. So what can we do with
- 1:11:10numbers, right? Well, we can apply basic
- 1:11:12math operation. It works similar to how
- 1:11:15you would use a calculator. So let's run
- 1:11:18through all of the examples and show you
- 1:11:21how that works. So if we come in here
- 1:11:23and we can literally like use this as a
- 1:11:26calculator. So we can do 5 + 5 and we
- 1:11:29can run this shift enter. You'll see
- 1:11:30this 10. We can do a minus it will be
- 1:11:33zero. We can do multiplication with an
- 1:11:35asterisk. We can do a division.
- 1:11:39Everything works like this. And we can
- 1:11:41also store that into variables. Right?
- 1:11:43So let's say we have our total and we
- 1:11:45want to calculate. we have 10 and we do
- 1:11:48it minus 7 and we come in here we store
- 1:11:50that. So now we do we perform the
- 1:11:53calculation and we store it in the
- 1:11:55total. I come in here and I run that we
- 1:11:58can see three. Now again as I go through
- 1:12:00this just remember because we're using
- 1:12:02the interactive session instead of
- 1:12:04having to write out print all the time
- 1:12:06and print what the total is I can come
- 1:12:08in here and just select total and run
- 1:12:10it. And we can also do powers. So power
- 1:12:13equals we could do 10 and then we use
- 1:12:14double asterisk. let's say to the power
- 1:12:16of two and then this should be 100. So
- 1:12:20give it a couple of tries. Make sure to
- 1:12:22play with this and also to get used to
- 1:12:24typing to selecting the pieces that you
- 1:12:28want to see and just get comfortable
- 1:12:29with this interactive window over here
- 1:12:32knowing at all times that this is quite
- 1:12:34a unique way of working with Python. And
- 1:12:36if I run this script like this, you'll
- 1:12:38see nothing is happening. There's no
- 1:12:40output because there are no print
- 1:12:42statements. So if I were to print the
- 1:12:44power in here, I would need to like
- 1:12:48explicitly write that out, say print,
- 1:12:50and then run it in the terminal session
- 1:12:52like a lot of other examples you'll find
- 1:12:54online do. Then you see the 100 over
- 1:12:56here. But with the interactive window,
- 1:12:58we can just start it up. Come here to
- 1:13:00the total, say, I want just this. I want
- 1:13:03just this. And I want to see the power.
- 1:13:05And here in the beginning, I know that
- 1:13:06I'm repeating myself with this, but you
- 1:13:08need to get those reps in in the
- 1:13:09beginning. you need to see like how I go
- 1:13:11through the code and select things and I
- 1:13:13am so used to this for me it's seamless
- 1:13:15I'm using the arrow keys I'm using shift
- 1:13:17but I'm I totally understand that when
- 1:13:19you go through this you might be like oh
- 1:13:21what how is he doing that so fast so
- 1:13:23follow along run the examples try and
- 1:13:25build your own calculator see what it
- 1:13:27does and as you go through all of those
- 1:13:28examples you'll build the muscle memory
- 1:13:30to do it just like I do all right so
- 1:13:32those are numbers and the basic math
- 1:13:34operations that you can do now let's
- 1:13:37continue to the next data types And
- 1:13:39those are strings. So strings is just a
- 1:13:42fancy word of for text. Any type of text
- 1:13:45we can put into a string. And in Python
- 1:13:48we do that between quotes. Now Python
- 1:13:50doesn't care actually if you use single
- 1:13:53or double quotes. You just got to be
- 1:13:55consistent with this. I always use
- 1:13:57double quotes. So you can also just do
- 1:13:59that. Totally fine. Just be consistent.
- 1:14:02And now there are a lot of things that
- 1:14:03you can do with strings. So let's run
- 1:14:05through a couple of examples. So I'm
- 1:14:07going to create a string here. And I'm
- 1:14:09going to say my name is Dave. This is a
- 1:14:13string over here. And we can even add
- 1:14:15some comments just showcase everything
- 1:14:18that we learned. And now I can select
- 1:14:20all of this and run it. We'll open up
- 1:14:22the session over here. So this is how we
- 1:14:24create a string. And in here we can put
- 1:14:27anything really. We can even go as far
- 1:14:29as let's say let's create my long
- 1:14:33string. We can also use triple quotes.
- 1:14:36And remember how we could also do that
- 1:14:38with comments, right? But if you do it
- 1:14:40after a equal sign, we can put in a long
- 1:14:43string. So you can say my name equals
- 1:14:46Dave and um my last name is Eilar. So in
- 1:14:53this way, let me clear up the capital
- 1:14:55letters over here. We can do this string
- 1:14:57and this is one line, but we can also
- 1:14:59have a long string. And if we now show
- 1:15:02and look what's in here, you can see
- 1:15:04that we have multiple lines in here. So
- 1:15:07that you can see by this uh back slashn
- 1:15:10that signals that it's a new line which
- 1:15:12actually means if we print that. So we
- 1:15:14can print my long string it will show
- 1:15:17and it will print that on a new line. So
- 1:15:20those are the two ways that we can
- 1:15:22specify a string and put it into a
- 1:15:26variable. Now with the string as a data
- 1:15:29type there are a lot of operations that
- 1:15:30we can do. So remember when we had
- 1:15:33numbers right integers or floats we
- 1:15:35could perform math operations. So
- 1:15:38strings have similar features. So one
- 1:15:41thing that we can do is for example
- 1:15:42first name let's set that to first name
- 1:15:45equals Dave and then we say last name
- 1:15:48equals Ear. What we can now do for
- 1:15:51example is we can set full name equals
- 1:15:54and then we do first name and then we do
- 1:15:57a plus sign. So we can actually perform
- 1:15:59some kind of like math operations on
- 1:16:01strings and then we say we want a space
- 1:16:04in between. So I do an empty string over
- 1:16:06here with just a space. Then do another
- 1:16:09plus sign and then I do last name and
- 1:16:13write that in here. Let me make this a
- 1:16:14little bit smaller for you so you can so
- 1:16:16you can see the full line. You can see
- 1:16:18everything. So now if I run just this
- 1:16:20line you can see first name is not
- 1:16:22defined. Oh yeah this is a very common
- 1:16:24error because I forgot to uh run these
- 1:16:27lines of code. So first I need to store
- 1:16:29this in memory. So now you can see over
- 1:16:31here Python understands okay first name
- 1:16:33is Dave and similar to last name is
- 1:16:35Eilar. And now when I run this whole
- 1:16:38line you can see that this will run and
- 1:16:40I can get the full name out of it. Okay.
- 1:16:43So now we're performing what's called
- 1:16:45string manipulation. And there are a lot
- 1:16:47of actions going on here. So try to
- 1:16:49follow along. Try to put everything in.
- 1:16:52Try to run them line by line and then
- 1:16:54look at what's in the variables. Try to
- 1:16:56select them. Get a feel for working with
- 1:16:59this programming language and the
- 1:17:00interactive window. Now what we can also
- 1:17:03do is we next to the plus sign we can
- 1:17:06also for example let's say we have an
- 1:17:08asterisk and we can say or let's let's
- 1:17:11actually do a dash. We can do a dash and
- 1:17:14we can say long dash equals and then we
- 1:17:18do the dash and we do it times. Let's do
- 1:17:20it times 10. We save that. So let's see
- 1:17:23what we have over here. Now we have well
- 1:17:25we I think we can do longer. Let's
- 1:17:27actually do um 30. So now you can see we
- 1:17:31have a really long dash. So now if you
- 1:17:33for example wanted to create a program
- 1:17:34and you want to display some
- 1:17:37information. So first let's say you
- 1:17:39print and then you do we do the full
- 1:17:42name. So we can print the full name and
- 1:17:44then afterwards we print the long dash.
- 1:17:48You can see if we do it like this. There
- 1:17:50we go. And now we can tailor it to kind
- 1:17:53of like the length. I think it will be
- 1:17:55around 12. So now you can see we have
- 1:17:58our name and a dash underneath that. So
- 1:18:00if you want to do some print statements
- 1:18:01or logging this can be helpful. So there
- 1:18:04are things that we can do with strings
- 1:18:06as well. Another operation is we can
- 1:18:09also check the length of a string. And
- 1:18:12this is using a Python built-in function
- 1:18:15similar to print. So if I type print,
- 1:18:17you will see that it turns blue, right?
- 1:18:19This means that this is a built-in
- 1:18:21function from Python. And how do you
- 1:18:23know if it's built in? In the beginning,
- 1:18:24you don't know. That's why you're going
- 1:18:26through this course. As as you'll find
- 1:18:28me explaining variables, sometimes there
- 1:18:30are just things off the shelf that we
- 1:18:32can use. And so getting the length of a
- 1:18:34string is also a built-in function, and
- 1:18:35that's through length. So not the
- 1:18:37complete length but we shorten it. And
- 1:18:38then for example we can plug in the long
- 1:18:41dash in here. And if we run that you'll
- 1:18:44find that it says 12. So what this
- 1:18:46function does is instead of just print
- 1:18:49instead of just printing it it will take
- 1:18:51the string and it will calculate how
- 1:18:53long it is. So if I take the full name
- 1:18:56and do that you'll find that my full
- 1:18:59name. So that's the first name plus the
- 1:19:02space in here plus the last name equals
- 1:19:0513. So that's a length of 13. Whereas if
- 1:19:08I plug in my first name, the length
- 1:19:10should be four because my name has four
- 1:19:12letters. So that's a built-in function
- 1:19:15that you can use. Now there are many
- 1:19:17many built-in functions and we'll cover
- 1:19:20some of them and as you progress on your
- 1:19:22Python journey, you'll encounter more
- 1:19:23and more of these. So when you're trying
- 1:19:25to solve a particular problem and you
- 1:19:26ask JBT, how do I do this in Python?
- 1:19:29Sometimes it will tell you look there's
- 1:19:30actually already a function or later a
- 1:19:32package for this that you can use. Now
- 1:19:35that's all you need to know for now
- 1:19:37about using strings. We can store text,
- 1:19:40we can manipulate it and we can do
- 1:19:42things with it to process information.
- 1:19:44Now next let's get into the third data
- 1:19:47type and those are booleans. So booleans
- 1:19:50are simply true or false. They can just
- 1:19:53be that and they are very handy in
- 1:19:55programming to make decisions because
- 1:19:58based on whether something is true or
- 1:20:00whether something is false we can make
- 1:20:02decisions and we can route our program
- 1:20:04or our data either to for example to the
- 1:20:07left or to the right. Now and one common
- 1:20:09example of this is so we with data
- 1:20:11luminina we build a lot of customer care
- 1:20:13automation systems and one of the steps
- 1:20:15that we have in there is we let an AI
- 1:20:18decide whether an incoming ticket should
- 1:20:20be escalated to a human. So there's a
- 1:20:23whole processing logic behind that but
- 1:20:25ultimately what the AI decides is
- 1:20:27escalate is true or false and when it's
- 1:20:30set to true meaning it should escalate
- 1:20:33we route it to a human to refute and if
- 1:20:35it's false the AI can handle it
- 1:20:37themselves. So th those are booleans and
- 1:20:39we literally write it out with like a
- 1:20:41true or a false and we use a capital
- 1:20:43letter. That's a syntax thing that you
- 1:20:45need to remember. So if I come in here
- 1:20:47and follow the examples. So let me clear
- 1:20:50this up. We can say let's say we have a
- 1:20:52user status and is uh logged in. If we
- 1:20:55set that to true, you will see that it
- 1:20:57will turn orange. This means this is the
- 1:21:00actual boolean the boolean value within
- 1:21:03Python. If I don't do the capital
- 1:21:06letter, you'll find that it's it doesn't
- 1:21:09turn orange and it will give the
- 1:21:11squiggly lines where it says look, you
- 1:21:14should not do this. It should either be
- 1:21:16true or it should be false. So those are
- 1:21:19boolean values. So right now I can say
- 1:21:22is the user logged in? This is false.
- 1:21:24Now booleans often come from creating
- 1:21:27comparisons. So we can do a direct
- 1:21:30assignment which is what we just did,
- 1:21:32right? So we can say is true and we can
- 1:21:35literally just set that to true. So that
- 1:21:37is a direct assignment. But we can also
- 1:21:40perform conditional logic to decide
- 1:21:42whether something is true or false. So
- 1:21:44if you look in the example over here you
- 1:21:46can do a comparison. So let's go through
- 1:21:49this and let's say someone is 18. So we
- 1:21:52have age is 18 and then we create a
- 1:21:54variable called can vote and then we do
- 1:21:56a comparison where we say look we take h
- 1:22:00and we check whether it's greater than
- 1:22:02or equal to 18 and we store that can
- 1:22:07vote is true because we have set age to
- 1:22:10true. So this is another like very cool
- 1:22:13way you can where you can play with the
- 1:22:14interactive session by just selecting
- 1:22:16this over here. So again I'm using the
- 1:22:17arrows arrows. I'm holding shift and
- 1:22:20then I select just this piece over here.
- 1:22:22And now I can check this. This is now
- 1:22:24true. But if I for example set this to
- 1:22:2816. So age over here age now is 16. And
- 1:22:33I do a comparison whether it's greater
- 1:22:35or equal to 18. You'll find it is now
- 1:22:38false. And now if I run the entire line
- 1:22:40I can now set can vote to false. So, do
- 1:22:43you already get a feel for what this is
- 1:22:46like and how this works? So, now the uh
- 1:22:48comparison operators in here. That's
- 1:22:51just one of those syntax things that you
- 1:22:53need to see a couple of times in the
- 1:22:56beginning. So, let's actually see what
- 1:22:58we can do over here. So, you have things
- 1:23:00like equal, which we do with double uh
- 1:23:03equals. So, remember the assignment of a
- 1:23:05variable is with one equal sign. But if
- 1:23:10we do two equal signs, we actually form
- 1:23:13a comparison. So if we let's let's again
- 1:23:16let's set this to 18 and then let's see
- 1:23:20we make another like we do is 18 is a
- 1:23:23variable and then we check whether age
- 1:23:26is equal to 18. So we set the age now
- 1:23:29it's 18 look then we perform this it's
- 1:23:32true. Now we do this not true. So these
- 1:23:35are ways that we can perform really any
- 1:23:38type of comparison that you want to
- 1:23:40make. So coming back over here, is it
- 1:23:42equal to? We can also is it not equal
- 1:23:44to? So we invert it. We do that using an
- 1:23:47exclamation mark. Then we have greater
- 1:23:49and less than. So we could use greater
- 1:23:51than 20, less than 30 or greater than or
- 1:23:54equal or less or equal. So these are all
- 1:23:57the types of common operators, right? If
- 1:23:59you ever built some kind of like logic
- 1:24:02or worked with a program or worked with
- 1:24:04something like sapier or make.com or nat
- 1:24:06these are very common operations and
- 1:24:08this is just a way this is just a python
- 1:24:11syntax to write that out. So this is
- 1:24:13something you won't remember right now.
- 1:24:15So this is always something you have to
- 1:24:17refer to. That's also really one why I
- 1:24:19wanted to create this handbook. So you
- 1:24:20can bookmark this and whenever you're
- 1:24:22working with variables you can come here
- 1:24:24in here check it out or of course simply
- 1:24:27ask AI and it will also tell you what to
- 1:24:30do. Okay, so those are booleans and
- 1:24:32again as with any section if you're
- 1:24:34running into errors make sure you check
- 1:24:36out the common mistakes. All right and
- 1:24:38up next we are going to the section
- 1:24:40working with data. So we already covered
- 1:24:43the math, right? The arithmetic
- 1:24:44operators to do simple math and to
- 1:24:47perform calculations. And one thing you
- 1:24:49should know about Python is that it it
- 1:24:52follows the same rules really when it
- 1:24:54comes to arithmetics that you would use
- 1:24:57and on your math math exams in high
- 1:24:59school, right? Or when you're using a
- 1:25:00calculator. So for example, the
- 1:25:03multiplication becomes for an addition.
- 1:25:05So this will be 14 and not 20. And if
- 1:25:07you use parentheses, that's how you can
- 1:25:09prioritize certain operations to do them
- 1:25:12before. So, similar to what it was like
- 1:25:14with math in Python, it works the same
- 1:25:16way. Then we have the comparison
- 1:25:17operators, which I just shown you. And
- 1:25:20feel free to stop here and take some
- 1:25:22time to play with these. I'm quickly
- 1:25:24going over this because I want to get to
- 1:25:26the logical operators because we can
- 1:25:29also combine boolean values and
- 1:25:31conditions and we can even include the
- 1:25:34words and and or. So let's have a look
- 1:25:36at what that looks like. So let me
- 1:25:39actually take this snippet over here and
- 1:25:41we're going to play with that. So let's
- 1:25:43see over here we have h equals 25 and
- 1:25:46let me actually I can zoom out and I can
- 1:25:48clear all of this for you and then zoom
- 1:25:50in a little bit. So we have age is 25.
- 1:25:53We have a license which is true. And now
- 1:25:56we perform a check and we want to
- 1:25:57perform a check and both must be true.
- 1:26:00So to determine whether someone can
- 1:26:03drive both the age needs to be like in
- 1:26:05the US needs to be greater or equal than
- 1:26:0816 and also has a license should be true
- 1:26:11and this is also one of the cool things
- 1:26:12about Python right because look at how
- 1:26:15easily we can read this it's almost pure
- 1:26:18English so let's go through this can
- 1:26:20drive we set that equal to and then we
- 1:26:23perform the first operation so age is
- 1:26:25greater than or equal to 60 is that the
- 1:26:28case it's 25. So let's check that. Let's
- 1:26:32just run this line. That is true. Okay.
- 1:26:35Now we see end over here. And we have
- 1:26:38has license. So has license is set to
- 1:26:41true. So what now will happen if we use
- 1:26:44the end? This line over here. This will
- 1:26:48output true if both of the clauses in
- 1:26:52here are true, which is the case. So if
- 1:26:54I now run this, you'll find that this is
- 1:26:56true. And if we then print can drive it
- 1:26:59will be set to true. But if we now set
- 1:27:02this to false. So someone is 25. So they
- 1:27:06are still over 16 true but has a license
- 1:27:09is false. And now we run this and print
- 1:27:13can drive is false. So you can see how
- 1:27:15we can now start to build this logic
- 1:27:17right. And similar we can also do or and
- 1:27:20this means it's either one of the two
- 1:27:23should be true. So if we do it like
- 1:27:25this, they can still drive because
- 1:27:27they're 16. This is maybe in like some
- 1:27:29weird country or state where you can
- 1:27:31either have a license or 16 and you're
- 1:27:33good to go. So coming back to the
- 1:27:35examples over here, you'll find that you
- 1:27:38can combine these in all kinds of ways.
- 1:27:40So whenever you're trying to solve a
- 1:27:42problem, even if you want to stack 10
- 1:27:45conditions and very complex combinations
- 1:27:48of all kinds of variables that you can
- 1:27:50think about using all of these operators
- 1:27:53equal to, greater than, and or and using
- 1:27:56these truth tables and understanding how
- 1:27:59they work, you can see that you can
- 1:28:01almost like create any kind of
- 1:28:02decision-making logic. So go through
- 1:28:04this and here can here you see
- 1:28:06understanding the truth table. So that
- 1:28:07this is what I was going uh for true and
- 1:28:10true will be true and this is using the
- 1:28:12and this is using the or and not is
- 1:28:14another one. So this is how you can flip
- 1:28:16it. So let me actually show you what
- 1:28:18that looks like. So let's see if set has
- 1:28:21a license is set to true. Let's see.
- 1:28:23Let's do that. I can also now for
- 1:28:25example do not has license. And now if I
- 1:28:28run this this will say false because has
- 1:28:31a license is true. And when when I
- 1:28:32invert that it turns into false. So
- 1:28:35let's do another example here. Let's do
- 1:28:36drunk. Let's say drunk is equal to true.
- 1:28:41So can drive now becomes age should be
- 1:28:44greater than or equal than 16 and has
- 1:28:50license. And here's the thing. You can
- 1:28:52also do equals true. But you don't need
- 1:28:55to do this. So this is like as you type
- 1:28:58it out, you might want to do this. But
- 1:29:00since has license is already a boolean
- 1:29:02value, you don't have to make a direct
- 1:29:05comparison with this. But both will
- 1:29:07work. But let's for the sake of
- 1:29:08simplicity leave it out. And then also
- 1:29:11we do the third clause in there. We
- 1:29:13literally say and not drunk. Okay. So
- 1:29:17now what you can see over here, let me
- 1:29:19actually zoom out a little bit so you
- 1:29:21can see everything. Now if I run this
- 1:29:23can drive like make sure we have
- 1:29:25everything in here in memory. Now you
- 1:29:28can see if we run this and then we do
- 1:29:30can't drive is false because they're
- 1:29:32drunk. They're 25. They have a license
- 1:29:35but they're drunk and they cannot drive.
- 1:29:36If we do it in false, they can't drive.
- 1:29:38Now here was one more Python trick that
- 1:29:40you'll often encounter. There are also
- 1:29:42shortcut assignments. So when you have a
- 1:29:45score, let's say score is 10. So I come
- 1:29:47in here, let's clear everything out.
- 1:29:49Let's say score equals 10. And you want
- 1:29:53to add something to that. You could say
- 1:29:55score equals score. and then we add
- 1:29:58five. So now score will be 15. You can
- 1:30:01also directly do score plus equals five.
- 1:30:05And then we add another five to the
- 1:30:07score and now it's 20. And we can do
- 1:30:09this over and over and over again. So if
- 1:30:11I run this a couple of times, you can
- 1:30:13now see score is 90. So this is a simple
- 1:30:16shortcut assignment where we don't have
- 1:30:17to do this redundant like score equals
- 1:30:19score + 5, but we can do it directly and
- 1:30:22this works with almost all math
- 1:30:25operators. All right. So, those were
- 1:30:26some common operators. Now, let's get to
- 1:30:29into the string manipulation. And I want
- 1:30:31to show you two more things when it
- 1:30:34comes to working with strings that can
- 1:30:36be that are very useful, especially when
- 1:30:38you're working with AI and when you're
- 1:30:40working with prompts. So, we already saw
- 1:30:42that you can use the plus sign, right?
- 1:30:44But now I want to show you frings. So,
- 1:30:47let's see what they are and why they are
- 1:30:50so common in uh when you're working with
- 1:30:52AI and language models. So let's say we
- 1:30:53have our string and let's say we have uh
- 1:30:56let's say we do hi there my name is
- 1:31:01Dave. We can run this. We have the
- 1:31:04string and we have their hi name there
- 1:31:05my name is Dave. But let's say you have
- 1:31:07a program and you don't want to hardcode
- 1:31:10this name but you want to do it based on
- 1:31:13the username right? So let's say name
- 1:31:15equals Dave and then oh I should put
- 1:31:18that in quotes right to make it a
- 1:31:20string. How can we now make this in such
- 1:31:22a way where we make this dynamic and we
- 1:31:25replace this with the variable over
- 1:31:27here? So now depending on who is
- 1:31:30interacting with the system, it will
- 1:31:32give them a different greeting. And this
- 1:31:34is used all the times when you are
- 1:31:37working with AI models and prompts, you
- 1:31:38want to dynamically inject information
- 1:31:40that you retrieve from another system,
- 1:31:42store that in a variable and then put it
- 1:31:44in a string. So the way we do that in
- 1:31:47Python is through what they call
- 1:31:49fstrings. And this is again this this is
- 1:31:52now a syntax thing because this is just
- 1:31:54something you need to remember. There's
- 1:31:56not really any logic behind it, but it's
- 1:31:58called fstrings. And we literally put an
- 1:32:00F before it. So you have the string, you
- 1:32:02have the quotes, and you just put an F
- 1:32:04in here. And when we plug that F in
- 1:32:06here, what we can now do is we can come
- 1:32:08in here and we can use curly brackets
- 1:32:11and we can now plug in any variable. So
- 1:32:15you can now see that this is a string
- 1:32:17and it's not giving us any errors. And
- 1:32:19if I now run this and I print this, you
- 1:32:21will see that if I move my oh wait, let
- 1:32:24me actually move myself to the left side
- 1:32:27so you can actually see something. So
- 1:32:29here you can now see my name is Dave.
- 1:32:31And if we change this to I don't know
- 1:32:34John and we run this you'll find that
- 1:32:36the string is now hi there my name is
- 1:32:39John. So that's the notion of fstrings.
- 1:32:42Super useful. And let's see if I for
- 1:32:45example get rid of this you can see
- 1:32:47right now if I run this and print it you
- 1:32:50can see that it literally like hardcodes
- 1:32:52the curly brackets in here. It it will
- 1:32:54be orange. So it will Python will
- 1:32:56indicate that it recognizes that you
- 1:32:58want to do something there but it will
- 1:33:00literally just print it out exactly as
- 1:33:02is. So that's why you need to put the f
- 1:33:04there and then it works. Now then
- 1:33:06another thing that I want you to know
- 1:33:08about strings is that in Python you have
- 1:33:11a lot of what they call string methods.
- 1:33:14So these are methods functions that you
- 1:33:17can apply to a string and it will
- 1:33:20perform an action. And the way you do
- 1:33:22this is so here's an example. So you
- 1:33:24have text, you have the string in here
- 1:33:26and instead of putting it before it, so
- 1:33:29print and then using the the brackets,
- 1:33:31you directly take the string variable,
- 1:33:33you do a dot and then you apply the
- 1:33:36string method by typing out the method
- 1:33:38and then using the brackets in here. So
- 1:33:40let's follow uh let's follow along with
- 1:33:42this to get a feel for what that is. So
- 1:33:45let's say let's come over here. We have
- 1:33:47Dave and we can do name. We do dot lower
- 1:33:51and then we do the parenthesis. And now
- 1:33:54you can see this is my name in lowerase.
- 1:33:56But I can also do my name in uppercase.
- 1:34:00Let's see in uppercase. And I can even
- 1:34:03do let's say if we have a sentence. So
- 1:34:05you could for example do sentence equals
- 1:34:09hi my name is Dave. You can even do a
- 1:34:14title. So you can do sentence.title
- 1:34:17and then it will apply title case if I
- 1:34:19store it in memory. And there we go. So
- 1:34:22you can see it will capitalize all of
- 1:34:24the first letters. So these are called
- 1:34:26string methods. And I'm going to show
- 1:34:28you one more example over here. I'm not
- 1:34:30going to walk through everything but you
- 1:34:32can even see if you have this message
- 1:34:34over here. So I love the Python
- 1:34:35programming language. We can also for
- 1:34:38example uh create some boolean logic
- 1:34:40around this where we can say starts with
- 1:34:43ends with and that gives us true or
- 1:34:45false values. We can find certain
- 1:34:48phrases within a sentence. We can count
- 1:34:50the occurrence or number of times Python
- 1:34:53is occurring in this message and we can
- 1:34:55even replace certain parts. So here if
- 1:34:58we have the message and we replace
- 1:34:59Python with JavaScript it will now print
- 1:35:03I love JavaScript programming with
- 1:35:05JavaScript. now and I totally understand
- 1:35:06that that is a lot of information right
- 1:35:08and you definitely don't need to
- 1:35:10remember all of that like even I often
- 1:35:13have to look up these things like oh
- 1:35:14what was it again like there's something
- 1:35:16in Python with starts with and ends with
- 1:35:18these are such niche use cases that when
- 1:35:22you need them all you need to know is
- 1:35:24that Python has a lot of functionality
- 1:35:26out of the box to solve common problems
- 1:35:28so whenever you're dealing with
- 1:35:30something there is a high chance that
- 1:35:32you don't need to come up with the
- 1:35:33entire logic yourself or create a really
- 1:35:36complex function, you can first just ask
- 1:35:38chatbt and say, "Look, I'm trying to
- 1:35:40solve this problem. I need to I have
- 1:35:42this sentence and I need to understand
- 1:35:43if it if it starts with this and then I
- 1:35:45want to replace a certain part and JGPT
- 1:35:47will literally give you the most
- 1:35:49effective way to do it through a
- 1:35:50combination of all of these methods that
- 1:35:53I just shared." So the goal really is to
- 1:35:55get you familiar with what you can do
- 1:35:57with data. What are string methods? What
- 1:35:59is the notation? seeing them, walking
- 1:36:01through them, and just getting a feel
- 1:36:03for how this programming language works
- 1:36:05is really the goal at this point, not to
- 1:36:07fully understand and remember
- 1:36:09everything. That's important to keep in
- 1:36:10mind. All right. And now we get into the
- 1:36:12section control flow. So, how can we
- 1:36:15actually make decisions within our
- 1:36:17program, right? We've already we already
- 1:36:19saw that we can use true and false and
- 1:36:21we can do calculations. But now whenever
- 1:36:23we're building programs, we need to do
- 1:36:26something like look if at an ATM a
- 1:36:28password is correct then we allow
- 1:36:30access. If not we give an error. If a
- 1:36:33user clicks on a button only then we
- 1:36:36perform an action. In a game if the
- 1:36:38health is equal to zero it's game over.
- 1:36:41Otherwise we can continue. And within
- 1:36:43programming we do this through what you
- 1:36:46call if statements. So let's run through
- 1:36:48some examples. So let's say we have a
- 1:36:51temperature and we set that equal to 25.
- 1:36:55Now what we can do is we can build a
- 1:36:57system that based on the temperature
- 1:37:00does either a certain action when it's
- 1:37:02above a threshold or something else when
- 1:37:04it's below a threshold. So we can simply
- 1:37:06start by saying look if the temperature
- 1:37:09is greater than 25 we now use a colon
- 1:37:15and we get to the next line. This is
- 1:37:17something new. We haven't done this. So
- 1:37:19we introduce the if statement which is
- 1:37:21an operator that we can use. An if
- 1:37:23statement always just starts with the
- 1:37:25if. Then we have the conditional logic
- 1:37:27over here and then when we end that
- 1:37:29logic we do a colon, we do a enter and
- 1:37:32then we get to the next line and here we
- 1:37:34use an indentation. This is very
- 1:37:36specific to Python. So it goes to the
- 1:37:39next line and what's doing uh what it's
- 1:37:41doing behind the scenes. You can see in
- 1:37:43the highlight over here it's adding four
- 1:37:45spaces. Now our code editor is doing
- 1:37:48this automatically for us because it
- 1:37:50understands the Python programming
- 1:37:51language and it understands what it
- 1:37:53does. So just so you know that's what's
- 1:37:55going on behind the scenes. And now what
- 1:37:57we can do is we can for example write a
- 1:37:59print statement over here where we say
- 1:38:01it's hot. If we run this nothing will
- 1:38:05happen. And that is because the
- 1:38:06temperature is equal to 25. If we set it
- 1:38:09to 26 and we run this it will say it's
- 1:38:13hot. Remember right similar to the
- 1:38:15example I gave about the customer care.
- 1:38:17Do we need to escalate it to a human?
- 1:38:19Yes or no. This is it's a similar type
- 1:38:21of logic. So let's set it back to 25.
- 1:38:24Nothing will happen. Now let's create
- 1:38:26another case. So what we can now do is
- 1:38:29we can now go back. So we exit out of
- 1:38:31this if statement and we continue with
- 1:38:33an else statement. And now here we don't
- 1:38:36have to specify any logic because this
- 1:38:38will simply execute in all other cases.
- 1:38:42And then we say print it's nice weather.
- 1:38:46Now if I run this it will say it's nice
- 1:38:49weather because if we follow the order
- 1:38:51of operations which in Python will be
- 1:38:54from top to bottom and from left to
- 1:38:57right it will first check if the
- 1:38:59temperature is greater uh if the
- 1:39:01temperature is greater than 25 it will
- 1:39:02print it. This is not the case. Okay.
- 1:39:04Now we go into the else condition. This
- 1:39:07will always run. If this is not true
- 1:39:09this will run. That is how it is
- 1:39:12currently set up. It's it's a boolean
- 1:39:14boolean decision-making logic. And now
- 1:39:15the syntax here with if and then a colon
- 1:39:18and an else and then nothing there and
- 1:39:19another colon is just one of those
- 1:39:21things. You just have to see it and do
- 1:39:23it a couple of times before it clicks.
- 1:39:25But let's say you want to add more
- 1:39:26conditions to the mix. So actually what
- 1:39:29we want to do is say look if the
- 1:39:32temperature is greater than 25 we say
- 1:39:34it's uh it's hot. But we can also say if
- 1:39:38the temperature is greater than 30, we
- 1:39:42say it's very hot. And now what we do in
- 1:39:48here, if we if we set it up like this,
- 1:39:50we have an if statement and then another
- 1:39:52if statement. And let's see, let's
- 1:39:55actually put this at 24. What will
- 1:39:58happen right now? You'll find that
- 1:40:00currently it will say it's nice weather.
- 1:40:03But then if we put this to 31 and we run
- 1:40:07this, you'll find that it's both running
- 1:40:09is very hot and it's hot. But we in this
- 1:40:12case we don't want that because we want
- 1:40:14it to be either one of the decision-m
- 1:40:17points. So for that Python has something
- 1:40:19else and that's called an L if. So here
- 1:40:22we can chain things together. So it will
- 1:40:24first check if the temperature is
- 1:40:27greater than 30 and if that is the case
- 1:40:29it will print is very hot and then it
- 1:40:32knows that it can end the loop. So it
- 1:40:34will not check for this. So what this
- 1:40:36looks like is now it will say it's very
- 1:40:38hot even though this condition is also
- 1:40:41true. It will not get to that because of
- 1:40:44how we structured it. So another example
- 1:40:46over here is uh here another chain and
- 1:40:49you can also use multiple alifs. you can
- 1:40:51actually chain them together. So let's
- 1:40:53say we have a score and if we say if
- 1:40:56it's uh greater or equal to 90 we say a
- 1:40:58excellent here we we get a B here we get
- 1:41:01a C here it needs improvement. So let me
- 1:41:04actually copy paste this to see what
- 1:41:06this looks like. So now with 85 you get
- 1:41:09a B and if you have a 90 you get
- 1:41:12excellent. So remember the order of
- 1:41:14operations right from top to bottom from
- 1:41:16left to right and if we use an if l if
- 1:41:18chain the script will stop once one of
- 1:41:21the conditions is true and if it gets
- 1:41:23through everything and there is none of
- 1:41:25these conditions is true it will always
- 1:41:28execute the else statement. This is
- 1:41:29something you have to get used to but
- 1:41:31this is really the bread and butter of
- 1:41:34building programs. You take in the data
- 1:41:37whatever type of data type it is whe
- 1:41:39whether it's a number a boolean or a
- 1:41:42number you combine that into some kind
- 1:41:44of like variables and you apply some
- 1:41:46operations and then you want to do stuff
- 1:41:48with it. If it's this we do that if we
- 1:41:50get to here then we execute this
- 1:41:52function. If the escalation is true we
- 1:41:55we make sure we get a real human in the
- 1:41:57loop. Really the fundamental building
- 1:42:00blocks of how you build systems and how
- 1:42:02you put something together in a
- 1:42:04programming language. Now the nice thing
- 1:42:06is that everything we've learned up
- 1:42:07until this point can also be re
- 1:42:10reapplied and combined. Right? So here
- 1:42:12when you're using if else statements we
- 1:42:14can also use the and or and not
- 1:42:17operators to determine the boolean
- 1:42:19logic. So similar to how we were first
- 1:42:22looking at age and license and we're
- 1:42:24just printing what it was. We can also
- 1:42:27create if else statements around this
- 1:42:29and combine them in those two. So just
- 1:42:32to showcase that to you, you can come in
- 1:42:34here and here this will print you can
- 1:42:37drive and if we put put it to 12. So
- 1:42:40this is a 12y old we cannot drive. If we
- 1:42:43want to let the program know that this
- 1:42:45is not possible we can print this and we
- 1:42:48will say you cannot drive. Now we run
- 1:42:51this and it will go and we can put any
- 1:42:53type of l if statements in between. And
- 1:42:56now with if else statements we can even
- 1:42:58do nested conditions. So we can for
- 1:43:00example say if has ticket and then we go
- 1:43:03to the next line but we also say if age
- 1:43:07greater or equal to 18 we print enjoy
- 1:43:12the movie and then we do an else
- 1:43:14statement in here so they have a ticket
- 1:43:16but they're not 18. we print needs
- 1:43:19supervision
- 1:43:21and then we can come in here all the way
- 1:43:23to the end and then add another print
- 1:43:25statement and say please buy a ticket.
- 1:43:30So now you can see someone's 15 has a
- 1:43:32ticket they need supervision. Whenever
- 1:43:35they're 18 they can enjoy the movie.
- 1:43:37When they don't have a ticket they need
- 1:43:39to buy a ticket. Now the next concept
- 1:43:42that we will cover in the control flow
- 1:43:44section is the notion of loops where we
- 1:43:47can repeat code multiple times. So this
- 1:43:49is often something that you need to do
- 1:43:51when you're building programs. And for
- 1:43:53example, let's say you want to do
- 1:43:54something like this. You want to perform
- 1:43:55an operation five times. Instead of
- 1:43:58writing this out in your program, which
- 1:44:00is which is really for verbose, we can
- 1:44:02create a loop around this which is much
- 1:44:04cleaner and much shorter. The most
- 1:44:06common way to like do this is using a
- 1:44:09for loop. So let's give an example of
- 1:44:12this. And again there is a specific
- 1:44:14syntax that we need to understand in
- 1:44:16here. So let's clear this up. When we do
- 1:44:19a four, we start with four. That's why
- 1:44:22it's called a for loop. And we select a
- 1:44:26counter in here. And this is one of
- 1:44:28those things in the beginning it's a
- 1:44:29little bit tricky because this can
- 1:44:30pretty much be anything. But let's take
- 1:44:32i for now. But we can also put x. And we
- 1:44:34can also put whatever in here. But a
- 1:44:37common way if you want to create a
- 1:44:38counter is I because it's really short.
- 1:44:40And then we say for i in and then in
- 1:44:43this case we can give it a range. And
- 1:44:45let's say we give it five. We can then
- 1:44:47do something like print and then we do
- 1:44:49i. So in this case if I run this you
- 1:44:52will see that we'll print 0 to four in
- 1:44:54this case. Here is there's a lot going
- 1:44:56on in here because right now like up
- 1:44:58until this point you probably were like
- 1:44:59okay Dave I can follow all of this but
- 1:45:01this this is not plain English. This is
- 1:45:03weird. Why does it start with zero?
- 1:45:05First of all, one thing to keep in mind
- 1:45:07is that Python is a uh zero index-based
- 1:45:11programming language. Meaning that
- 1:45:13Python starts to count from zero. This
- 1:45:16is something that we will also encounter
- 1:45:18later when we're working with lists and
- 1:45:20indexes. If you want to get the first
- 1:45:22element, we say we want element zero
- 1:45:24instead of element one. That's why you
- 1:45:27see zero over here. And what we are
- 1:45:30essentially doing here is we're creating
- 1:45:33an iteration where we say look for i in
- 1:45:37range five and range five is a range
- 1:45:40where we say look we start with zero and
- 1:45:42then we go to one to two to three to
- 1:45:44four and then we stop. It's syntax. It's
- 1:45:46a notation. It's something you have to
- 1:45:48get used to. And then we perform an
- 1:45:50operation. And in this case we use i. So
- 1:45:52we use the counter uh variable here as
- 1:45:55well. But we can also for example print
- 1:45:58hello world and then if we run this it
- 1:46:00will just simply five times print hello
- 1:46:03world. But the i refers to the counter
- 1:46:05in here. But let's get back to the docs
- 1:46:07over here and see what's going on over
- 1:46:09here. So again python starts counting at
- 1:46:12zero not at one. It's called zero
- 1:46:13indexing. And you can also count from
- 1:46:15different starting points. So just this
- 1:46:17is just a way of repeating things over
- 1:46:19and over again. We can do it through
- 1:46:21numbers by giving a range let's say 1 to
- 1:46:24six. uh we can even count with steps of
- 1:46:27two all things that are possible. So let
- 1:46:30me actually run this over here to give
- 1:46:32you an example for for uh what that
- 1:46:34means. So before we had five, right? So
- 1:46:38we said range five and then we print
- 1:46:41everything. But we can also say look we
- 1:46:43want to go from one to six and then
- 1:46:46you'll find that it will print 1 to five
- 1:46:48because it will stop before six. That's
- 1:46:50just the way it works. And that's one
- 1:46:52thing like right now you're probably
- 1:46:54wondering like oh it's a little bit
- 1:46:55tricky so you start at zero and you put
- 1:46:57in six but you actually go to five even
- 1:47:00I to this date whenever I do four loops
- 1:47:02um you're always tinkering with this so
- 1:47:04what you end up doing is you're
- 1:47:06experimenting with this and you oh wait
- 1:47:08no I actually want to get to to six so I
- 1:47:10plug in seven then you correct it and
- 1:47:13that's the iterative process right
- 1:47:15that's also what I love about using the
- 1:47:17interactive session it's so fast you can
- 1:47:19select bits and pieces and continue. And
- 1:47:22then here you have, you can see we add
- 1:47:24another variable to it. So we say we
- 1:47:26want to go from zero. We want to start
- 1:47:29at zero. We want to go to 10, but we
- 1:47:31want to do it in steps of two. And then
- 1:47:33what you'll find is that it will go from
- 1:47:350 to 2 to 4 to 6 to 8. So that's
- 1:47:39something we can also do with the range
- 1:47:41function. And there are more components
- 1:47:43to it. But that's just enough for now to
- 1:47:46understand. Look, if we want to do
- 1:47:47things over and over and over again, we
- 1:47:50don't want to do this. That's the
- 1:47:53takeaway for this section. And that's
- 1:47:55all for now. All right. And that brings
- 1:47:57us to data structures. So how we can
- 1:48:00store multiple values together. So up
- 1:48:03until this point, we have stored one
- 1:48:05value per variable, right? So we were
- 1:48:07talking about the numbers, we were
- 1:48:09talking about the strings and the
- 1:48:10boolean values. But what if you need to
- 1:48:12store multiple values? So you want to
- 1:48:14create a collection and put them
- 1:48:15together. That's where data structures
- 1:48:18come in. So these are like containers
- 1:48:20and they come in the form of lists like
- 1:48:23a shopping list ordered items. So I want
- 1:48:25this, this, this, and I also want
- 1:48:27bananas in there and I also want apples
- 1:48:29or a dictionary. These have key value
- 1:48:32pairs. So it could be like a phone book.
- 1:48:34So you have a name and there is a number
- 1:48:36associated to it. So they come in pairs
- 1:48:38and then you have what is called tupils.
- 1:48:40These are fixed. So you create them once
- 1:48:42and you can't really mess with them. So
- 1:48:44for example like coordinates and then
- 1:48:46you have sets. These are a bag of unique
- 1:48:48items. So you can take a whole lot of
- 1:48:51information and you just get rid of all
- 1:48:53the duplicates. So you only have the
- 1:48:54unique values in there. Those are the
- 1:48:56common data structures that you'll use
- 1:48:58within the Python programming language.
- 1:49:00So let's start with lists which is
- 1:49:02actually a really common one. You'll use
- 1:49:04this all the time. So, we're going to
- 1:49:07start with the syntax and that is as
- 1:49:11follows. So, we're going to clear this
- 1:49:12up and we're going to say my list
- 1:49:15equals. So, spell that out correctly. My
- 1:49:18list equals and now here comes the
- 1:49:19syntax. We use brackets, square
- 1:49:22brackets, not the curly brackets. That's
- 1:49:24for the dictionaries we'll use later.
- 1:49:26We'll use square brackets. Now, this is
- 1:49:29the container in which we can start to
- 1:49:31put stuff. And Python is really
- 1:49:34flexible. So you can literally view this
- 1:49:37as some kind of bag or container and we
- 1:49:39can dump all types of stuff in it. So
- 1:49:42remember we had Alice, right? We can
- 1:49:44dump Alice in here. Alice is a string,
- 1:49:46but we can also plug in 25. Um we can
- 1:49:50also say look we have uh h equals 25.
- 1:49:53And now next to 25 we also actually plug
- 1:49:56in the h which is now a variable. But we
- 1:49:59can also plug in actually true. And you
- 1:50:02know what? We also uh had the has
- 1:50:05license uh which in this case is false
- 1:50:09and now we plug that in and that's all
- 1:50:12totally fine if we store it in memory
- 1:50:15and then run it. So let me clear this up
- 1:50:17to get rid of the errors. So now we have
- 1:50:19a list all types of different data
- 1:50:21formats and data types that are in
- 1:50:23there. That's the beauty of Python is
- 1:50:25really flexible uh and it doesn't really
- 1:50:27care about that. Now whenever we have a
- 1:50:29list we often want to do something with
- 1:50:32that. So now we have this list and now
- 1:50:34we can index this list. So let's say
- 1:50:37you're working on a problem you have
- 1:50:38this container and you want to take
- 1:50:40Alice out of that list or whatever the
- 1:50:43that element is. Lists are ordered
- 1:50:46meaning that how you store it in this
- 1:50:49way will like Python will remember and
- 1:50:53through this we can access certain
- 1:50:56indexes of this list to grab information
- 1:50:59out of it and we do that in a similar
- 1:51:01way using the square brackets but now
- 1:51:04directly on the list variable itself. So
- 1:51:07we can now do the square brackets and
- 1:51:09now we're going to index things. So a
- 1:51:12couple of minutes ago I explained how
- 1:51:14Python is a um zero B uses a zerobased
- 1:51:17index. So it starts at zero. So that
- 1:51:20means if we want to grab Alice out of
- 1:51:22here we do a zero and that will give us
- 1:51:25Alice. So we could for example say name
- 1:51:28is equal to my list and then we take the
- 1:51:30first element. Now that is Alice. Now we
- 1:51:33can set H equals my list and then we
- 1:51:37take the second element but we index it
- 1:51:39with one. And now we get 25 and so on.
- 1:51:43We can go on and on and on. And also
- 1:51:45what what you can also do is you can
- 1:51:47also say look what if we want the last
- 1:51:49we want the last item but like what is
- 1:51:51it? Is it like three four five? Python
- 1:51:53has a way uh to do this. So this is
- 1:51:55actually like has license. So we can say
- 1:51:57let's say the license equals oh look and
- 1:52:00here actually this is interesting. we
- 1:52:02get a blue uh highlight over here
- 1:52:05meaning that there could be a problem
- 1:52:07where this is an internal uh variable
- 1:52:10that Python is using. Now in this case
- 1:52:11we should be fine. Uh but let's actually
- 1:52:14like override it with has license. So
- 1:52:16sometimes you have that for example when
- 1:52:17you write print that's that's something
- 1:52:20that we can use inside Python internally
- 1:52:22and that's often not how you want to
- 1:52:23name your variables. So that's just a
- 1:52:25quick side note. So we can now say my
- 1:52:27list and I was explaining that how we
- 1:52:29can get the last element. We can do a
- 1:52:31minus one. So we can also refers the
- 1:52:34index. So you can now see we get to has
- 1:52:36license. We can also do minus2 and that
- 1:52:39will give us the true which should be
- 1:52:42true. And then we can even get minus
- 1:52:43three. So there are multiple ways like
- 1:52:46forward or backward to work with the
- 1:52:49list and to get elements out of it. Now
- 1:52:52next to grabbing single items that we
- 1:52:54just saw, we can also take slices. So we
- 1:52:57can also specify a range using the
- 1:52:59colon. Now next to storing information
- 1:53:02in a list and then grabbing something
- 1:53:03from it. We can also over overwrite data
- 1:53:07in a list we can add to it. We can grab
- 1:53:09from it. We can remove things. So let's
- 1:53:11walk through some common operators in
- 1:53:13here. So let's say we have the list and
- 1:53:15we say my list and now we say look we
- 1:53:18have my list and we take the first
- 1:53:21element in there. We say Alice and we
- 1:53:22say look now this is Dave. Now if we
- 1:53:25look at our list you can see Alice has
- 1:53:27now been updated with Dave. We can also
- 1:53:30use a list method. Uh in this case is
- 1:53:33append and we can just add something to
- 1:53:36it. So let's actually add Alice back to
- 1:53:39the list. And what this will do is it
- 1:53:42will append it. Let's see show you over
- 1:53:44here. So you can see it has now added
- 1:53:46Alice to the end of the list. So append
- 1:53:50is just taking a list as is and then
- 1:53:51stacking that to the end. And we can
- 1:53:54also remove stuff. So if we come in here
- 1:53:56and let's say hey we have my list and we
- 1:53:59now do remove and again we want to
- 1:54:01remove Alice from the list. So Alice is
- 1:54:03having a hard time with list this list.
- 1:54:05We're not sure if we want her on or off
- 1:54:07or whether it's Dave Alice is gone
- 1:54:09again. So all operations that we can
- 1:54:12follow. Often in Python there are also
- 1:54:14multiple ways to accomplish the same
- 1:54:17goal. Uh with append uh there is also an
- 1:54:20insert. So instead of just saying look
- 1:54:22we want this at the end we can also
- 1:54:24insert it into a specific index. So
- 1:54:27coming here again let's see so Alice is
- 1:54:30from the list again and then we can say
- 1:54:32look we want to insert and then we say
- 1:54:34look we want it on index one and we
- 1:54:37bring Alice back in there and let's run
- 1:54:40this. So you can see Alice is back in
- 1:54:42there. Lots of different ways to think
- 1:54:44about look what do we what do I want to
- 1:54:46accomplish? What do I want to do? How do
- 1:54:48I want to store the data? And then
- 1:54:50Python likely has something for that for
- 1:54:53you to accomplish that goal. And similar
- 1:54:55to strings, lists also have methods to
- 1:54:58do even more with it. So we can check
- 1:55:00how long a list is. We can count, we can
- 1:55:04index, we can sort, we can reverse. All
- 1:55:07stuff that you may need to do at some
- 1:55:09point where you run into an issue and
- 1:55:11then you'll find, oh, look, Python can
- 1:55:12actually reverse this list for me. Easy.
- 1:55:15But again, these are more these are not
- 1:55:17so common, I would say, in the real
- 1:55:19world, especially when you're working on
- 1:55:21AI cases. Every now and then they pop
- 1:55:23up, but for now, it's totally fine. Just
- 1:55:26high level be aware of them. Know that
- 1:55:28you can do stuff with lists, but it's
- 1:55:30much more important to understand the
- 1:55:32fundamentals, right? What is the list?
- 1:55:34We can store data into it and we use
- 1:55:36brackets to do that. That's important.
- 1:55:39And we index them. That's the most
- 1:55:41important thing for now. So, let's get
- 1:55:42into dictionaries. So remember, right,
- 1:55:45these are key value pairs. So within a
- 1:55:48list, we simply have a grocery list,
- 1:55:51whatever. Alice doesn't have to be
- 1:55:53related to 25. They're just in the same
- 1:55:56list, but could be entirely different
- 1:55:59concepts. A dictionary changes that. A
- 1:56:02dictionary uses key value pairs. And we
- 1:56:04do that using the curly brackets. So
- 1:56:07here we can start to store information
- 1:56:09in a way where I can say look we have a
- 1:56:12person and now I'm going to open up the
- 1:56:16uh I'm going to create the curly
- 1:56:17brackets in here. I'm going to do do an
- 1:56:19enter and I'm going to say hey let's say
- 1:56:20a person has a name and there comes
- 1:56:23Alice again and I should put that in
- 1:56:25quotes over here. So this is the key. So
- 1:56:26the name is Alice and Alice has an age
- 1:56:29and now that is a number. So let's say
- 1:56:33Alice is 25 and we separate all of the
- 1:56:37new elements in the dictionary similar
- 1:56:39to how we did that in the list with a
- 1:56:41comma. So whenever we go to the next
- 1:56:43line we do a comma and then we can say
- 1:56:45look Alice also has um a city and we set
- 1:56:49that equal to New York. So Alice is 25
- 1:56:52lives in New York. Now this becomes a
- 1:56:56dictionary and what we can do with
- 1:56:58dictionary is we can look up certain
- 1:57:01elements in there. So if we have this
- 1:57:03and we look at the entire dictionary we
- 1:57:06get everything. But now if we want to
- 1:57:08for example grab the we want to know how
- 1:57:11old Alice is in this case what we do is
- 1:57:14instead of using indexing with numbers
- 1:57:17we use the keys to look up the value. So
- 1:57:20we do that also with square brackets.
- 1:57:23Again this is a syntax thing. So we
- 1:57:25define the dictionary with curly
- 1:57:27brackets but when we want to retrieve
- 1:57:29information from it we use the square
- 1:57:32brackets. Something we need to remember.
- 1:57:34And now I can plug in the key. So I can
- 1:57:36say h. And now that will pull the
- 1:57:39information from the dictionary. It will
- 1:57:41perform a lookup and we'll say look we
- 1:57:43got 25. If we do the name we'll get
- 1:57:46Alice. If we do the city we'll get New
- 1:57:48York and so on. And similar to lists, we
- 1:57:51can also update or overwrite information
- 1:57:54in the dictionary. So we can also say
- 1:57:56look person uh name we can just
- 1:57:58overwrite that and say Dave. So now all
- 1:58:01of a sudden you can see over here the
- 1:58:03output now this dictionary contains
- 1:58:05Dave. And we can also add stuff to the
- 1:58:07dictionary which is actually quite
- 1:58:09straightforward. Uh we can just specify
- 1:58:12another key. So something that's not in
- 1:58:14there. So we can for example say we do
- 1:58:16license equals uh true. And now if we
- 1:58:20run this you'll find that the name is
- 1:58:22still Dave. You can see age25 city. And
- 1:58:26now we have added the license to that as
- 1:58:28well. And if we want to get rid of that
- 1:58:30what we can do is we can simply do a
- 1:58:32delete. So we do delete person license.
- 1:58:35And now if we check that you will now
- 1:58:37find that license is not in here
- 1:58:40anymore. So those are the same type of
- 1:58:42operations that you can do with a list
- 1:58:45and within a dictionary. And when to use
- 1:58:48which one is something you have to get a
- 1:58:50feel for when you're are when you're
- 1:58:53working with Python, when you're
- 1:58:54programming in general, there are often
- 1:58:56infinite ways to solve the same problem.
- 1:58:58So you could very well solve problems by
- 1:59:01just using list and storing everything
- 1:59:03in there. But sometimes it's much easier
- 1:59:05to have key value pairs where if you
- 1:59:08want to look up something, you don't
- 1:59:09have to figure out look what was the
- 1:59:11index of this list and then need to
- 1:59:13figure out where was it. You simply
- 1:59:15know, oh, I stored it at the H uh I
- 1:59:18sorted at the H key. So if I want to
- 1:59:19know the H, we just need to plug in
- 1:59:21that. This is all something you'll get a
- 1:59:23feel for as you get more experienced and
- 1:59:25more exposure to working with the Python
- 1:59:27programming language. All right. And
- 1:59:29lastly, dictionary also have methods. So
- 1:59:32we can use the keys, we can get the
- 1:59:34values, we can can get the items. So all
- 1:59:36different ways of accessing the
- 1:59:38information that's available within the
- 1:59:41dictionary. This is a nice exercise to
- 1:59:43try for yourself and see how they work.
- 1:59:45Okay, then let's get into tupils and
- 1:59:48then finally in sets. So these are data
- 1:59:51structures that actually in the wild you
- 1:59:55don't really use a lot, but it's good to
- 1:59:57know how they work just so when you
- 1:59:59encounter them. So a pupil is immutable.
- 2:00:02So remember right with the list and the
- 2:00:05dictionary I saw look we can create it
- 2:00:07and then look we can just override the
- 2:00:09name we can remove Alice all of that.
- 2:00:11Tupils are immutable. So the the idea of
- 2:00:13a tupil is you want to create it and the
- 2:00:16program should never touch that. So for
- 2:00:18example when you have a coordinate or an
- 2:00:20RGB color and just when you want to
- 2:00:23adjust it you just write create a new
- 2:00:25one because the coordinate is not going
- 2:00:27to change and tupils are specified with
- 2:00:30parenthesis. So remember we had lists
- 2:00:32square brackets we had dictionaries
- 2:00:35curly brackets now we have tupils
- 2:00:37parenthesis okay so tupils go in either
- 2:00:41in pairs or you can add more to it. So
- 2:00:44we can have a point and uh we could have
- 2:00:46three and five and we have colors. So
- 2:00:48let's actually plug this in and get a
- 2:00:51feel for what this is like. So we have
- 2:00:53an empty pupil. There's nothing in
- 2:00:54there. We have a point which is three
- 2:00:57and five and then we have the colors in
- 2:00:58here. So what I can now do is let's say
- 2:01:00colors and I want to get the first
- 2:01:03element in there. So this works similar
- 2:01:05to how we're working with the list,
- 2:01:06right? It's very similar uh but it's
- 2:01:09just in a way where look if we now say
- 2:01:11look this is now blue. this will get an
- 2:01:14error because if this were a list, this
- 2:01:17would be totally acceptable. But now
- 2:01:19tupil object does not support item
- 2:01:22assignment. That's what the error says
- 2:01:24because that's one of the properties of
- 2:01:26why you want to use a tupil. So other
- 2:01:28than that, it's very similar to a list
- 2:01:30and we can do all the same things,
- 2:01:31right? We can do get items, we can use
- 2:01:33zero, we can do minus one, we can do
- 2:01:35slicing. That's all you need to know for
- 2:01:37now. So let's get into sets. final data
- 2:01:40structure of really the Python basics,
- 2:01:43all the really most fundamental Lego
- 2:01:45blocks. And a set is a way to create
- 2:01:47unique values to make sure that whenever
- 2:01:50we're working with a collection, there
- 2:01:51are no duplicates in there. There are
- 2:01:53two ways to create sets. We can use the
- 2:01:55set notation over here. Or we can use
- 2:01:58curly brackets, but then not assigning
- 2:02:00the key value pairs because otherwise it
- 2:02:02would be a dictionary. So let's quickly
- 2:02:04go through this because you just need to
- 2:02:05see it at this point rather than like
- 2:02:07fully understanding everything that's
- 2:02:09going on. So we can create an empty set.
- 2:02:11So there's nothing in here and then we
- 2:02:13could later add things to it. But we can
- 2:02:15also set it with values. Both ways work.
- 2:02:17So here let's say we have a set of
- 2:02:19numbers 1 2 3 4 5. So these are the
- 2:02:21numbers. So this is now a set even
- 2:02:24though we use curly braces because we
- 2:02:27don't do the assignment with uh the
- 2:02:30colon and using uh strings in there.
- 2:02:32It's a set. Now we can also do it like
- 2:02:35this. So again in a similar way we use
- 2:02:37set parenthesis and then we plug the
- 2:02:40list in there. That also works. Now we
- 2:02:43can use it to dduplicate items because
- 2:02:46if you don't do that like if you don't
- 2:02:49have or don't intend to do that like you
- 2:02:51could just as well use a list. There's
- 2:02:53no uh there's no point for that. So
- 2:02:55let's say we have the scores over here.
- 2:02:57So notice how 90 appears in here two
- 2:03:00times. So first this is a list. See
- 2:03:03we're using square brackets. So if I
- 2:03:05store this in memory and let me actually
- 2:03:08switch this over here so you can see it.
- 2:03:09If I store this in memory and print it,
- 2:03:11you can see uh this is the list. But now
- 2:03:14we can create unique scores by using the
- 2:03:17set notation and we plug that in here
- 2:03:20and you can see oh it's actually like it
- 2:03:22was 90 and 85. It's also twice in there.
- 2:03:25I didn't even notice that. So now you
- 2:03:26can see it get it gets rid of the
- 2:03:28duplicate values and now we can store
- 2:03:30that and now our unique scores become
- 2:03:32just that and we can do that exactly the
- 2:03:35same over here. Apple, banana, orange.
- 2:03:37These are the fruits but now if we add
- 2:03:39banana one more time it works in exactly
- 2:03:43the same way. Oh, I missed a quote over
- 2:03:45here. So now fruits is still apple,
- 2:03:48banana, orange even though banana is in
- 2:03:51there two times. So that's really what
- 2:03:53you should know about sets and the basic
- 2:03:56operations. We can remove, we can
- 2:03:58discard, we can check things, but it's
- 2:04:00to dduplicate collections. All right,
- 2:04:03and that brings you to the end of the
- 2:04:05Python basics section. So we covered
- 2:04:08almost all of the very fundamental
- 2:04:10building blocks that you need to
- 2:04:11understand about the Python programming
- 2:04:13language. Data types, data structures,
- 2:04:16operators, how you can combine them. And
- 2:04:18you should now get a feel for what it's
- 2:04:21like to write simple Python functions,
- 2:04:23right? You should be getting comfortable
- 2:04:25with either executing code through the
- 2:04:27terminal terminal or see why the Jupyter
- 2:04:30interactor session is so nice to work
- 2:04:33with and how you can quickly explore
- 2:04:35what the data is, check if you made any
- 2:04:37errors and course correct. So with this
- 2:04:39fundamental understanding out of the way
- 2:04:41right now, the next section, building
- 2:04:44programs, is all about how we can
- 2:04:46actually use all of these building
- 2:04:48blocks and create longer scripts instead
- 2:04:50of just isolated lines that we've been
- 2:04:53doing and how to piece things together.
- 2:04:55So it starts to look more and more and
- 2:04:57more like we're actually building
- 2:04:58something and automating something.
- 2:05:00We're getting there. You're crushing it.
- 2:05:02And right now, I still understand this
- 2:05:04is new. These concepts are very
- 2:05:06abstract. They're isolated. You don't
- 2:05:08have to remember all of this. This is
- 2:05:10just the first exposure and it will get
- 2:05:12better over time. And now this would be
- 2:05:14another great time to take a quick
- 2:05:15break. Maybe grab another fresh cup of
- 2:05:17coffee or your favorite beverage and
- 2:05:19then we'll get into the building
- 2:05:20programs section. All right, so let's
- 2:05:23dive into building programs. I also took
- 2:05:26a fresh cup of coffee here. And in
- 2:05:29building programs, we are going to cover
- 2:05:31here on the left side. We can see we're
- 2:05:33going to get into functions, external
- 2:05:35tools, practical tips to use, how you
- 2:05:37use Python in the real world, error
- 2:05:40handling, and then we get into classes.
- 2:05:43So, this is really where you'll get to
- 2:05:45see Python come to life in action, and
- 2:05:48we can actually start to do stuff with
- 2:05:50the language. So, let's dive into
- 2:05:52functions, which are used to create
- 2:05:55reusable blocks of code, so we don't
- 2:05:57have to repeat ourselves. You can think
- 2:06:00of a function like a recipe. you can
- 2:06:01follow multiple times. a machine that
- 2:06:03takes input and produces output or a
- 2:06:05named shortcut for for example complex
- 2:06:07operations and before we already saw
- 2:06:10that we could use loops right so when we
- 2:06:12did the five times print hello world
- 2:06:14that's a little bit redundant and we
- 2:06:16don't want to do that so we created the
- 2:06:17loop to do that but let's say we have
- 2:06:20more complex logic so it's not just a
- 2:06:22oneline print statement but there are
- 2:06:24actually calculations there steps
- 2:06:26printing steps maybe we need to get some
- 2:06:28information manipulate some information
- 2:06:30and every time something happens within
- 2:06:32in our system, we need to do that.
- 2:06:34That's where functions come into place
- 2:06:36where we can define it once and then
- 2:06:38later within our code, we can simply
- 2:06:40call that function and we can now use
- 2:06:43that functionality. So we don't have to
- 2:06:45write the same thing over and over
- 2:06:47again. And you've actually already been
- 2:06:49using some of Python's built-in
- 2:06:51function. So for example the print
- 2:06:52statement that we use all the time or
- 2:06:55the length that we use to um count the
- 2:06:58items or the length of an array we have
- 2:07:01also used that already. So those are
- 2:07:03Python built-in functions and within
- 2:07:06functions we are right now we're going
- 2:07:08to cover three main things. We're going
- 2:07:09to I'm going to teach you how you can
- 2:07:11define functions. Then we're going to
- 2:07:13talk about parameters. So these are
- 2:07:15things you put in the functions to
- 2:07:16control the inputs and the outputs and
- 2:07:18then returning the values. So this is
- 2:07:20what the output of the function will be.
- 2:07:22All right. So let's start with defining
- 2:07:25functions. And for this I'm going to
- 2:07:27come over here to Visual Studio Code and
- 2:07:30we're going to start with a new fresh
- 2:07:33clean slate here in hello.py. So as with
- 2:07:36anything with any new concept we're
- 2:07:38going to start with some syntax, right?
- 2:07:40Because first there are some rules that
- 2:07:41we need to understand before we can
- 2:07:43actually get into the functionality. Now
- 2:07:45every function in Python starts with
- 2:07:47defaf from definition meaning we're
- 2:07:50going to define a function then followed
- 2:07:52by a space and then we're going to write
- 2:07:55the name of the function. This can be
- 2:07:57literally anything. You can put anything
- 2:07:59here. Now as a rule of thumb you want
- 2:08:01the function to be descriptive of what
- 2:08:04it does. So let's start with a simple
- 2:08:06greeting function to create a print
- 2:08:09statement. And what you then want to do
- 2:08:12after the name of the function, you need
- 2:08:15parenthesis opening and closing
- 2:08:17parenthesis and then a colon. Again,
- 2:08:19this is all syntax. You need to see it
- 2:08:21once and then you can quickly refer to
- 2:08:23it. For now, this is all we need. And
- 2:08:25then we can hit enter. And now we get
- 2:08:27into the function. So we have now
- 2:08:29specified our function over here. And
- 2:08:31here in here with the tabs or four
- 2:08:34spaces, we can actually put stuff in
- 2:08:37here. So we can for example write a
- 2:08:39print statement and say hello. All
- 2:08:41right. And now let's have a look at what
- 2:08:42happens when we run this. So you can see
- 2:08:45right here we we load the function into
- 2:08:47memory but there's no output. We don't
- 2:08:49see anything here. And the same would be
- 2:08:51true if we run it in the terminal. You
- 2:08:54can see it just tries to run the script
- 2:08:56but there's no output. It just mentioned
- 2:08:58that it runs the file. So that is the
- 2:09:01case because when you define a function
- 2:09:03it is simply a placeholder for that
- 2:09:05logic. But when you want to actually use
- 2:09:08a function, we need to specifically tell
- 2:09:11Python to do that. So what we can do is
- 2:09:13we can come over to a new line over here
- 2:09:15and type in greet and then we do opening
- 2:09:18and closing parenthesis. And now this is
- 2:09:20actually where we would call the
- 2:09:21function. So now if I one more time open
- 2:09:23this up. Now if I do greet you can see
- 2:09:26that it executes the function and that
- 2:09:29it outputs the print statement over
- 2:09:31here. Similar if I do a copy paste over
- 2:09:33here uh and I can do hello again and I
- 2:09:37store this into memory and then do
- 2:09:39greet. You can see now we've changed our
- 2:09:41function and then now when we call the
- 2:09:43function now it prints this. So that was
- 2:09:45your first function. So the important
- 2:09:47thing to remember is the syntax. We
- 2:09:49start with defaf function name opening
- 2:09:51and closing parenthesis and then we do
- 2:09:53the colon. Then you can add your code
- 2:09:54here. Make sure it's indented. And then
- 2:09:57if you don't want to return something,
- 2:09:59you don't have to put in this pass over
- 2:10:01here. But you can also do it for
- 2:10:02clarity. So normally functions will
- 2:10:05often return something. And this pass
- 2:10:07putting this pass over here is simply a
- 2:10:09kind of like a readable way for humans
- 2:10:11to say look this function doesn't return
- 2:10:13anything. I in the next sections I'll
- 2:10:15show you how we can return stuff. But
- 2:10:17you can see it doesn't change anything.
- 2:10:19So you can also just get rid of this and
- 2:10:21it will be exactly the same. but Python
- 2:10:24accepts it. So those are the key parts
- 2:10:27and then some tips on naming functions.
- 2:10:29So like I've said, you want functions,
- 2:10:32you want functions to be descriptive of
- 2:10:33what they're doing, right? And there's
- 2:10:35also there al there are also some style
- 2:10:37rules to this similar to how we talked
- 2:10:40about there are style rules to
- 2:10:42variables, right? We use a similar setup
- 2:10:44over here. So we use lowercase letters
- 2:10:46and whenever there's a space, we use an
- 2:10:48underscore. So if we want to calculate
- 2:10:51some kind of total, we do calculate
- 2:10:53underscore total. We want to send an
- 2:10:55email, send underscore email, no capital
- 2:10:58letters. So we don't want to do uh we
- 2:11:01don't want to use capital letters in
- 2:11:02here. Those are reserved for classes
- 2:11:04which we will cover later. But remember
- 2:11:07these are styling styling guidelines. So
- 2:11:10it will work perfectly fine. You won't
- 2:11:12get an error. But other developers will
- 2:11:14look at you and they will see that
- 2:11:16you're a beginner and we don't want
- 2:11:18that, right? So then calling the
- 2:11:19functions this is what I already showed
- 2:11:21you right. So let let me actually copy
- 2:11:23paste this example over here to see we
- 2:11:25can also call uh functions multiple
- 2:11:27times. So that's the nice thing about a
- 2:11:29function. So here we have say goodbye we
- 2:11:31can do it once and now if we do want to
- 2:11:33do it one more time in our script we can
- 2:11:35simply just refer and just call the
- 2:11:38function instead of having to do it over
- 2:11:40and over again. And now what this means
- 2:11:42whenever you run your entire script so
- 2:11:44everything runs you can see that all of
- 2:11:46the logic here is executed. by three
- 2:11:48times. And beyond just simple print
- 2:11:51statements, we can really do anything
- 2:11:53with in a function. So we can also come
- 2:11:55back to some of the logic we already
- 2:11:57tested before and we can input if else
- 2:11:59statements. And the most important thing
- 2:12:01here to keep in mind is the indentation
- 2:12:04and how you structure how you structure
- 2:12:06these functions, right? So let me walk
- 2:12:08you through it. So when we create the
- 2:12:09function, we do defaf and we do the
- 2:12:11check weather. And you can also see over
- 2:12:13here like how your ID how the code
- 2:12:15editor is helping with this. So now this
- 2:12:17this is how we specify the function. Now
- 2:12:19we do an indent. Now if we want to check
- 2:12:22what if we want to uh include an if
- 2:12:24statement we do if and then let's say uh
- 2:12:27temp
- 2:12:29greater than 25. We for example print
- 2:12:33and we say it's hot. And now you can see
- 2:12:37these squiggly lines under here under
- 2:12:39temperature. And that is because right
- 2:12:40now Python doesn't know what temperature
- 2:12:43is. And that's because we haven't
- 2:12:44specified it yet. So you want to store
- 2:12:47that over here and say look temperature
- 2:12:49is 16. If temperature is greater than 25
- 2:12:52print it's hot. Then we go in here and
- 2:12:55then I do a shift tab to go back to this
- 2:12:57line. I do an else. I do another enter.
- 2:13:00Our IDE will cover the indentation and
- 2:13:03otherwise print it's nice weather. So
- 2:13:07this is why it's also good to like I've
- 2:13:09said beyond just copy and pasting the
- 2:13:11examples over here really writing it out
- 2:13:14because if you just do copy paste and
- 2:13:16you run it everything will run but it's
- 2:13:18those nitty-gritty things where like
- 2:13:20look how how does this work? Should I
- 2:13:22have it like this or have do I have it
- 2:13:24on this line? And you can immediately
- 2:13:26tell that your IDE will tell you like
- 2:13:28something's off. And this is how you
- 2:13:30build the like the the muscle memory and
- 2:13:32the the uh the skill really to look at
- 2:13:35Python code and think about okay look
- 2:13:37this is a function we have if else
- 2:13:39statements this is how it should be
- 2:13:40structured. So now if we do this
- 2:13:43remember if we run this what happens
- 2:13:45nothing correctly because we haven't
- 2:13:47called the function yet. So now I go to
- 2:13:50the other line over here. I go all the
- 2:13:53way to the back all the way really to
- 2:13:55the beginning. So no indentation and I'm
- 2:13:57going to do the check weather. I hit
- 2:13:58enter to autocomplete. So that's also
- 2:14:00something you'll notice, right? So I do
- 2:14:02check and now my IDE already says look
- 2:14:05check weather is a function that I have
- 2:14:07over here. So now I can just press enter
- 2:14:09and it will autocomplete that. So that's
- 2:14:12also one of those things where you need
- 2:14:14to you need to get your hands on the
- 2:14:16keyboard. You need to be able to type
- 2:14:18and then you'll find all kinds of
- 2:14:20interesting things that your IDE will
- 2:14:21show you. So you'll find that as I go
- 2:14:23through all of these examples, I'll also
- 2:14:26explain more and more of these things
- 2:14:28behind the scenes. So now we have to
- 2:14:29check weather over here. We can put it
- 2:14:31into memory. Check the weather. So it's
- 2:14:33nice weather. I can come over here.
- 2:14:35Let's say let's make it 30. Store this.
- 2:14:38Check weather. It's hot. Okay, that's
- 2:14:40our function to check the weather. All
- 2:14:42right. Okay. So let's come back over
- 2:14:44here. You can check out some common
- 2:14:46mistakes. If uh things don't go wrong,
- 2:14:48things is like you forget the uh
- 2:14:50parenthesis. That's a that's a big one.
- 2:14:52You forget the colon at the end. So do
- 2:14:54greet no colon. All beginner mistakes
- 2:14:57that you'll uh run into or the bad
- 2:14:59indentation. So it's not formatted
- 2:15:01correctly. All right. So let's now let's
- 2:15:03continue on this and let's talk about
- 2:15:04parameters. So parameters work with
- 2:15:08functions to make them dynamic. Right?
- 2:15:10So if I come back to this example. So
- 2:15:12right now like this is hardcoded and
- 2:15:15hardcoded means whenever this script
- 2:15:17runs it will always be this. I can do
- 2:15:20this all the time. I can do check
- 2:15:22weather, check weather, check weather.
- 2:15:23It will always be hot and this will
- 2:15:24never change. That's because there are
- 2:15:26no parameters that we can
- 2:15:29programmatically or dynamically change.
- 2:15:31So that's where parameters come in. You
- 2:15:33can now see that we can also add
- 2:15:35parameters in here and parameters go in
- 2:15:38between the parenthesis. So over here
- 2:15:40you can see we have the greet function
- 2:15:42but then we plug in the name over here.
- 2:15:44Now we can use that variable name in the
- 2:15:47function itself. And then when we call
- 2:15:49the function we can plug in that
- 2:15:52parameter and it will use that it will
- 2:15:55use that data within the function. Okay.
- 2:15:56So let's have a look at how this works.
- 2:15:59Again we have our simple function over
- 2:16:00here. So let's do another one. So we do
- 2:16:02greet. So dev greet this is all the same
- 2:16:05and then we do the parenthesis. And now
- 2:16:07what we do is we do name and then we do
- 2:16:10a colon. So now this function takes name
- 2:16:13as a parameter. And what we can now do
- 2:16:14is we do print and we create a string.
- 2:16:17we say hello and then remember if we
- 2:16:21wanted to to use variables within
- 2:16:23strings, do you remember what it was? It
- 2:16:25was called using an f string. So we put
- 2:16:28a little f before the string and then we
- 2:16:31could use the curly brackets in here to
- 2:16:34plug in a parameter. So now when we have
- 2:16:36this function and we go to greet, what
- 2:16:40we can do is we can now say name equals
- 2:16:44and let's say we can put in Dave. So we
- 2:16:46save this and we do greet and you'll
- 2:16:48find that it says hello Dave but we can
- 2:16:50also do this one more time and we can do
- 2:16:53hello Alice. So this is a way for us
- 2:16:56this is a really this is a key concept
- 2:16:58about working with function because this
- 2:16:59is something you'll do all the time
- 2:17:00where when you're building programs you
- 2:17:02think about look what logic do I want to
- 2:17:04implement what data what information is
- 2:17:06is coming at me and how do I want to use
- 2:17:09that information within my function so
- 2:17:11now we've made a dynamic script that we
- 2:17:13can change and one thing to uh remember
- 2:17:17here is that for Python it doesn't
- 2:17:20matter in this case if I specifically
- 2:17:23say name equals Dave or I just do greet
- 2:17:26Dave because how this works is you can
- 2:17:28also have multiple parameters and it
- 2:17:31will just follow the order of
- 2:17:32operations. So let me show you what I
- 2:17:34mean with that. So I can also for
- 2:17:35example let's let's do let's do last
- 2:17:37name first name last name and then we
- 2:17:39say look we have a first name in here
- 2:17:42and then I just do let's see I do space
- 2:17:45in here and then we do last name and so
- 2:17:48now we have two parameters in here that
- 2:17:50we can insert. And now what you'll find
- 2:17:53is if I do this and if I run this
- 2:17:55function we'll get an error because it
- 2:17:57says look greed. Let me actually move me
- 2:18:00to the side. So you can see now greed is
- 2:18:02missing one required positional argument
- 2:18:04last name. So Python now understands
- 2:18:06look in this function you actually need
- 2:18:08two parameters and you only gave one. So
- 2:18:11if we now plug in my last name over here
- 2:18:15you can see that right now this is all
- 2:18:18uh correct and now we can see hello Dave
- 2:18:20ablar. So now it's all good and you'll
- 2:18:23see that you actually don't have to
- 2:18:25specify first name last name because
- 2:18:27Python understands look this is the
- 2:18:28order of operation. First we do the
- 2:18:30first name and then we do the last name.
- 2:18:32So if I swap this around and do it like
- 2:18:35this and I agreed it will be reverse. It
- 2:18:38will it will take my last name and we'll
- 2:18:40plug it in the first name. So I what I
- 2:18:42always uh like to do I always like to be
- 2:18:45explicit with this and really say look
- 2:18:48first name equals Dave and then I put
- 2:18:50the last name in here. So you don't have
- 2:18:53to do this. Python will also work
- 2:18:54without but especially if you're working
- 2:18:56with multiple functions right now you
- 2:18:59can clearly see look this function is
- 2:19:01greed and I plug in the first name and
- 2:19:03the last name. So you add a little bit
- 2:19:05more code to it but it helps for
- 2:19:07readability. So now when I plug this in
- 2:19:09and I greet it, you'll find that it
- 2:19:12works correctly. And now what's also
- 2:19:13interesting now we can also like if you
- 2:19:16want to for whatever reason you can also
- 2:19:18swap it around. So now the order doesn't
- 2:19:21matter because we are explicit about it.
- 2:19:23So now if I run this even though the
- 2:19:26order is in reverse it still says my
- 2:19:29name correctly over here because we
- 2:19:31mapped them to the correct parameters
- 2:19:33over here. And now functions can also
- 2:19:35have default parameters. So what you can
- 2:19:38do over here whenever you specify the
- 2:19:40function let's say first name let's say
- 2:19:43you can put an equal sign in here and
- 2:19:45let's say we do John and then last name.
- 2:19:48So oh this is another interesting thing
- 2:19:50you can specify default values in here.
- 2:19:53Now you'll see that we get red squiggly
- 2:19:55lines in here and that means that here's
- 2:19:57an error. So this is another syntax
- 2:19:59thing. Whenever you want to specify
- 2:20:02default values, meaning that right now
- 2:20:05uh I for example don't have to put in a
- 2:20:07first name and then it will if there's
- 2:20:09no first name, it will default to John.
- 2:20:11But there's an order to things. So you
- 2:20:13need to uh you need to set the
- 2:20:17parameters that don't have a default
- 2:20:18value first and then you set the ones
- 2:20:21that have default values. So now it's
- 2:20:22just like it's just like swapping things
- 2:20:24around in different order. The
- 2:20:25functionality is still the same but this
- 2:20:27is just like what Python expects. So now
- 2:20:30if I store this function now let's see I
- 2:20:33can uh come in here and look now I can
- 2:20:36actually run this function and I only
- 2:20:38need to plug in the last name and it
- 2:20:40won't give me it won't give me an error
- 2:20:42because now it will simply say look okay
- 2:20:45first name is not there in that case I
- 2:20:47always take John and let's see we can do
- 2:20:51something similar for the last name and
- 2:20:53now because this is now also has a
- 2:20:56default value we can swap it around
- 2:20:58again just for the order of things. And
- 2:21:01now I don't actually have to plug
- 2:21:03anything into my function and I can just
- 2:21:05run it and it will run with the default
- 2:21:08values of John Doe. But I can simply
- 2:21:11override that and say look I want to
- 2:21:13greet it with Dave and vice versa. You
- 2:21:15can do it with last name, first name,
- 2:21:17both. So that is a way to work with
- 2:21:19parameters. You can plug them in. You
- 2:21:21can give them default values. You can
- 2:21:23change them to make your programs
- 2:21:25dynamic. Okay. So we've already seen
- 2:21:28that you can just work with multiple
- 2:21:30parameters. So you can add as much
- 2:21:31information as you want there. So let me
- 2:21:34quickly show you this example about
- 2:21:35calculator. So here you can see we have
- 2:21:38a function calculate total. We take the
- 2:21:40price, the tax rate and the discount.
- 2:21:42And now instead of doing simple print
- 2:21:44statements, we're going to apply some
- 2:21:46math. Right? So we we first calculate
- 2:21:49the tax by u multiplying the price with
- 2:21:52a tax rate. Then we have a final price.
- 2:21:54So we're storing v variables inside this
- 2:21:57function over here and then we print the
- 2:22:00final price using an fstring and then
- 2:22:02you can see over here order matters. So
- 2:22:05let's see because right now we are not
- 2:22:08specifying the uh names right we already
- 2:22:11saw this then order matters if we are
- 2:22:13specific about this that's why I always
- 2:22:16recommend to do that you cannot make
- 2:22:18that mistake so you'll always find that
- 2:22:21it's very clear that the discount is
- 2:22:24this this is the tax rate and this is
- 2:22:25the price so that's why I always
- 2:22:28recommend using these keyword arguments
- 2:22:30that you can see over here right you
- 2:22:32specify the function and then when you
- 2:22:34use them just make it explicit. Say the
- 2:22:36city is this instead of just like
- 2:22:37relying on the order uh of operations.
- 2:22:41Now, one more other thing that I want to
- 2:22:42show you here when it comes to functions
- 2:22:45is the notion of global versus local
- 2:22:50variables within Python. This is a
- 2:22:52common mistake and this can be really
- 2:22:54frustrating in the beginning. But
- 2:22:56whenever so by now you know you when you
- 2:22:59uh run a Python file, it goes from top
- 2:23:01to bottom, from left to right. But there
- 2:23:03is also a notion as to when we are
- 2:23:06inside a function or in a class for
- 2:23:08Python that information now becomes
- 2:23:10locally and I'll show you in a bit what
- 2:23:12that means but it essentially means that
- 2:23:14you can use that information within the
- 2:23:15function and within the function Python
- 2:23:17understands what it is but outside of
- 2:23:19the function we cannot use it. Let me
- 2:23:22show you an example. So let's take the
- 2:23:23calculate the calculate total over here.
- 2:23:26So we have this function and over here
- 2:23:29let's even make it simpler by setting by
- 2:23:32hard coding the price over here. So or
- 2:23:34let's say we we just take the price and
- 2:23:37we get rid of the tax and the discount.
- 2:23:40So we set the tax rate we hardcode it.
- 2:23:43So we set that to
- 2:23:458 and then we set the discount to 10.
- 2:23:49And actually let's make it even more
- 2:23:51explicit. So we put the tax rate here.
- 2:23:54So we plug that and then we can put the
- 2:23:57text right here and then we say the
- 2:24:00discount is 10 and then we put that
- 2:24:03here. So now we can see and you can also
- 2:24:06see how I can play with this. I can add
- 2:24:08a comment here. So we can for example so
- 2:24:10these are the default values and then
- 2:24:12over here we are going to do the
- 2:24:15calculation. So and then we do print
- 2:24:19final answer final price. Okay. So now
- 2:24:22we have made the function simpler in a
- 2:24:25way where it only takes the price as an
- 2:24:27input and we can calculate this and you
- 2:24:29can see this show up over here. So now
- 2:24:32what happens if we for example are in
- 2:24:35another part of our script later down
- 2:24:37the line and we want to continue. So we
- 2:24:39first made one calculation and now we
- 2:24:41want to maybe add something to it and we
- 2:24:43want to use the discount one more time.
- 2:24:45So if we for example now say look okay I
- 2:24:48want to use that discount again because
- 2:24:50we we set it to 10 right uh discount is
- 2:24:5310 over here you see if I just type in
- 2:24:54discount in here it will give us the
- 2:24:56yellow squiggly line saying discount is
- 2:24:59not defined so when I run this it will
- 2:25:01get an error even though this right now
- 2:25:05is all stored in memory it's in the same
- 2:25:06file discount is not available so you
- 2:25:09can see I'll actually move that discount
- 2:25:11is not available and that is because
- 2:25:14this is the difference between local and
- 2:25:16global variables. Whatever is inside a
- 2:25:19function is considered locally in Python
- 2:25:22and then outside the function we cannot
- 2:25:24use that. So there is an order to
- 2:25:26things. So if I for example now set over
- 2:25:29here at the top I set discount is let's
- 2:25:32say 20. I run this you'll find that we
- 2:25:37set the discount to 20. Now we'll get
- 2:25:40inside the function and it will perform
- 2:25:43the calculation. you you'll still see
- 2:25:45that the total is the same. So we get
- 2:25:47the same answer. We get the 98 and
- 2:25:49that's because inside this function,
- 2:25:51Python prioritizes the variable that you
- 2:25:54have over here. So even though first we
- 2:25:55say discount is is 10 because we go from
- 2:25:59top to bottom and from left to right, it
- 2:26:01will overwrite the 10 over here. Then it
- 2:26:04will perform here the calculation using
- 2:26:06all of the information in here. But then
- 2:26:08later when outside the function we refer
- 2:26:10to the discount, it is still 20. And
- 2:26:12this is really just one of those
- 2:26:13examples that you need to run into this
- 2:26:15a couple of times in the real world and
- 2:26:17think about like, oh look, I thought
- 2:26:19discount was 10, right? Why is it 20
- 2:26:21right now? And then why is it 20 right
- 2:26:23now? And they see, oh wait, it's a
- 2:26:25global variable over here and here is
- 2:26:27the local variable. Now, um I've shown
- 2:26:29you that if you don't have a global
- 2:26:34variable and you just have local
- 2:26:36variables in the function and you try to
- 2:26:38access it, it won't work. But here's the
- 2:26:42thing, it works the other way around. So
- 2:26:44within functions, we can use global
- 2:26:47variables. So if I specify the discount
- 2:26:49outside of the function, we can use that
- 2:26:52discount in here and Python will know,
- 2:26:54look, we have a global variable. So
- 2:26:56that's one level higher, it overrides it
- 2:26:58and we can use that inside a function.
- 2:27:00Now, this is not common, but it can uh
- 2:27:04it works. And why I said it's not common
- 2:27:07because typically you want to be very
- 2:27:09specific about this. and then still add
- 2:27:11the discount as a parameter because
- 2:27:14otherwise information can get lost
- 2:27:16meaning that if I specify the discount
- 2:27:18over here and then let's see I have the
- 2:27:20function and now we calculate the total
- 2:27:22price you can see that the output is
- 2:27:24still the same so this discount is
- 2:27:27referring to what's specified over here
- 2:27:29but now when you're working on real
- 2:27:30projects you often have multiple files
- 2:27:32multiple functions and now someone's
- 2:27:34working on this and you see this
- 2:27:36function over here and someone decides
- 2:27:37to get rid of this now this function
- 2:27:40doesn't work anymore because now uh
- 2:27:42let's see if I get rid of this. Now it
- 2:27:44says look there's no discount over here.
- 2:27:46So adding that and making that specific
- 2:27:48in this function is best practice in
- 2:27:51that case so that you always know look
- 2:27:53whenever you need to calculate the total
- 2:27:55we also need to plug in that discount
- 2:27:59specifically over here and it doesn't
- 2:28:00matter where we get it from but this is
- 2:28:02the place and that's how you don't
- 2:28:04forget it that it needs to be in there.
- 2:28:06So that was a little bit of playing with
- 2:28:08global local variables. You get some
- 2:28:10exposure to what it's like to work with
- 2:28:12the function to input the parameters and
- 2:28:15then how to call the function. And
- 2:28:17really it's about practice here. You
- 2:28:18need to see multiple examples. So later
- 2:28:21on when we're going to the practical
- 2:28:22Python in this session, we're going to
- 2:28:24actually do some stuff because I'm fully
- 2:28:26aware and this is some of the things
- 2:28:28that like really bothered me when I was
- 2:28:30learning Python in the beginning. You
- 2:28:32always see these like cookie cutter
- 2:28:33examples. So like look I can yes I can
- 2:28:36print someone's name but what what is
- 2:28:38actually the point of that right? So
- 2:28:41bear with me we need those fundamental
- 2:28:43building blocks. So then here I'm
- 2:28:44literally going to show you like how you
- 2:28:46can take a CSV file import it do
- 2:28:48calculations and then write it back to a
- 2:28:49file and that's really where things will
- 2:28:51start to click and we're going to reuse
- 2:28:53these building blocks again but we need
- 2:28:55to be step by step. Okay so then the
- 2:28:57final section in here of functions is
- 2:28:59returning values. So up until this point
- 2:29:03we created functions that just do
- 2:29:05something and then either just print
- 2:29:07something or do nothing. Functions can
- 2:29:09also return something and we do that
- 2:29:12with the return syntax over here. So
- 2:29:15let's dive into some examples. Okay. So
- 2:29:18let's say we have the simple function
- 2:29:20and we do a print and we take a and b as
- 2:29:25parameters and we just in this case we
- 2:29:28just print a and b. So this is now what
- 2:29:32we saw before very simple function we
- 2:29:34don't return anything. So now if we do
- 2:29:36add print and we call this and we plug
- 2:29:39in a= 5 and let's say b= 10. Okay, wait.
- 2:29:46We can for example do let's actually do
- 2:29:48plus. Okay, there we go. So now you can
- 2:29:50see we run this function and it just
- 2:29:52does a print statement but it just shows
- 2:29:55up in the terminal but now we cannot
- 2:29:57access that 15. It's like it's gone
- 2:29:59right now. It just it was a one-time
- 2:30:01print but now we there's nothing. Let's
- 2:30:04say we want to add something else to it.
- 2:30:06There's no way to to reference that 15
- 2:30:09or a variable where that is stored in.
- 2:30:11So that where that's where return comes
- 2:30:13in. So when we want to perform an
- 2:30:15operation and we also want to like store
- 2:30:18that and do something with it. So then
- 2:30:20what do you do? You add a return. So we
- 2:30:23do a return. We do add and we do a
- 2:30:26return. So we do this. We do the same
- 2:30:29stuff. So we do a and b. We plug that in
- 2:30:32and let's see colon. And now what we can
- 2:30:36do is instead of a print we do a return
- 2:30:39and then we say a and then we do plus b.
- 2:30:42If we now run this and we say add return
- 2:30:46and we call that function. The thing is
- 2:30:48in the terminal if I run this over here
- 2:30:51let's see oh sorry I should plug in the
- 2:30:54variables over here let's see we will
- 2:30:57also see 15 but there is a difference
- 2:31:00and that is when we do the at print so
- 2:31:02we just print it it will like printing
- 2:31:04is just show showing it but we cannot do
- 2:31:06anything with that later whereas
- 2:31:08returning it it is actually returning it
- 2:31:11and we can capture and we can store that
- 2:31:12information and the way we do that is
- 2:31:14simply by saying look we have our
- 2:31:16function and it outputs something and we
- 2:31:19store that into a variable. So now what
- 2:31:22we can do now if we run this now you'll
- 2:31:25see we'll we'll just run this line and
- 2:31:27you won't see the 15 show up here
- 2:31:30because it's stored in result and now
- 2:31:32result is something that we can use and
- 2:31:35we can do whatever with that. So now we
- 2:31:36can do + 50, we can do + 20 and that
- 2:31:39information is stored. And here it's
- 2:31:42also important to let's see to give a a
- 2:31:45quick distinction between the
- 2:31:47interactive session that we use all the
- 2:31:49time and running it in the terminal uh
- 2:31:51when programs run in the background for
- 2:31:53example because because when I for
- 2:31:54example comment this out, I select
- 2:31:56something and I do command forward slash
- 2:31:58or on Windows uh control slash you can
- 2:32:00comment out entire blocks very easy.
- 2:32:03This helps if you want to run your
- 2:32:04program without running this. For
- 2:32:06example, if I now run it in the
- 2:32:08terminal, let's see. So, we do run in
- 2:32:10dedicated terminal. You can see this
- 2:32:12show up. Now, you can see that it will
- 2:32:14it will print the 15 out over here. So,
- 2:32:16you'll see that if we close this out and
- 2:32:19now this and I encourage encourage you
- 2:32:21to follow along with this and also like
- 2:32:23play with like commenting these blocks
- 2:32:25out and then moving quickly between
- 2:32:27them. Now, if we run this, you'll see
- 2:32:30that we run it, there's no 15. So this
- 2:32:33is a difference between the interactive
- 2:32:35session and the terminal if you do it in
- 2:32:37the interactive session. Even though
- 2:32:39it's not like printing it, we can still
- 2:32:42see the the output. But that's just
- 2:32:44something that you have to keep in mind.
- 2:32:45But there's there is under the hood
- 2:32:47there's a difference because this 15 is
- 2:32:49something that we that we can use and
- 2:32:52this is print statement that that just
- 2:32:54shows up because let me show you if I
- 2:32:56now do so we have the result you saw we
- 2:32:58can store that right we have that 15 but
- 2:33:00if we do that over here so we say if the
- 2:33:03add print so we do print results equals
- 2:33:06we can save the output we will see the
- 2:33:0815 but now when we do print result it's
- 2:33:11empty there's nothing here so little
- 2:33:14tiny difference but something in
- 2:33:15beginning that you need to get used to.
- 2:33:17Okay. And so with that we can perform
- 2:33:20all kinds of calculations. So let's take
- 2:33:22the following example over here. Let's
- 2:33:24copy paste it. So here we have a
- 2:33:25function to calculate the area. So it
- 2:33:27takes as an argument the width and the
- 2:33:30height and then we calculate the area by
- 2:33:33multiplying it and then we return the
- 2:33:34area. So we can also store in between
- 2:33:38variables. We can expand on them do
- 2:33:40calculations and then return the
- 2:33:42variable. So we don't specifically have
- 2:33:44to do the return statement here. Whereas
- 2:33:47this would also work. It would be
- 2:33:49exactly the same. But this is a little
- 2:33:51bit easier to also help you as a
- 2:33:54programmer think through your program,
- 2:33:56right? What's the goal? First, we want
- 2:33:57to calculate the area. How do we do
- 2:33:59that? Width time height. Okay. And the
- 2:34:01area is the stuff that we want to
- 2:34:03return. So if I run this and I calculate
- 2:34:06the area, we can print the room size and
- 2:34:09it's 120 square ft. And we can simply
- 2:34:14for example come in here and let's say
- 2:34:15you know we want to er uh we want to add
- 2:34:17a margin of error. So we want to say
- 2:34:19look area is area and then we do it
- 2:34:23times 1
- 2:34:25let's see let's add a 5% margin and then
- 2:34:28you'll find that it's bigger and these
- 2:34:31returned values we can use them later.
- 2:34:33So if I take this example over here. So
- 2:34:36let's say we have a very simple function
- 2:34:38to double a number. We can have a result
- 2:34:40which is now uh 10 because we input five
- 2:34:43and the function doubles it number times
- 2:34:45two. We get that result and then we can
- 2:34:47use it in another expression. So let's
- 2:34:50say we have the total we do double five
- 2:34:53double3 and then we get 16. So you can
- 2:34:56see how we can now start to combine
- 2:34:58things right. We take this function and
- 2:35:00we use it just in an expression. So
- 2:35:03instead of just first storing the
- 2:35:04results we look double five that will
- 2:35:08output 10 and double three will output
- 2:35:11six and we can simply combine that right
- 2:35:14like this will be 10 we store it in
- 2:35:16total and now we have total and we can
- 2:35:19print this over here and we can also use
- 2:35:21it in a condition. So we can say look if
- 2:35:23double 7 is bigger than 10 we say it's a
- 2:35:27big number. So the like this is this
- 2:35:30this can get a little bit tricky to to
- 2:35:32work with but that's why I why I love
- 2:35:34the interactive session because you can
- 2:35:36literally look at okay what does double
- 2:35:387 do by selecting this using the uh
- 2:35:40arrow command uh arrow on your keyboard
- 2:35:43and shift and I can look this is 14 so
- 2:35:46now I do if double 7 which is 14 is
- 2:35:50greater than 10 it's a big number so now
- 2:35:52if I run this it will say big number but
- 2:35:54if I say let's say we do three and I run
- 2:35:57this it will not do anything. And within
- 2:35:59functions, we can also return multiple
- 2:36:01values similar to how we could also
- 2:36:03input multiple parameters, right? So,
- 2:36:06let's do a let's do a just a simple
- 2:36:09function just as an example. Uh we
- 2:36:12define it and then say look, we have a
- 2:36:14we have our numbers. Let's say we have
- 2:36:17our numbers which is a list. We do 1 2 3
- 2:36:214 5. You should actually do some spaces
- 2:36:24in here for clarity. So we have the
- 2:36:27numbers in here and then what we want to
- 2:36:28return or let's say first we do we do
- 2:36:31the first number and that is going to be
- 2:36:34our we have our numbers and then
- 2:36:36remember this is a list right and we can
- 2:36:38index that by using the uh square
- 2:36:40brackets and then we do index zero this
- 2:36:42refers to the one so this is the first
- 2:36:44number and then let's say we do the last
- 2:36:48number and that is going to be uh let's
- 2:36:51see we take that same thing numbers and
- 2:36:54then we do minus one and then what we
- 2:36:56can do is we can return first number and
- 2:36:59then we do a comma. So this is syntax
- 2:37:01again. So it's not end or n. We do a
- 2:37:04comma to say look we want to return the
- 2:37:06first number and we want to return the
- 2:37:08last number. And then what we can do is
- 2:37:11we can for example let's say if we have
- 2:37:13this here in memory we can call our
- 2:37:16simple uh function with doesn't take any
- 2:37:19input parameters right now. And then if
- 2:37:22we want to store that we could for
- 2:37:23example say first number and then comma
- 2:37:26again last number and we can capture
- 2:37:29that. So now if we run this you'll find
- 2:37:32that we have first number one last
- 2:37:34number is five. And the thing to keep in
- 2:37:36mind here is that the variables over
- 2:37:38here do not have to be the same as what
- 2:37:41we put over here. So we could for
- 2:37:43example just as well do f and l and it
- 2:37:45would also work. So now we have if we we
- 2:37:48do it via print statement we could print
- 2:37:49our f which is one or we could just look
- 2:37:51at f over here is one and in a similar
- 2:37:54fashion our l is five. So that's how you
- 2:37:58return multiple values from a function.
- 2:38:01And that also wraps up the section here
- 2:38:04on functions where the most important
- 2:38:06thing to keep in mind here is that when
- 2:38:08you're using functions, if you use a
- 2:38:10print statement, it just displays it.
- 2:38:12When you want to return something, which
- 2:38:14is what you often want to do in the real
- 2:38:16world, use the return. And in the
- 2:38:19beginning, you'll make a lot of mistakes
- 2:38:21with the syntax. You have to do it a
- 2:38:23couple of times before it really clicks.
- 2:38:25def function name colon indentation it
- 2:38:28will get more and more familiar. Okay,
- 2:38:30so with that let's dive into the next
- 2:38:33section se section called external
- 2:38:35tools. So here we are going to get into
- 2:38:39one of Python's core tracks where we can
- 2:38:42actually use a lot of like out ofthe-box
- 2:38:45tools that other people have created for
- 2:38:47us to make our life as a programmer much
- 2:38:51more fun and way easier. So, we already
- 2:38:54talked about packages, right? The pip
- 2:38:56install things. In the beginning, I
- 2:38:57showed you the request library. So, now
- 2:38:59we're going to dive a little bit deeper
- 2:39:01into that and show you a little bit more
- 2:39:03examples. So, why Python is so awesome
- 2:39:06and why I also like back in university.
- 2:39:09So, this is 10 years ago when I when it
- 2:39:11really start to click for me working
- 2:39:13with Python was beyond all of the boring
- 2:39:16stuff that they showed in the lectures
- 2:39:18like what I show you right now. I know
- 2:39:19this is boring, right? Writing a
- 2:39:21function, like doing a print statement.
- 2:39:22Yeah, but but Dave, what can we do with
- 2:39:24it? This is where it gets cool because
- 2:39:26now with simple packages that we can
- 2:39:28import, we can scrape an entire website.
- 2:39:30We can perform data analysis. We can
- 2:39:32import AI and machine learning models.
- 2:39:34We can use external APIs and we can
- 2:39:36automate stuff on our computer. And
- 2:39:38building something like that from
- 2:39:40scratch as a beginner would be
- 2:39:43impossible. But I'm going to show you
- 2:39:44how you can import those packages, work
- 2:39:46with them, and it's going to be super
- 2:39:48fun. So let's first quickly cover some
- 2:39:50terminology and then we'll get into the
- 2:39:52examples. But in Python there is a big
- 2:39:55difference between built-in packages.
- 2:39:57These already come with Python. So you
- 2:40:00can use them right now without an
- 2:40:01installation and external libraries. You
- 2:40:04need to install those for example
- 2:40:05through pip first. That's a distinction.
- 2:40:07Not everything comes uh out of the box.
- 2:40:10Now here's some terminology that you
- 2:40:12should be aware of. So this will get you
- 2:40:14get more familiar with this over time
- 2:40:16but you sometimes hear me refer to like
- 2:40:18now I'm talking about packages and
- 2:40:20before we were uh creating functions
- 2:40:22right later we'll get into classes and
- 2:40:24you also have what's called modules. So
- 2:40:27here's a quick overview in Python as
- 2:40:29Python programmers among each other when
- 2:40:31we say module we mean a single Python
- 2:40:34file. So our hello.py Pi over here. You
- 2:40:38could consider this a module. And right
- 2:40:41now we like this is all we know, right?
- 2:40:43We have only have worked with a single
- 2:40:45Python file. But when we go beyond that,
- 2:40:47what you actually do in the real world
- 2:40:49is you create all kinds of files that
- 2:40:51work with each other and that talk with
- 2:40:53each other. All of these files you can
- 2:40:54call those modules, right? So then a
- 2:40:56package is a folder containing multiple
- 2:40:58modules. So we'll we'll cover this
- 2:41:01later. When we install a package, you'll
- 2:41:03find that we can use various bits and
- 2:41:05pieces from it. And then within the uh
- 2:41:08packages and within the modules, we can
- 2:41:10then import the functions. And that is
- 2:41:12really where we get to the core
- 2:41:13functionality of what we can do with it.
- 2:41:15Right? So think of it like this. There's
- 2:41:17kind of like a mental model. A module is
- 2:41:19like a toolbox or tools in there. A
- 2:41:21package is like a garage with multiple
- 2:41:23toolboxes. So there's lots of stuff in
- 2:41:25here. Then a function is a specific tool
- 2:41:28from the toolbox like a hammer or a
- 2:41:30screwdriver. You you really need it to
- 2:41:31solve a particular problem. And then a
- 2:41:33class is like a blueprint for building
- 2:41:35tools. I think this is a really good
- 2:41:37mental model to keep in mind right now.
- 2:41:39Okay. So let's look at an example of
- 2:41:41imports. And when you are importing uh
- 2:41:45packages or modules you'll start at the
- 2:41:48very top of the of the script. So we do
- 2:41:50that at the top. That is just how we do
- 2:41:52that in Python. And we also need it
- 2:41:54before we can use it really. So if I
- 2:41:57come in here and I show you I show you
- 2:41:59first show you this step by step. There
- 2:42:00are comments in here. uh we don't need
- 2:42:02those but this is just to explain how it
- 2:42:04works. We can do an import statement. So
- 2:42:07this is the syntax import and then for
- 2:42:09example we do math. So this is a builtin
- 2:42:12module that is available within Python.
- 2:42:15We don't have to install it. I can
- 2:42:17simply run this and it will say look
- 2:42:19import math and it will say okay this is
- 2:42:21fine we can now use this. So I can for
- 2:42:24example now use this module and I can
- 2:42:26use a function from this module by
- 2:42:28taking math dot and then for example
- 2:42:31taking the square root which is sqrt
- 2:42:34short for square root and I can plug in
- 2:42:3616 and I can run that and now the output
- 2:42:39is four. So now instead of having to
- 2:42:41come up with like how do I calculate the
- 2:42:42square root and how do I need to create
- 2:42:44a custom function for that I just use
- 2:42:46math and then I just use the square root
- 2:42:49function. So that's how that works and
- 2:42:51again like I've said you don't need
- 2:42:53this. So you it could be as simple as
- 2:42:55just import math and then here we do the
- 2:42:58square root and now we we can store it
- 2:43:00right that's how we can work with it.
- 2:43:02But there is another way that's the
- 2:43:04pattern over here. We can also import
- 2:43:06specific items from a module. And here's
- 2:43:10the syntax instead of just starting with
- 2:43:12the import. So import math, we do from
- 2:43:16math, import, and then the specific
- 2:43:19functions that we want to use. So it's
- 2:43:22very readable. It reads just like plain
- 2:43:24English. That's why it's really nice.
- 2:43:25And we can now instead of having to do
- 2:43:28math dots square root, you'll see the
- 2:43:32squiggly lines because Python will say,
- 2:43:34look, I don't know what math is because
- 2:43:36we didn't import math. We did from math.
- 2:43:39So we looked into the toolbox and we
- 2:43:42just took the square root and the pi. We
- 2:43:44just took the hammer and the wrench, not
- 2:43:46the entire toolbox. So pi python doesn't
- 2:43:48know what the toolbox is right now, but
- 2:43:50we do know what square root is. And we
- 2:43:53can plug in 16 and it works in a similar
- 2:43:55way. So this is an introduction to how
- 2:43:57you work with imports. And almost every
- 2:44:00Python file that you will create will
- 2:44:03start with some types of imports. So
- 2:44:05this is really important to get used to.
- 2:44:08So, Python has some very useful built-in
- 2:44:11modules. So, for example, take the
- 2:44:13random library and I'm just going to
- 2:44:15show you these examples over here. So,
- 2:44:18we can import the random module. So,
- 2:44:20we'll do the entire thing. Import random
- 2:44:22and we can use module functions. So, in
- 2:44:25here we can say look, we can do random
- 2:44:27and then rand int from random integer is
- 2:44:30a function that's available in here and
- 2:44:33it takes as arguments a starting a
- 2:44:36starting point and an end point. So it
- 2:44:37gives a range and then we say look we
- 2:44:39want a random number uh between 1 and 10
- 2:44:41and now it gives us nine but we can run
- 2:44:44this over and over and over again and
- 2:44:46you'll see that every time we run this
- 2:44:48it will be different. So that's how we
- 2:44:50can rate random numbers but we can also
- 2:44:52do a random choice. So whenever we can
- 2:44:55also have a list and we can say random.
- 2:44:57Choice and then in here if we run this
- 2:44:59let's see um apple banana orange and
- 2:45:02then we get what do we get? All right.
- 2:45:06So, if you want to start an online uh
- 2:45:09gambling app or casino, you can do that
- 2:45:12with Python. You just plug in a bunch of
- 2:45:14random integers and random choices and
- 2:45:16you can now let people bet on whether
- 2:45:18it's going to be an apple, banana, or an
- 2:45:20orange. Well, there there's your next uh
- 2:45:23project idea that you can start with.
- 2:45:25Okay, so now coming back to other
- 2:45:28built-in modules. There are plenty and
- 2:45:30here are some useful ones. So for
- 2:45:32example we have the datetime uh module
- 2:45:34the library where we can work with all
- 2:45:36kinds of dates. So we can get the date
- 2:45:38right now we can get the time we can
- 2:45:40calculate what the time will be or the
- 2:45:42date will be in a week from now. Uh we
- 2:45:44can interact with the operating system.
- 2:45:46We can work with JSON data and these are
- 2:45:49all libraries like I want to I just want
- 2:45:51to show it to you right now. But there
- 2:45:53is really a lot to these. So the best
- 2:45:56way to like really learn about this. So
- 2:45:58look, so now we have import daytime, we
- 2:46:00have today, and then we can see today uh
- 2:46:02today's date. But knowing
- 2:46:05what how to use this. So daytime uh
- 2:46:08knowing that you need to do date today,
- 2:46:10that's all stuff where for example you
- 2:46:12go to chat GPT how what can I do with
- 2:46:16the daytime lip in Python? this is
- 2:46:20really the way to go because even for me
- 2:46:22like under or remembering the very
- 2:46:24specifics of oh the daytime library how
- 2:46:27do I specifically get the time right now
- 2:46:29in a specific format I don't know that
- 2:46:32and I don't have to remember that
- 2:46:33because AI is there for me so now you
- 2:46:36can see look we can get the current date
- 2:46:37and time you can also just get the date
- 2:46:39and time you can also get specific dates
- 2:46:42or time so there's so much stuff that
- 2:46:44you can do with it and all kinds of
- 2:46:46formatting but that's the beauty of AI
- 2:46:47right now you just need to be aware of
- 2:46:49oh look whenever I want to do something
- 2:46:52in Python with dates we have the daytime
- 2:46:55library and if you forget even that you
- 2:46:57can just ask chat GBT like what's that
- 2:46:59library again that you can do stuff with
- 2:47:01dates with in Python it be look it's the
- 2:47:03daytime library and that's how you do it
- 2:47:05so with this you can like figure out all
- 2:47:07kinds of uh calculations uh everything
- 2:47:10that you want to do with a date is
- 2:47:12possible in here okay and then we have
- 2:47:14working with the operating system so
- 2:47:17Python can also like do literally do
- 2:47:19anything on on your computer. It can can
- 2:47:22create files. It can browse files. It
- 2:47:23can create folders. It can read files.
- 2:47:26We can do all of that stuff. And we'll
- 2:47:27we'll see some examples later down the
- 2:47:29line. So I can come in here. So that's
- 2:47:31the OS from the operating system. So we
- 2:47:34import it and we can say look what's the
- 2:47:36current uh working directory. So we can
- 2:47:37print it. You can say look uh we're
- 2:47:39currently in here in my Dropbox in my
- 2:47:41Python projects. So this is where we're
- 2:47:43currently at. So it understands that.
- 2:47:45And we have one to work with JSON data
- 2:47:47which we'll cover later. is very common
- 2:47:49when you're working with AI. So there's
- 2:47:50a lot of stuff in the Python uh
- 2:47:52programming language already that we can
- 2:47:54use. All right, then quick uh summary on
- 2:47:58importing methods. So we can import the
- 2:48:00entire module, right? We've seen that we
- 2:48:02can import specific functions by doing
- 2:48:04from module import and then the function
- 2:48:07name. We can also import with an alias.
- 2:48:10So let's say you have the pandas library
- 2:48:12which we will uh use in the in the next
- 2:48:14lessons. you'll find that we're going to
- 2:48:16do import pandas as then we import it as
- 2:48:19pd. So whenever we want to use pandas,
- 2:48:21we don't just have to write it out. We
- 2:48:23do pd. And in Python, this is also like
- 2:48:25one of those um styling things where for
- 2:48:28some libraries, there's just like we all
- 2:48:30as developers have agreed agreed like if
- 2:48:33you use pandas, you import it as pandas
- 2:48:35spd. That's just the way we do it. Do
- 2:48:37you have to do it like that? No. Uh but
- 2:48:40that's using an alias. So that's also
- 2:48:42one more thing that there is. You can
- 2:48:43also import everything from a module. So
- 2:48:45by using the asterisk, you don't want to
- 2:48:48do that. Okay. So then let's get into
- 2:48:50installing packages. And we've already
- 2:48:53uh seen a sneak preview of this. So now
- 2:48:55we need to get back to the terminal
- 2:48:57again. Remember what that was, right? So
- 2:48:59quick refresher. Let's see. We're in
- 2:49:01here. Let's open up the side window
- 2:49:03again to uh quickly get zoom out a
- 2:49:06little bit. Look where are we? We are in
- 2:49:08our Python forai folder and we have this
- 2:49:11virtual environment, right? And uh if we
- 2:49:14want to open up the terminal, you go
- 2:49:15over here, you do new terminal. And
- 2:49:18there we are. And now remember, right,
- 2:49:20we can use the pip install. So now we
- 2:49:21can do pip install. We already installed
- 2:49:24the request library. So you can do that
- 2:49:25one more time. It will probably say look
- 2:49:27this is already satisfied. And we can
- 2:49:28for example also let's do a pip install.
- 2:49:31Do pandas. Let's do the pandas library.
- 2:49:33Well, because we'll use that uh later
- 2:49:35on. So this will take some time. We'll
- 2:49:36go through everything. So this is how we
- 2:49:39install packages in there. And once
- 2:49:41that's done, what we can now do, I can
- 2:49:44now do an import. So let's do uh import
- 2:49:47pandas. And remember pandas, you import
- 2:49:49that as an alias, right? Um so we do
- 2:49:52import pandas pd. And now let's see if
- 2:49:55this works. And there we go. We can now
- 2:49:57import the pandas library. But if I try
- 2:49:59to import a library that's not installed
- 2:50:01yet. So for example, let's do from let's
- 2:50:04say from pientic import uh base. Let's
- 2:50:08do base model. So if I do it like this
- 2:50:11you can see uh there's no module named
- 2:50:13paidentic. So this is a very common
- 2:50:15issue in the beginning even when you
- 2:50:17install pandas for example and you want
- 2:50:19to try and import it if you get module
- 2:50:21not found errors it's not installed or
- 2:50:24it's not installed in the correct
- 2:50:25environment. So you may open up a
- 2:50:28terminal that where your virtual
- 2:50:30environment is not activated. So you
- 2:50:32don't see the fan over here. That's one
- 2:50:34of the most common beginner mistakes and
- 2:50:36it can be super frustrating because then
- 2:50:38you're following along and you're typing
- 2:50:40everything but then you just need to
- 2:50:41select the right Python interpreter and
- 2:50:44then make sure when you open up the
- 2:50:46terminal when you have the right
- 2:50:48environment selected that the virtual
- 2:50:50environment is activated. So that's one
- 2:50:52of the most common mistakes that you'll
- 2:50:54run into. Now when it comes to packages
- 2:50:56we can also install specific versions.
- 2:50:58So if we for example look up this
- 2:51:00request library and do we do request pip
- 2:51:02and we go to the Python package index
- 2:51:05you can find the whole history of the
- 2:51:07request library and you can see that
- 2:51:09currently the latest version uh is this
- 2:51:11one over here like usually you can go to
- 2:51:14the uh to the GitHub page as well. Yeah,
- 2:51:17here's the source. So you can literally
- 2:51:19see like all this is is just a
- 2:51:22collection of Python files that other
- 2:51:23people already created and you can see
- 2:51:25all of the info here. You can see the
- 2:51:26examples. Uh so here you can also say
- 2:51:28look this is now the latest version but
- 2:51:31if I want to install a specific version
- 2:51:34or I want to lock a certain function
- 2:51:36because like sometimes things change and
- 2:51:37you have an older project where you need
- 2:51:39a specific version otherwise you get
- 2:51:41errors you can do it like this you do
- 2:51:43pip install and you do two equals so
- 2:51:46that's uh it's not one it's two and then
- 2:51:48if I come in here let's see we open up
- 2:51:50another terminal so the request library
- 2:51:53is already installed but I can override
- 2:51:55this by running this command and now it
- 2:51:59will downgrade it. So you will find over
- 2:52:01here it successfully uninstalled the the
- 2:52:04the version that we had. So it was the
- 2:52:05latest version and it successfully
- 2:52:07installed an older version in this case.
- 2:52:11So that's also something that you can
- 2:52:12do. You can also install multiple
- 2:52:14packages. So on one line you can do for
- 2:52:16example you can install pandas, numpy,
- 2:52:18mattplot lip all in once. And let's see
- 2:52:22let's come over here. It will totally
- 2:52:24work. So we'll run this. As you can see
- 2:52:27over here, this is all finishing going
- 2:52:29after each other. So that's how you can
- 2:52:30install multiple packages. But when
- 2:52:33you're working with Python, there's one
- 2:52:34more key concept that you'll find in
- 2:52:36almost every tutorial that you'll follow
- 2:52:38and it's also essential when you are
- 2:52:40working together with other people on a
- 2:52:42project. And that is the notion of a
- 2:52:43requirements.txt
- 2:52:45file. So this is a file that we can
- 2:52:47store inside our project where that
- 2:52:50looks something like this where there is
- 2:52:51a specification of all the packages that
- 2:52:53we use and also the versions and then
- 2:52:56instead of new members manually adding
- 2:52:59everything we can run a simple a single
- 2:53:01command that will install everything
- 2:53:04from that text file and that text file
- 2:53:07is going to be the requirements.txt
- 2:53:09file. So we can in a similar fashion we
- 2:53:12don't also have to create this manually.
- 2:53:14we can simply work on our project and
- 2:53:15then whenever we want to freeze all of
- 2:53:18the requirements, we can hit a pip pip
- 2:53:20freeze and then uh push it to
- 2:53:21requirements.txt.
- 2:53:23So let's see what that looks like in
- 2:53:25action. So first uh I'm I want you to
- 2:53:28create one from scratch. So what we can
- 2:53:29do is we can simply copy
- 2:53:30requirements.txt.
- 2:53:32We come in here and let's see I am going
- 2:53:35to create a new file requirements.txt.
- 2:53:38So this is just a text file. We can put
- 2:53:40anything in here. And now what we can do
- 2:53:41is for example we can come in here. We
- 2:53:44can copy this specific section over
- 2:53:47here. Come back to our project. And now
- 2:53:50we have a requirements.txt file. And now
- 2:53:53what we can do is we can use the
- 2:53:54following following command. So it's pip
- 2:53:56install-r requirements.txt.
- 2:53:59So let's copy this. Come back to our
- 2:54:01project. So make sure you have your
- 2:54:02virtual environment selected. We can
- 2:54:04open up a new terminal and let's see
- 2:54:07that will open. It will load the
- 2:54:08environment. And now if I do this pip
- 2:54:10install our requirement.txt,
- 2:54:13we run this, it will install everything
- 2:54:15that's in here. And now we have
- 2:54:17successfully uh added all of that to our
- 2:54:19environment. Now if I close out of this
- 2:54:22and now I can show you how the pip
- 2:54:24freeze works. So let's say we completely
- 2:54:25get rid of this and we don't keep track
- 2:54:27of that, but we were just working on our
- 2:54:29project. We do pip install this, pip
- 2:54:30install that, and now we want to put
- 2:54:33that into a requirements.txt file. We
- 2:54:36can come over here and we can do pip pip
- 2:54:38freeze and we can use the arrow sign to
- 2:54:40put it in requirements.txt.
- 2:54:43So we can copy this. Come over here. We
- 2:54:46do pip freeze requirements.xt. And what
- 2:54:49you'll find right now is now it's
- 2:54:50creating the txt file in here and you
- 2:54:52find all of the exact same verses in
- 2:54:55there. Now what's also one nice thing
- 2:54:57about working with Visual Studio Code.
- 2:54:59If you are in here for example and let's
- 2:55:02say we get rid of our virtual
- 2:55:03environment. So let's say this is a
- 2:55:06fresh new project that someone else was
- 2:55:08working on and they shared it with you.
- 2:55:09So there are requirements in here. What
- 2:55:11we can now do we can follow the same
- 2:55:13process where we do look we want to
- 2:55:14create a virtual environment. We say we
- 2:55:16use fence and now we can say we want to
- 2:55:19use this python installation. We use the
- 2:55:20latest one. And now because there is a
- 2:55:22requirement.txt file in our folder it is
- 2:55:25asking us like look do you want to
- 2:55:27install any dependencies. So we can say
- 2:55:29yes and we do okay. And now it's
- 2:55:31creating the environment and also
- 2:55:32installing the dependencies in one shot.
- 2:55:35So this is something like I said very
- 2:55:37common whenever you are working on an
- 2:55:40external project. Someone is sharing
- 2:55:41code via git and github that we will
- 2:55:43show uh I will introduce to you later if
- 2:55:45you're new to that. This will always be
- 2:55:47a starting point because they'll likely
- 2:55:49be using packages and you want to make
- 2:55:51sure you get all the same versions so
- 2:55:53you you will exactly know that the code
- 2:55:55will work. All right. So that's a quick
- 2:55:57introduction to how you can install
- 2:55:59external packages and then also how you
- 2:56:01can import them right now. How do you
- 2:56:03find packages? Well, right now the best
- 2:56:05place to do that really is chatgbt.
- 2:56:07There are lots of list and websites. But
- 2:56:09right now if you want to solve a problem
- 2:56:10with Python, you should really ask like
- 2:56:12how can I do this in Python and are
- 2:56:14there any packages that can help me with
- 2:56:15that? And GBT will literally give you a
- 2:56:17list of all the packages that are useful
- 2:56:19for that, how to install them, how to
- 2:56:20work with them and we'll point you to
- 2:56:22the documentation. Okay. Common
- 2:56:24mistakes, import errors. make sure that
- 2:56:26is installed correctly. Naming conflicts
- 2:56:29can also be an issue. So this is also
- 2:56:32one of the things you should be aware
- 2:56:33of. If you for example import uh daytime
- 2:56:36and then you create a variable now the
- 2:56:39daytime then the import is then gone.
- 2:56:41You override it. Remember right so when
- 2:56:43we for example were talking about the
- 2:56:44discount set discount to 10 and then you
- 2:56:46if you override that it's 20. Similar is
- 2:56:49with import. It's just a variable name.
- 2:56:51It's just a placeholder for uh Python.
- 2:56:53So that's something you should be aware
- 2:56:55of. Okay, so we've covered external
- 2:56:59tools introduction importing packages
- 2:57:01both builtin um and external. Now let's
- 2:57:05cover working with APIs. So this is one
- 2:57:08of the it's a really common thing when
- 2:57:10you are uh working on AI projects and
- 2:57:13that's why I want to explain it already
- 2:57:15here. it it may already be a little bit
- 2:57:17more advanced, but this is just such a
- 2:57:20core skill that you need to understand
- 2:57:21because when you are building AI systems
- 2:57:24and agents, what you are essentially
- 2:57:26doing is you're taking information from
- 2:57:28some type of input from some type of
- 2:57:30system and you want to do something with
- 2:57:31that, right? You want to pull data from
- 2:57:33a CRM. You want to get order information
- 2:57:35from Shopify or Wukcommerse or you want
- 2:57:37to send a message through Slack or an
- 2:57:39email service or use the models from
- 2:57:41OpenAI or Entropic. That's all done
- 2:57:44through using APIs. So, let's look at
- 2:57:47this. And for this, we're going to use
- 2:57:49the requests library which we've already
- 2:57:52installed. And I'm going to show you how
- 2:57:54to work with a free and open-source API.
- 2:57:57This is a weather API. So, let's go
- 2:58:00through this uh step by step. And you
- 2:58:02can for this you can actually copy paste
- 2:58:03it because I don't want you to fully
- 2:58:05like type this over and then we are
- 2:58:07going to work with this. So, let's see.
- 2:58:08Don't save this. Uh let's go. We can
- 2:58:11close this out again. Okay, there we go.
- 2:58:14Back into things. So from the top, we
- 2:58:17import the request library. The quest
- 2:58:19request library is a Python library that
- 2:58:22we can use to interact with APIs. Now
- 2:58:25the uh URL that we have over here is
- 2:58:28just something that you need to look up
- 2:58:30in this case. So every API that you use
- 2:58:33will have instructions. You can look
- 2:58:35into the documentation says look here's
- 2:58:36the URL and here are parameters that you
- 2:58:39can plug in there in order to interact
- 2:58:41with this uh API. So you can see this is
- 2:58:44api.openo.com
- 2:58:46or v1 forecast and then what we need to
- 2:58:48plug in is a latitude and a longitude.
- 2:58:51So that's how we can get the weather
- 2:58:53information from a location. Here we we
- 2:58:57know that the latitude and longitude of
- 2:58:59Paris like we just set that to this.
- 2:59:01This is not something you have to
- 2:59:02remember but this is just as an example.
- 2:59:04this AI gave this to me. So, we're
- 2:59:06assuming this is correct. And then we
- 2:59:08have the URL. And look what you can see
- 2:59:10right now. Now, we have built up the URL
- 2:59:13over here. And you can see that because
- 2:59:15we were using frings, you can now see
- 2:59:17that the latitude and the longitude are
- 2:59:20plugged in. Right? So, now we're
- 2:59:22bringing more and more of what we've
- 2:59:24learned together. So, this is an F
- 2:59:25string. Now, we can use the request
- 2:59:27library. So we do request and then we do
- 2:59:31get using the URL over here to make an
- 2:59:34API call. So let's run that. And you can
- 2:59:37see we have a green check mark. Let's
- 2:59:39have a look at what's in here. We get a
- 2:59:42response that says 200. And in the world
- 2:59:44of APIs that means 200 is okay. 200 is
- 2:59:48good. And for now you don't have to
- 2:59:50understand why. We're just going through
- 2:59:52this exercise. Uh so just follow along
- 2:59:54with me. And what we can now do is the
- 2:59:56response that we got back, we want to
- 2:59:59look at the data that's underneath that.
- 3:00:01And for that within the request library,
- 3:00:03we can call thejson function to have a
- 3:00:07look at the data. So now we do that. And
- 3:00:09then if we print the data or look at the
- 3:00:12data over here, you can see that this is
- 3:00:14the information that we got back from
- 3:00:16the API. So you can see the input
- 3:00:18parameters let long. And then over here,
- 3:00:21let's see. You can see like the current
- 3:00:24time over here. So this is the time in
- 3:00:27uh UTC right now in the UTC time zone.
- 3:00:30And you can see that let's see over
- 3:00:32here. Make sure we can see everything.
- 3:00:34We have the temperature and then the
- 3:00:36interval. And we can see it's uh 13.1°
- 3:00:41C. The interval here is seconds. So this
- 3:00:44is really this is really cool, right? So
- 3:00:45now we were able with just a few lines
- 3:00:49of Python to extract and capture the
- 3:00:52information from what's the weather
- 3:00:53right now, right now in Paris. Okay, so
- 3:00:56now you can hopefully see that this is
- 3:00:58actually starting to get a little bit
- 3:00:59useful, right? We can actually do stuff
- 3:01:01and let's actually have a look at let's
- 3:01:03do this one more time and let's look at
- 3:01:05this data object over here that we're
- 3:01:08getting back. So if we look at this and
- 3:01:11if we look at the type of this data that
- 3:01:15we have over here, we can see that this
- 3:01:16is a Python dictionary. And this means
- 3:01:20that what we can do right now based on
- 3:01:22everything that we learned about using a
- 3:01:24dictionary, we can also access specific
- 3:01:27keys and then the values in there using
- 3:01:30the keys. So if in our program right now
- 3:01:32for example, we just wanted to get the
- 3:01:34temperature. What we could do is we
- 3:01:35could either look at the data over here
- 3:01:37and we say look we have at the top level
- 3:01:39over here you so you need to be aware of
- 3:01:41the small indents over here which are
- 3:01:42nested dictionaries. You can see that
- 3:01:45here we have under current we have a a
- 3:01:48nested dictionary and in here is the
- 3:01:50temperature. So we can view that like
- 3:01:53this. So first of all we can have a look
- 3:01:54at all of the keys. So we can indeed see
- 3:01:56look there is a current. So you can see
- 3:01:59it all the way. Let me move this around
- 3:02:00so you can see a current. That is the
- 3:02:03last key that is in here. So let's have
- 3:02:06a look at what that looks like if we now
- 3:02:08take the dictionary and remember
- 3:02:10indexing for a dictionary is using the
- 3:02:12square brackets and then we plug in the
- 3:02:14key. So now if I let's clear this up for
- 3:02:17you to show it. Now you can say look
- 3:02:19from this data it's it's it's a
- 3:02:22dictionary. There's a lot of information
- 3:02:23in there but now I just want the current
- 3:02:25and the current key has the following
- 3:02:27information here. So we have the time,
- 3:02:29we have the interval and we have the
- 3:02:30temperature. So then what we can do is
- 3:02:33we can continue to do that because this
- 3:02:37if I look at this, this is still a
- 3:02:39dictionary. You can have dictionaries
- 3:02:41inside dictionaries. So now we can just
- 3:02:43continue the pattern and we can simply
- 3:02:46do another lookup with another key. And
- 3:02:49now you can see that we have the actual
- 3:02:52temperature. So this is now something
- 3:02:53that we could actually store. So we can
- 3:02:55store the temperature and now we have
- 3:02:57captured this in such a way where we can
- 3:02:59program programmatically use the
- 3:03:01temperature and I know that we're moving
- 3:03:03quick here. We're make we're making big
- 3:03:05steps because right now instead of like
- 3:03:07just focusing on new concepts we're also
- 3:03:10bringing in previous concepts that we
- 3:03:12already covered, right? And now it's
- 3:03:13like oh wait wait wait yes dictionaries
- 3:03:15and then oh what was the syntax again?
- 3:03:17How do we do that? Uh but that's the
- 3:03:19learning process. We make it more and
- 3:03:21more complex over time. So here you can
- 3:03:23see one more time in the docs uh and at
- 3:03:25any time if you feel like oh this is a
- 3:03:26little bit too much go back to the docs
- 3:03:28there's more info there you can see the
- 3:03:29nested structure that's uh that's in
- 3:03:32there. Okay so now we can also go one
- 3:03:35step further and actually start to
- 3:03:37create a function around this to capture
- 3:03:40just what we need. So let's have a look
- 3:03:42at what's going on over here. So if we
- 3:03:44structure it like this, we can now
- 3:03:46actually start to build a program where
- 3:03:48we say look we import the request
- 3:03:50library. We have a function which is
- 3:03:53called get weather and we do def get
- 3:03:55weather and then we plug in the
- 3:03:57parameters. So we have latitude
- 3:03:58longitude and then we say look the
- 3:04:00response is and then we do exactly the
- 3:04:03same that we already did, right? So this
- 3:04:04is what we did in the previous step. We
- 3:04:06get the data and then we return the data
- 3:04:09current and then we take the
- 3:04:10temperature. So you see what we're doing
- 3:04:11over here. This is where like now this
- 3:04:13is where we start to actually like
- 3:04:15become a programmer. This is
- 3:04:17programming. We figure out some logic.
- 3:04:19We know how to solve it and then we we
- 3:04:21put it into a function and then we we
- 3:04:24return that. And now we can say look we
- 3:04:26can get the weather or the temperature
- 3:04:27in Paris right now which is 13.2.
- 3:04:31We can get the temperature in London
- 3:04:3311.8. And we can get the temperature in
- 3:04:35Tokyo which is 19.1. And now we can
- 3:04:39print all of those. This is cool, right?
- 3:04:41So here you can see the beauty of using
- 3:04:44functions and why why they are so useful
- 3:04:47and how everything comes together and
- 3:04:49especially if you can if you combine it
- 3:04:51with external uh services and APIs that
- 3:04:54other people make available and we
- 3:04:55import the request library. Now all of a
- 3:04:58sudden we have we can literally build a
- 3:05:00weather alarm. So you could build a
- 3:05:02program around this for your like
- 3:05:03hometown or city. Whenever a temperature
- 3:05:06is like either below or above a certain
- 3:05:08threshold you can trigger something. So
- 3:05:10summary of what we've learned. You send
- 3:05:12the request to the API URL with
- 3:05:14parameters like the cor the coordinates
- 3:05:16that we did. The API processes your
- 3:05:18requests and find the data sends it back
- 3:05:20to you. You receive that data in a JSON
- 3:05:23format which we then load into Python in
- 3:05:25a dictionary and then you extract the
- 3:05:27specific parts you need. So the pattern
- 3:05:29here is always the same when you are
- 3:05:31working with external APIs. You connect,
- 3:05:33send requests, get data back and then
- 3:05:35you use the information from it in
- 3:05:37whatever shape or form you need it. And
- 3:05:39APIs are really how modern software
- 3:05:41systems comm communicate with each
- 3:05:43other. So when you're building an AI
- 3:05:45system, for example, that needs to
- 3:05:46integrate with a ticketing system, you
- 3:05:48look up that ticketing systems uh API
- 3:05:51documentation, you need to probably get
- 3:05:52an API key and then you can write Python
- 3:05:55functions around that to capture
- 3:05:56customer information or order
- 3:05:58information or all of the apps that you
- 3:06:01use on your laptop like right now.
- 3:06:03Probably like 90% of them have a public
- 3:06:05API that you can use. So, for example,
- 3:06:07Slack or your favorite to-do app, they
- 3:06:09all have APIs where you can extract the
- 3:06:12key, understand the uh URL that you need
- 3:06:14to connect with and the parameters that
- 3:06:16you need to plug in there and then you
- 3:06:17can send and receive information from it
- 3:06:19into it. All right, so now next we are
- 3:06:22going to we're going to the section
- 3:06:23working with data and this is going to
- 3:06:26be really cool. And here we're going to
- 3:06:29ramp things up a little bit. In this
- 3:06:31specific section, what I want you uh to
- 3:06:34do is I just want you to follow along
- 3:06:36and we're going to copy paste the code
- 3:06:39snippets. You don't have to like type
- 3:06:41all of this out because it's way too
- 3:06:42much. And my goal with this section is
- 3:06:45to show you what's possible with Python
- 3:06:48because I always like I remember when I
- 3:06:51was learning Python, the my favorite way
- 3:06:53to learn was through reverse
- 3:06:55engineering. So I would find the script
- 3:06:57online and now with GPT it's even
- 3:06:59easier. You literally tell it like,
- 3:07:01"Hey, look to this." And then you see
- 3:07:03the capabilities and you're like, "Whoa,
- 3:07:05this is cool." And then you start to
- 3:07:07connect the dots where you're like,
- 3:07:08"Hey, if I can do this, I can probably
- 3:07:11also do this. What would that look
- 3:07:13like?" And then you start to look at the
- 3:07:14code and then you start to play with the
- 3:07:16the parameters and with the variables.
- 3:07:18And then that's how you get a feel for
- 3:07:21what you can do with this language. So
- 3:07:23what we're going to do right now is
- 3:07:25we're going to build on the API that we
- 3:07:27just saw. We're going to load u a lot of
- 3:07:29data and we're going to manipulate that
- 3:07:32and we're going to visualize that. So in
- 3:07:34order to follow along with this section,
- 3:07:35you need uh the request library, the
- 3:07:37pundas library and the mud plot lib
- 3:07:39library. I already showed that in a
- 3:07:42previous section where I showed you how
- 3:07:43you can install multiple libraries. If
- 3:07:45you did not run the command at that
- 3:07:47point, you should do it now because we
- 3:07:49need all of these libraries. Uh request
- 3:07:51is to work with APIs, pundas is to work
- 3:07:53with data and then the metplot library
- 3:07:55is to create visualizations. So we can
- 3:07:57create plots. First we're going to what
- 3:07:59we're going to do and I what I recommend
- 3:08:00is I recommend creating a new file for
- 3:08:02this. So let's come in here. Let's clean
- 3:08:04it up. And then I do uh command B. I do
- 3:08:07new file. Let's call it do get data.py.
- 3:08:11So new file. Make sure to give it a.py
- 3:08:14extension. And then right now I can
- 3:08:16close this one more time because this is
- 3:08:17going to be a big script. And I want you
- 3:08:19to I want you to save this as well so
- 3:08:22you can later reference it. So, first
- 3:08:24we're going to get 7 days of uh weather
- 3:08:27data. So, I'm going to copy paste this
- 3:08:29script. I'm going to plug it in here.
- 3:08:31And I just want you to briefly go
- 3:08:33through it with me to understand what's
- 3:08:35going on over here. So, first at the
- 3:08:37top, we start with the imports, right?
- 3:08:39The request and then we do the daytime
- 3:08:41library. Now you can see right now we
- 3:08:43also import uh time delta which is a a
- 3:08:46function in here that we can say look if
- 3:08:48we have the daytime today which we can
- 3:08:51get daytime now we can actually get a
- 3:08:54week ago by saying time delta days is 7
- 3:08:57and this programmatically understands
- 3:08:59that okay look right now is today's date
- 3:09:02we need to go 7 days back so let's let's
- 3:09:04walk through this and I'm going to zoom
- 3:09:06out a little bit so you can see
- 3:09:08everything uh side by side let me see I
- 3:09:10can go one over here. So I can do uh
- 3:09:13daytime now which is going to give us
- 3:09:16the exact timing right now like to the
- 3:09:18millisecond and then we can do today and
- 3:09:21then time delta 7 is a week ago. So you
- 3:09:24can see a week ago is now uh visualized
- 3:09:27over here. So you can see we can get uh
- 3:09:30if you look at the date it goes all the
- 3:09:32way back exactly one week. Okay. Now
- 3:09:35we're going to format the dates for the
- 3:09:38API because the API that we're working
- 3:09:40with here the uh Paris AP or the get
- 3:09:43weather API for Paris it expects this uh
- 3:09:46format. So we need to uh specify the
- 3:09:49year the month and then the date. So
- 3:09:52what we can do is we can use this method
- 3:09:55over here used essentially to conver
- 3:09:58convert a day time into a specific
- 3:10:00format. And why I said like look just
- 3:10:02copy this right now because I understand
- 3:10:05this is a lot. We have time delta. We
- 3:10:07have this like strive time thingy. We
- 3:10:09have all these uh commands over here.
- 3:10:11For now we can just say look this gives
- 3:10:13us the start date in exactly the way we
- 3:10:16need it for the API and also the end
- 3:10:18date in exactly the way we need it. So
- 3:10:20now we have a date range. And now if you
- 3:10:23look in here we can plug this into the
- 3:10:26uh function where right now the latitude
- 3:10:28and the longitude are hardcoded. So this
- 3:10:30is always for Paris. We can change that
- 3:10:32right now. And the the dynamic variables
- 3:10:35in there are now the start date and the
- 3:10:37end date. So let's run this. This is now
- 3:10:40our URL. And now we can do the response.
- 3:10:43We can get the data. And then we can
- 3:10:46print it. And you can see right now,
- 3:10:48let's see if I actually do it like this.
- 3:10:51Now you can see that we have more data
- 3:10:54in here where you can see the that we
- 3:10:56have daily data for the past seven days.
- 3:10:59And you can see the maximum and the
- 3:11:00minimum for those those days. So now
- 3:11:03instead of just getting like the current
- 3:11:05temperature right now, we have more
- 3:11:07information. So that was step number
- 3:11:09one. So now let's continue. So now we're
- 3:11:12going to load it into pandas. So pandas
- 3:11:14is a library that you can use to
- 3:11:16manipulate data. You can really think of
- 3:11:18it as Excel but for uh for Python.
- 3:11:22Pretty much anything that you can do in
- 3:11:24Excel plus more you can also do with the
- 3:11:26pandas library. And it's it's a really
- 3:11:28great library. So I have a background as
- 3:11:30a data scientist like for the first like
- 3:11:323 years of my career like pandas is like
- 3:11:35pretty much all I did. Pandas mod lip
- 3:11:37and then machine learning libraries. But
- 3:11:39this pandas was always the starting
- 3:11:40point. So what we're going to do right
- 3:11:42now is we're actually going to uh turn
- 3:11:44this into a nice little script. So what
- 3:11:45I'm going to do right now is I'm going
- 3:11:47to paste this here. But now what I want
- 3:11:49you to do is instead of take doing the
- 3:11:51import here, I'm going to put that at
- 3:11:53the top. That's just a style thing like
- 3:11:55it works like to Python is totally fine
- 3:11:58with having the imports in here. But you
- 3:12:00should get used to having all the
- 3:12:01imports at the top. And now what what
- 3:12:04you can do over here is you can even
- 3:12:05like do let's say we do a hashtag and
- 3:12:08then we do kind of like a big line to
- 3:12:10say look first this was the stuff with
- 3:12:13the API. Now we're getting to the stuff
- 3:12:16that we're doing with pandas. So when we
- 3:12:19have the data that's still in memory. So
- 3:12:22remember if you close this out and now
- 3:12:25you come in here and you will try to do
- 3:12:27this it will say data is not defined. So
- 3:12:30make sure that whenever you're working
- 3:12:31with the interactive session you keep it
- 3:12:33open and you make sure you should think
- 3:12:36about what what does Python currently
- 3:12:37have in memory and if that's not the
- 3:12:39case you need to rerun it. So now we
- 3:12:41have the data once more and you can also
- 3:12:43see how quick this is right this is
- 3:12:44super nice if you close out of it now in
- 3:12:471 second we have the last week week's
- 3:12:50worth of data again. So now in here in
- 3:12:52the data object we now it changed a
- 3:12:55little bit. So before we had the current
- 3:12:57key right but now that is not in there
- 3:12:59because we didn't get the current data
- 3:13:01we get the we get a date range. So now
- 3:13:03we have the daily key. So we can get the
- 3:13:05daily data which is a dictionary in here
- 3:13:07which we see right now. So now we have
- 3:13:09that information in here and now we're
- 3:13:11going to turn that into a data frame.
- 3:13:14And this is pandanda's uh way of saying
- 3:13:16look if you have an excel spreadsheet
- 3:13:18right you have the columns and you have
- 3:13:20the rows you can create a nice little
- 3:13:22table in pandas that is called a data
- 3:13:24frame and again we have specific syntax
- 3:13:27for how to do that we use in this case
- 3:13:30pd because we imported pandas pd then we
- 3:13:33use the data frame and then we need to
- 3:13:35specify a specific structure in here for
- 3:13:37now don't worry about how this works you
- 3:13:40don't need to know that for now all you
- 3:13:41need to do is run this. And now what we
- 3:13:44can do if we now look into the data
- 3:13:47frame, you can see that we actually have
- 3:13:48a table in here that's very readable.
- 3:13:51And that's one of the things that I like
- 3:13:53about the panos library where if I look
- 3:13:55at this, this is messy. Even though it's
- 3:13:58the exact same information, right? And
- 3:13:59computers love this. Computers love JSON
- 3:14:02data and dictionaries because it's very
- 3:14:03fast. It's very memory efficient. But
- 3:14:06like I when I analyze data, this is this
- 3:14:08is what I want to see because this is
- 3:14:10very clear. I can exactly see just like
- 3:14:12in Excel. Okay, awesome. This is
- 3:14:14something that I can understand and that
- 3:14:16we can now do stuff with. Now, one more
- 3:14:18thing that we're going to do is we're
- 3:14:20going to turn the actual date and we're
- 3:14:23going to change the uh format because
- 3:14:26out of the box and when you're working
- 3:14:28with uh pandas, this is a very common
- 3:14:29operation. the date right now it will be
- 3:14:32a string because when you are uh sending
- 3:14:36information back and forth via an API
- 3:14:38using JSON JSON doesn't care about data
- 3:14:41types it's all string based so now we
- 3:14:44need to tell Python look this is
- 3:14:45actually a uh this is actually a date
- 3:14:48because that's going to unlock some of
- 3:14:49the features that we can use for
- 3:14:51plotting so it understands that uh there
- 3:14:53is an order of operations and we can
- 3:14:55change the scale so we run that and now
- 3:14:58we have a data frame Let's see over here
- 3:15:01it is exactly the same but now if we uh
- 3:15:04now under the hood the date uh Python
- 3:15:07understand that this is a date just
- 3:15:09follow along copy executed make sure
- 3:15:12that you have the data frame over here
- 3:15:14like this and then we get to the next
- 3:15:16step so you should see the output now
- 3:15:18we're going to visualize it and this is
- 3:15:20what we can do with the mattplot lip
- 3:15:21library so first let's see I'm going to
- 3:15:23copy all of this so you can see there's
- 3:15:25a lot of information uh going on over
- 3:15:27here over here let's do one more let's
- 3:15:29just do a Quick break here to see look
- 3:15:31now we're getting into Mattplot lip and
- 3:15:33remember we put the imports at the top.
- 3:15:37So now you can see yellow squiggly
- 3:15:38lines. Python says look I don't know
- 3:15:40what plt is. So we come over here we
- 3:15:43plug it in here. And this is just one of
- 3:15:45those things where mattplot lip and then
- 3:15:48you need pipplot. Importing it as plt is
- 3:15:51just something we do. It's just
- 3:15:52something we all agreed on. I could do
- 3:15:55anything here and it would work but plt
- 3:15:58is the way we do it. So make sure you
- 3:15:59import that as well. So now we import
- 3:16:01the met plot lip library and now Python
- 3:16:04understands look I can now use that PLT
- 3:16:08and this again is a library has a whole
- 3:16:10specific set of syntax and instructions
- 3:16:12where we where we can create figures. So
- 3:16:14we have a figure, we can plot it, we can
- 3:16:16do the X label, we can do the Y label,
- 3:16:18we can create a title, we can create a
- 3:16:19legend. There are almost infinite
- 3:16:22possibilities with this library as well.
- 3:16:24But let's let's show what we can do over
- 3:16:27here. There we go. Now we have created a
- 3:16:30figure. So now you can see on the x-axis
- 3:16:33over here you can see the dates of last
- 3:16:35week. We see the minimum temperature and
- 3:16:36the maximum temperature. And we have a
- 3:16:38title Paris weather past 7 days
- 3:16:41temperature here on uh on the y-axis.
- 3:16:44This is now already a report that you
- 3:16:47can create. And like I've said in the
- 3:16:49beginning of my career working as a data
- 3:16:51scientist and data analyst like this was
- 3:16:53core part of my work and not necessarily
- 3:16:56getting weather from weather data from
- 3:16:58Paris but using company information and
- 3:17:00more specifically IoT data from sensors
- 3:17:03to analyze trends and to create reports.
- 3:17:06And actually right now to this day like
- 3:17:08still one client that I'm working with
- 3:17:10I've I have a task in my inbox right now
- 3:17:12where I need to create a report like
- 3:17:14this and we have a whole Python uh
- 3:17:17codebase that gets the data from from
- 3:17:19the IoT sensors from the database and we
- 3:17:21have it set up in such such a way where
- 3:17:23the researchers get exactly the type of
- 3:17:25plots that they're looking for. So now
- 3:17:27we are quickly making moves and already
- 3:17:29actually getting close to skills that
- 3:17:32you can actually pli apply in the real
- 3:17:34world and that you can even get paid
- 3:17:36for. That's why I wanted to take a quick
- 3:17:38leap here without you worrying about
- 3:17:41okay look what's everything that's going
- 3:17:43on over here but just show you some of
- 3:17:45the possibilities and have a look over
- 3:17:47here you also have the save fic in here.
- 3:17:49Now if I open this up you can see it's
- 3:17:51even saved as a PNG. So that's already
- 3:17:54in here. So I can now create an email
- 3:17:55say hey look client here's the weather
- 3:17:58from in Paris from the past seven days
- 3:18:00and I can email that. Python can also do
- 3:18:02that. Now let's see there's one more
- 3:18:04thing. Now we're also going to save it
- 3:18:06to a CSV file. Create some separation.
- 3:18:10Now we're going to use the OS library.
- 3:18:12Put it at the top. Import it. Make sure
- 3:18:14to import it. Let's see. Let's close
- 3:18:16this. What we can do right now is we can
- 3:18:20use the OS library to say look we want
- 3:18:22to so we want to store we want to export
- 3:18:24our data as a CSV file so we can for
- 3:18:27example both send the image and also the
- 3:18:29data set and now with the OS library we
- 3:18:32say look if this path doesn't exist so
- 3:18:34data we make the directory so look at
- 3:18:36this in this folder there's no uh data
- 3:18:39folder if I run this we now have a data
- 3:18:42folder pretty cool right pretty cool and
- 3:18:45now we can save it and this is all
- 3:18:47possible because of pandas. It makes it
- 3:18:49super easy similar to how Excel you can
- 3:18:51just like export to CSV. We can take our
- 3:18:54data frame which is the one over here
- 3:18:56and we can say to CSV. So that's a
- 3:18:59method that's available on there and
- 3:19:01then we can provide a path data and then
- 3:19:03we say we call it Paris uh weather CSV
- 3:19:07and then we do that. And now you can see
- 3:19:09a confirmation over here because we have
- 3:19:10a print statement which says we have the
- 3:19:12data saved to Paris weather.csv. So now
- 3:19:15let's see let's close out of this. Let's
- 3:19:17actually have a look inside the data
- 3:19:19folder. Wow, look we have a weather.csv.
- 3:19:22We can even reveal that in the finder
- 3:19:24and you can actually see that now we
- 3:19:25have a file over here that we can share
- 3:19:28and that we can work with even in other
- 3:19:30tools. So this is pretty cool, right? So
- 3:19:33here you can see the complete example.
- 3:19:35And like I said, we're making big steps
- 3:19:38right here. We're going from isolated
- 3:19:40building blocks to literally bringing
- 3:19:41everything together. We connected to a
- 3:19:43real API. We worked with dates and
- 3:19:46times. We processed data with pandas. We
- 3:19:48created the visualizations. We handled
- 3:19:50files and folders. And we saved the
- 3:19:52results. These are literally the skills
- 3:19:54of like a junior data analyst. These are
- 3:19:56the skills that you need to understand.
- 3:19:58And now, as an exercise, here's what I
- 3:20:00want you to do. I want you to try and
- 3:20:02modify the code to get the weather for
- 3:20:04your city. So you can come in here and
- 3:20:06find uh where wherever you live and then
- 3:20:09update everything in here from like the
- 3:20:11latitude, longitude to also uh the
- 3:20:14titles over here so it doesn't say
- 3:20:16weather in Paris and then you can even
- 3:20:19uh change the file name over here. So go
- 3:20:22through the entire thing, play with it
- 3:20:23and see if you can create the weather
- 3:20:24chart and the export for the weather in
- 3:20:27your city. Okay, and now it's time to
- 3:20:29dive into the next section which is
- 3:20:30called practical python. So here, beyond
- 3:20:34just showing you isolated code snippets,
- 3:20:36I'm going to actually teach you what
- 3:20:38it's like to work with Python in the
- 3:20:41real world. So we're going to build real
- 3:20:43programs with a proper structure. And
- 3:20:46you got a sneak peek of that in the
- 3:20:48previous section already. But here, what
- 3:20:50we're going to do is we're we're going
- 3:20:51to set up a project. We're going to
- 3:20:53understand Python paths and how they
- 3:20:55work with each other. We're going to
- 3:20:56work with even more data, and we're
- 3:20:58going to organize our code. So, we're
- 3:21:00going to split our code into reusable
- 3:21:01functions and also across files. This is
- 3:21:05really, really important and a lot of
- 3:21:07beginner courses and tutorials skip that
- 3:21:09and it took me years to like fully
- 3:21:11figure this out and to really be
- 3:21:13confident with this. So, let's first get
- 3:21:16into the project structure. Super
- 3:21:19important talking about organizing your
- 3:21:21workspace. So, currently we are in this
- 3:21:24folder, right? We already created some
- 3:21:26some folders in here. We have the
- 3:21:27hello.py, PI we have the weather chart
- 3:21:29which I'm going to get rid of right now
- 3:21:31and we have the get data that we created
- 3:21:33but now let's actually start to create
- 3:21:36some structure in here and see how all
- 3:21:37of that works together. So what I want
- 3:21:39you to do is I want you to create a uh a
- 3:21:42new folder and we're going to call this
- 3:21:44sales analysis. So let's come in here
- 3:21:48and let's see we are going to create
- 3:21:50sorry not a new file we do a new folder
- 3:21:52and we do sales analysis. So this this
- 3:21:55can be another like project inside this.
- 3:21:57So sales analysis in here. Okay. And
- 3:22:00then what you want to do is inside the
- 3:22:03sales analysis create these subfolders.
- 3:22:05So you do data and you do output. So in
- 3:22:08here we do new folder. We have data and
- 3:22:10we do another folder. We do output.
- 3:22:13Okay. All right. So it should should
- 3:22:15look like this. Now what we're going to
- 3:22:18do is we're going to create a data file
- 3:22:20that we are going to work with. So you
- 3:22:22can simply copy paste this this uh over
- 3:22:25here and then inside the data folder
- 3:22:28we're going to over here we're going to
- 3:22:30do new file and I'm going to do sales
- 3:22:32and I'm going to specify the uh uh the
- 3:22:35file extension CSV. So this will signal
- 3:22:38look this is a CSV file and then I'm
- 3:22:40going to paste this in here and I am
- 3:22:42going to save it. Now you can see over
- 3:22:44here that do you want to install uh
- 3:22:46rainbow CSV? This is actually something
- 3:22:48that I recommend. So let's see over
- 3:22:50here. Yes, I trust this. I'm going to
- 3:22:52install rainbow CSV. If you if you don't
- 3:22:55get the popup, you can also just go to
- 3:22:57the extensions over here, right?
- 3:22:59Remember these are the building blocks
- 3:23:01and then you search for rainbow CSV and
- 3:23:05then you click on it and then you click
- 3:23:06install because look what this will now
- 3:23:08do is it will show us uh different
- 3:23:10coloring. So you can see the columns
- 3:23:12easily coming back. So now we have a CSV
- 3:23:15file in here and then let's see over
- 3:23:18here. Now let's understand paths and how
- 3:23:22they work. So when we are for example in
- 3:23:24the sales analysis folder. So let's say
- 3:23:26this is a project you're you're working
- 3:23:28on in here and you want to reference the
- 3:23:31sales the sales.csv the file that we
- 3:23:33just created. We actually need to refer
- 3:23:35to it to say look we need data. We need
- 3:23:38to go into data folder and then we want
- 3:23:39sales. CSV. So it's all like with
- 3:23:43respect to where things are live on your
- 3:23:45file system. So let's give an example of
- 3:23:48that to make that more clear. In the
- 3:23:49sales uh analysis folder, we're going to
- 3:23:51create a file analyzer.py and we're
- 3:23:54going to copy paste and we're going to
- 3:23:55plug this in. So this is a way for us to
- 3:23:58get a feel for it. So in sales analysis,
- 3:24:00we do analyzer.py
- 3:24:03and we plug this in. So now when we are
- 3:24:06in this file, when we for example want
- 3:24:08to access the data or the outputs, we
- 3:24:10need to work with specific parts. So
- 3:24:12let's give an example of what that looks
- 3:24:13like. Let's say we import OS which is
- 3:24:15the library we can use to get
- 3:24:17information about our operating system
- 3:24:19and we then print the current working
- 3:24:22directory which is the OS to get current
- 3:24:24working directory and we print that we
- 3:24:26can see all the way over here that we
- 3:24:28are currently in the sales analysis
- 3:24:30folder and now we can check let me
- 3:24:32actually zoom out a little bit now we
- 3:24:34can check whether Python can access our
- 3:24:36uh sales.csv CSV file. So we do an if
- 3:24:38statement and we say look if the OS path
- 3:24:41the path over here exists we print we
- 3:24:44found the data. Else we say we did not
- 3:24:46find the data. So let's run this and we
- 3:24:48can see look it found the data and that
- 3:24:50is because from analyzer.py if we want
- 3:24:53to get to here we need to say first go
- 3:24:55into data then access sales.csv. If I
- 3:24:59get rid of this so for example of the
- 3:25:00data just just give me sales.csv CSV and
- 3:25:03I run this, you'll find that we'll run
- 3:25:06into an error. Cannot find it because
- 3:25:08this file is looking then into the sales
- 3:25:10analysis folder for a file called
- 3:25:12sales.csv and that doesn't exist. So
- 3:25:15that is how you can start to organize
- 3:25:17your projects and create structure. And
- 3:25:19a best practice here is keep data
- 3:25:21separate. So don't mix code and data
- 3:25:23files. Create separate folders like data
- 3:25:25and outputs. Use clear names. Data for
- 3:25:28input files, outputs for results,
- 3:25:30figures for images. Use simple
- 3:25:32structures. Keep your main script at
- 3:25:34like the top level and go deeper. Also,
- 3:25:36don't go to really like other folders
- 3:25:38somewhere else on your computer. Keep it
- 3:25:41focused and isolated. And then always uh
- 3:25:43keep on testing as you go. Right? So,
- 3:25:45both using the interactive session which
- 3:25:47is great for running line by line, but
- 3:25:50then also make sure that when you run
- 3:25:52the entire file all at once, you can
- 3:25:54also access it. And this is one of the
- 3:25:56things where in the beginning uh
- 3:25:58remember I reconfigured when we were
- 3:26:00installing uh Visual Studio Code we
- 3:26:02configured the Python execution. So if
- 3:26:04you run into any errors here you need to
- 3:26:07come back to the settings. So one more
- 3:26:09time for Visual Studio Code settings.
- 3:26:12This is the one where you need to do
- 3:26:13that otherwise it will look from the
- 3:26:15project root and your uh folders and
- 3:26:18your paths will become much more complex
- 3:26:20and is a lot harder to keep track of
- 3:26:22everything. So this is what I recommend.
- 3:26:24keep on testing. So both of the methods
- 3:26:26work seamlessly. All right. So that was
- 3:26:28an introduction to how you can structure
- 3:26:30the projects and how you can work with
- 3:26:32Python pass. In the handbook over here
- 3:26:34in Python pass there is a whole section
- 3:26:36with a lot more instructions and working
- 3:26:39with Python pass can be a little bit
- 3:26:40tricky but it's also too much for now to
- 3:26:42really dive into. The only thing that
- 3:26:44you should really need to understand
- 3:26:46here like the mental model whenever you
- 3:26:48want to for example access data you want
- 3:26:50to write to or read files is you should
- 3:26:52really think about look where am I what
- 3:26:54folder is my python script in so for
- 3:26:56example here in the analyzer.py I am in
- 3:26:59here then if I want to access the data
- 3:27:02what you can then do is you could simply
- 3:27:04follow the structure by saying you go in
- 3:27:06the folder and then you do a you do a
- 3:27:08forward slash and then you access the
- 3:27:10file if you want to go one level up. So
- 3:27:13you are for example in the sales
- 3:27:15analysis and you want to access the
- 3:27:17Paris weather. What you then do? So let
- 3:27:19me actually show you that. So then what
- 3:27:21you use is you use two dots. So this
- 3:27:24means and then a slash. This means we go
- 3:27:27one level up. So let me zoom in a little
- 3:27:30bit. So we are in analyzer.py which is
- 3:27:32in the sales analysis folder. Let's say
- 3:27:34I want to go to this data folder. Now I
- 3:27:36go one level up. I go into data and now
- 3:27:39the sales CSV is not there but the Paris
- 3:27:42weather CSV is there. So now if I check
- 3:27:45this, this should also work. Look, now
- 3:27:48we can access data that's outside of the
- 3:27:51folder. So if we go in, we simply use
- 3:27:54the folder names or the file names and
- 3:27:57we use forward slashes. If we want to go
- 3:27:59up, uh, we do it with the two dots. And
- 3:28:01this this can stack. You can change
- 3:28:03this. So you can also like if you have a
- 3:28:05really big project, you can also
- 3:28:06literally go three folder levels up. Uh
- 3:28:10it works exactly the same way. So this
- 3:28:12is just also one of those things where
- 3:28:14you just need to get started. You need
- 3:28:15to just start working on stuff and then
- 3:28:17you run into issues where you're in a
- 3:28:19file like I cannot access this. I'm
- 3:28:22getting errors. Python is throwing me
- 3:28:23errors. Then this Python pause section
- 3:28:25will give you like simple rules to
- 3:28:27follow, how you can check, how you can
- 3:28:29debug, how you can find your files and
- 3:28:31give you a few like differences as to
- 3:28:33how you should go about it. So make sure
- 3:28:35to bookmark this uh handbook and also
- 3:28:37use chatgpt. Then we get into working
- 3:28:40with files. So yeah, I want to spend
- 3:28:42some time here because this is also
- 3:28:44super important for when you are uh
- 3:28:46going to work on AI projects because AI
- 3:28:49is always about processing some incoming
- 3:28:52data and we want to do something with
- 3:28:53that to usually automate something and
- 3:28:56there data comes in a lot of shape way
- 3:28:58shapes and and forms. So we can have for
- 3:29:00example CSV files, JSON files, XML
- 3:29:02files, te text files or even paret files
- 3:29:05which are efficient ways for for storing
- 3:29:07lots of information. And the good news
- 3:29:10is Python has like excellent libraries
- 3:29:12for all of these. Um, that was so nice
- 3:29:14also when I started out as a data
- 3:29:16scientist. Whatever like kind of like
- 3:29:18data set people would throw at me
- 3:29:20whether it was Excel, CSV, a parket or
- 3:29:23like a SQL database like within a couple
- 3:29:26of minutes you could tinker with a
- 3:29:27library and you could make a connection.
- 3:29:30So now let's start to play a little bit
- 3:29:32with our sales data. So again make sure
- 3:29:34you have pondas installed. You should
- 3:29:35already have this uh already. Now we are
- 3:29:38going to adjust our analyzer.py and
- 3:29:40we're going to copy and paste this chunk
- 3:29:43in there again just to get a feel for
- 3:29:46what we can do with this not to fully
- 3:29:47understand everything line by line. So
- 3:29:50if we come in here and let's see I'm
- 3:29:52going to close this out. We can first of
- 3:29:54all read the CSV file. So this is the
- 3:29:57CSV file that we could just that we just
- 3:29:59created right. So we now have it in a
- 3:30:01pandas data frame over here. Now we can
- 3:30:04also look at the shape which is like how
- 3:30:06many rows and columns do we have? So we
- 3:30:08can print that. Those are common
- 3:30:09operations and we can also add more
- 3:30:12columns to it. So we can calculate the
- 3:30:14total. So let's have a look at this. So
- 3:30:16you can see we have quantity and price.
- 3:30:18And now if we run this. So we do we take
- 3:30:20the data frame and we take the quantity
- 3:30:24column over here which we can do through
- 3:30:26indexing similar how we would do with a
- 3:30:28dictionary. That's how pandas works. We
- 3:30:31take the quantity and we take the price
- 3:30:33and we multiply that and we store that
- 3:30:35into a new column. Now when we look at
- 3:30:38the data set or the data frame, you can
- 3:30:40see that we have a total value in here
- 3:30:43that we can also uh check. So this is
- 3:30:45how we can now start to use pandas as
- 3:30:48pretty much as Excel. We can now also
- 3:30:50create an output directory if it's not
- 3:30:52already there yet. So we already created
- 3:30:54that, right? So let me actually get rid
- 3:30:56of this. move to trash and then we
- 3:30:59create the directory. So now we have
- 3:31:01that one more time and now we can save
- 3:31:03it in multiple ways. So you can see
- 3:31:05before I show you how you can export it
- 3:31:07to a CSV file, right? Well, we can also
- 3:31:09output it to JSON. There we go. We now
- 3:31:11have a JSON file. Very convenient. We
- 3:31:13can output it to Excel. So now you will
- 3:31:16get an error where it says look we need
- 3:31:19let's see we need open py excel. So let
- 3:31:22me actually show you that full error.
- 3:31:24This is now this is also very common
- 3:31:26when you're working with Python and it
- 3:31:27says something like module not found and
- 3:31:29in this case we need open pi excel in
- 3:31:31the background as well. So what we can
- 3:31:33do is we can open up our terminal again
- 3:31:35and you know how to do this right now.
- 3:31:36Whenever you need something in python
- 3:31:38you just do pip install open pi excel
- 3:31:40and now it will get that into our
- 3:31:43virtual environment. We can close out of
- 3:31:45this and now let me clear this up. I
- 3:31:48think we should already be good to go.
- 3:31:50So now do to excel. I don't think even
- 3:31:52we have to run uh all of the other parts
- 3:31:54again. Look, now we have an Excel file.
- 3:31:56Like literally like this is an Excel
- 3:31:57file that we can just like open in
- 3:32:00Microsoft Excel. So you can see there we
- 3:32:03go. We created an Excel file. Now let's
- 3:32:05see. We can also do a CSV file. And now
- 3:32:08you have the totals in here. And you can
- 3:32:11see all of the output parts created over
- 3:32:14here. And it prints it. So this is now
- 3:32:16also a little automator script that we
- 3:32:18can have. So let's see if I delete this
- 3:32:20file over here and completely get rid of
- 3:32:22the output. Instead of going through it
- 3:32:26uh line by line with the interactive
- 3:32:28session, I can also just hit the play
- 3:32:30button or on my keyboard do uh command
- 3:32:33enter and now it will run in the
- 3:32:35terminal. You can see boom all
- 3:32:37everything it created the folder, it
- 3:32:38created the JSON file, excel file and
- 3:32:40the CSV file. Now this is going to set
- 3:32:42the stage for pretty powerful
- 3:32:44automations, right? You can also already
- 3:32:46start to think about some data analysis,
- 3:32:48some data that you get via an API and
- 3:32:50just every time that you want to run
- 3:32:51this just like run this script or later
- 3:32:53you can also schedule this so it becomes
- 3:32:55fully automated and now you have all of
- 3:32:56these files here. So let's say you want
- 3:32:58to send like weekly sales reports to uh
- 3:33:00to your sales manager or something like
- 3:33:02that. You can create a simple script do
- 3:33:04the calculations and send it to it send
- 3:33:06it to him in an Excel file because
- 3:33:08that's what he understands is he's not a
- 3:33:10programmer. all ways that you can work
- 3:33:12with the Python programming language and
- 3:33:14similar to exporting the files with
- 3:33:16pandas we can also like read in these
- 3:33:18files again so within pandas if you want
- 3:33:20to read in a specific CSV file so let's
- 3:33:22say you have a data folder and in there
- 3:33:24is a file called file CSV you can do
- 3:33:26read CSV or we can read a JSON or we can
- 3:33:30read excel and all of these functions
- 3:33:32also come with their own set of
- 3:33:34parameters where you can tweak it you
- 3:33:36can there are literally like 15 to 20
- 3:33:38types of arguments that you can plug
- 3:33:40plug in there to skip rows to convert
- 3:33:42certain data formats to have specific en
- 3:33:46encoding files all possible really the
- 3:33:48sky is the limit there. So just so you
- 3:33:50know you can export you can take data
- 3:33:52you can read all kinds of formats you
- 3:33:54can manipulate it and then you can also
- 3:33:56export it again in all types of formats
- 3:33:59to do whatever really you want. If you
- 3:34:01want to learn more about this like
- 3:34:03pandas uh just a documentation great
- 3:34:05resource the JSON module reading files
- 3:34:08and also I keep saying it chat GPT plug
- 3:34:10it in. What can I do with pandas? Give
- 3:34:12me an example. I want to read XML data.
- 3:34:15How do I do this in Python? I want to
- 3:34:18work with an Excel spreadsheet in
- 3:34:19Python. How do I do this? All possible.
- 3:34:22Okay, let's get to the last component of
- 3:34:25the practical Python session is
- 3:34:27organizing code. This is a big one. It
- 3:34:29took me it took me way too long to like
- 3:34:32to properly figure out how to do this
- 3:34:34because it's not that hard but no one
- 3:34:36like just showed me how to do this uh
- 3:34:38professionally really because when you
- 3:34:41are starting out as a beginner when you
- 3:34:43are working with Python files it's
- 3:34:45almost always that you have an idea I
- 3:34:47want to do something and you start in
- 3:34:49one single file right so here we have
- 3:34:51the analyzer.py Pi this is we work on
- 3:34:53something and oh here this is something
- 3:34:54completely else we we work with data but
- 3:34:57in the real world in real projects you
- 3:34:59want to make your code modular. So you
- 3:35:02want to have tiny files ideally that
- 3:35:04have some specific logic and then
- 3:35:06whenever you want to use that logic you
- 3:35:08import it into another file. You can do
- 3:35:11that and I'm going to show you how you
- 3:35:12can do that right now. It's similar to
- 3:35:14the imports actually that we use for the
- 3:35:15packages. So what does that look like
- 3:35:18and what are the benefits? Well, your
- 3:35:19code becomes reusable. becomes way more
- 3:35:21readable because instead of having
- 3:35:23thousand lines in one big file which is
- 3:35:25called maincript.pby where everything is
- 3:35:29you can now have calculations I don't
- 3:35:31know user info export data visualize
- 3:35:34data you have all of these files within
- 3:35:37your project that now have a descriptive
- 3:35:39name that are short that you can easily
- 3:35:41read and understand. So let's create a
- 3:35:45uh let's start by creating a helper
- 3:35:46function in our sales analysis folder.
- 3:35:49We are going to create a helpers.py
- 3:35:51folder and we're going to plug in these
- 3:35:54functions. So let's actually do that.
- 3:35:55Come over here. So sales analysis new
- 3:35:58file. We do helpers.py
- 3:36:01and we plug this in. We can get rid of
- 3:36:03this. So now you can by now you should
- 3:36:06already be familiar with the concept of
- 3:36:08functions. And you should be able to
- 3:36:10read this and understand what it's
- 3:36:12doing, right? So calculated total it's a
- 3:36:15function. It takes the quantity and the
- 3:36:17price as input parameters and then it
- 3:36:20returns the quantity times the price. So
- 3:36:22it calculates the total. Here you can
- 3:36:24see we have a multi-line dock string
- 3:36:26that we have in here or it's it is in
- 3:36:28triple quotes but you could also do
- 3:36:30multiple lines in here to give a
- 3:36:32description of what this function does.
- 3:36:34And then we're going to format the
- 3:36:36currency. So, we're going to take any
- 3:36:38number which is the input parameter, the
- 3:36:41amount, and we're going to format it in
- 3:36:43a string where we say, look, we're going
- 3:36:44to put a dollar sign before it. It's an
- 3:36:46F string, so we can put in the amount.
- 3:36:49And then this is Python's way of saying
- 3:36:51we just want two decimals. Also syntax,
- 3:36:53something you just need to see. We can
- 3:36:55also change this to one, to five, or to
- 3:36:58two. So now we've created helper
- 3:37:01functions. So let's come back to what we
- 3:37:04can do with this. So now we can actually
- 3:37:06use these functions. So now if we come
- 3:37:08over to our analyzer.py and let's see
- 3:37:11we're going to I'm going to copy paste
- 3:37:13this. So we can just do do it line by
- 3:37:15line here together. Analyzer get rid of
- 3:37:18everything that's in here and we're
- 3:37:19going to make this a lot simpler and
- 3:37:20we're going to paste this in. Look what
- 3:37:22we're doing right now. So now we import
- 3:37:25pandas spd. This is we know that we can
- 3:37:28do this right because we installed
- 3:37:29pandas in our virtual environment. So
- 3:37:31now pandas so now python knows I can
- 3:37:34import this. But look, here's the cool
- 3:37:36thing. We have now created our own
- 3:37:39module called helpers. Remember modules
- 3:37:42is a single single file and from within
- 3:37:44there we can import functions. So we can
- 3:37:47say from helpers we import calculate
- 3:37:50total and format currency which are the
- 3:37:52exact names of the functions. So they
- 3:37:54need to be exact otherwise you get
- 3:37:56import errors. So now if I run this you
- 3:38:00see we don't have any uh import errors
- 3:38:03right now. We can import import these
- 3:38:05functions and it it needs to be exact.
- 3:38:08And now we can go ahead and we can read
- 3:38:10the CSV data. And now we can calculate
- 3:38:12the total for each row by creating a for
- 3:38:16loop over the data frame. Again, don't
- 3:38:18worry about the syntax what we're doing
- 3:38:19over here. But we're going to create the
- 3:38:21totals. And now the totals you can see
- 3:38:24is a list of numbers in here. And that's
- 3:38:27now very easy because we have our
- 3:38:28helpers functions. And what this
- 3:38:30essentially does is say look we have go
- 3:38:32over all the rows in a data frame and
- 3:38:34then take the quantity take the price
- 3:38:36and and put those into the calculate
- 3:38:38total function. So that's how we can
- 3:38:41work back and forth between different
- 3:38:43files. And in a similar format uh we can
- 3:38:46also format the currency in here. So if
- 3:38:48we then do everything now all of a
- 3:38:51sudden we have a sales report. You can
- 3:38:53see we have all all of the uh we have
- 3:38:56all of the totals for all of the
- 3:38:57categories. It's formatted using the
- 3:39:00dollar sign and it has two decimals over
- 3:39:02here. So now instead of having
- 3:39:04everything in one file, we make things
- 3:39:07modular. And now your helpers functions
- 3:39:10could you could have like plenty of
- 3:39:11functions in there and they could be
- 3:39:13helpful not only in the analyzer.py
- 3:39:15file, but maybe you have another script,
- 3:39:17another analysis where you need to do
- 3:39:19the same uh the same operations. All
- 3:39:21right, let's cover what we've learned in
- 3:39:23this practical Python section because
- 3:39:26we're making big steps right now. This
- 3:39:28is how you use Python in the real world.
- 3:39:29You now know how to organize and
- 3:39:31structure your project. Uh you know how
- 3:39:34Python finds files, right? How you can
- 3:39:36do that whether it's data files or
- 3:39:38whether it's Python files. You have
- 3:39:41created code that reads real data and
- 3:39:43saves real results. And you also created
- 3:39:46reusable functions in separate files.
- 3:39:48This is how real Python works. All
- 3:39:50right. And with that we have come to a
- 3:39:52section on error handling. Also
- 3:39:55something really important because as a
- 3:39:57programmer you are going to make errors
- 3:40:00and even if you don't make errors it can
- 3:40:02also just happen that your program your
- 3:40:04code might be totally fine but just
- 3:40:06because of the data that's flowing
- 3:40:08through things or data that's either not
- 3:40:10available or available within an API it
- 3:40:13your program will respond differently
- 3:40:15and then it will crash. So there are
- 3:40:17ways to go about this and to handle
- 3:40:19this. So when it comes to error
- 3:40:21handling, there are different types of
- 3:40:24errors that you make as a as a
- 3:40:26programmer and also errors that are
- 3:40:27beyond your control. So you as the
- 3:40:30programmer can for example have typos
- 3:40:32and syntax errors, right? Forgetting a
- 3:40:33comma or using a a dot instead of a
- 3:40:36comma or forgetting a cola colon. You
- 3:40:38can also have logic errors. So for
- 3:40:39example, dividing by zero uh that really
- 3:40:42only shows up when your code runs or
- 3:40:44using a variable before it's defined or
- 3:40:47using the making a mistake with local or
- 3:40:49global variables or calling methods that
- 3:40:51don't exist. That's all stuff that you
- 3:40:53as a programmer can do. But beyond that
- 3:40:56when for example you are interacting
- 3:40:58with a system and a user for example
- 3:41:00inputs ABC when it needs to be a number.
- 3:41:03So for example like what's your age and
- 3:41:05that's ABC it cannot do a comparison on
- 3:41:07that or a file gets deleted if you after
- 3:41:09your program starts or an API that
- 3:41:11you're using is suddenly offline or
- 3:41:13changed. So you should know you should
- 3:41:16be aware of these types of different
- 3:41:18errors. Now here are then some examples
- 3:41:20of what can happen in the real world. So
- 3:41:22a syntax error right? So for this I'm
- 3:41:24going to come back to my hello.py. Let's
- 3:41:27see hello.py to give some examples. So
- 3:41:30here you can see a syntax error. Look,
- 3:41:32we we have an if statement and we are
- 3:41:34missing the colon. So right now Python
- 3:41:38will say look we expected the colon in
- 3:41:41here. So we can put that in here. But
- 3:41:43now also it says look the x is not
- 3:41:45defined. So that's another error that we
- 3:41:47have in here. So now if we say x equals
- 3:41:492 now we're all good and we have fixed
- 3:41:51the program. In this case you also have
- 3:41:53runtime errors. So look at this. So for
- 3:41:55example this we don't see any error. So
- 3:41:59we have 10 and we divide it by zero.
- 3:42:00This is not something we can do uh also
- 3:42:03not in Python. So now when we run this,
- 3:42:05this is a runtime error because like you
- 3:42:07will not see it until you run it. That's
- 3:42:09why it's called runtime division by
- 3:42:10zero. So that's another error. You can
- 3:42:12also for example have a variable that
- 3:42:15doesn't exist or a type error. So let's
- 3:42:17look at this. So over here we have print
- 3:42:19score. Python is like dude I don't know
- 3:42:21what score is. I can help you with that.
- 3:42:24And then you can also for example have a
- 3:42:25type error. So when you take uh a string
- 3:42:28and in this case an integer and we try
- 3:42:31to uh subtract or add the two it says it
- 3:42:33can only connect concatenate strings
- 3:42:36with other strings. So, we've seen that
- 3:42:39it's totally fine to do 5 + 5 or in this
- 3:42:43case hello plus I don't know hi like
- 3:42:47this is all totally fine we can do that
- 3:42:49but when we mix data types then all of a
- 3:42:52sudden Python says ho I'm going to stop
- 3:42:55you there this is not how we do things
- 3:42:57so those are all different types of
- 3:42:59errors that you can get into and here is
- 3:43:03another like common list where you can
- 3:43:05go through I won't cover all of these
- 3:43:07right Now, but what I'm going to show
- 3:43:08you is the try and accept blocks in
- 3:43:12Python because this is a very common way
- 3:43:14to make your programs more robust. And
- 3:43:16with try and accept, we can we can say
- 3:43:19to Python, look, go and try this. And if
- 3:43:22it fails, don't worry about it. Just do
- 3:43:25this. Because if we don't use try and
- 3:43:28accept, our program will stop if it hits
- 3:43:30an error. The examples that I just gave
- 3:43:33you, if you, for example, let's do the
- 3:43:35uh the deficient over here. Let's say if
- 3:43:37we now do uh we do print hi there. If I
- 3:43:41run this, you won't see the print
- 3:43:43because it will never get there. And it
- 3:43:45doesn't matter if I do it in the
- 3:43:46interactive window or I do it in the
- 3:43:48terminal, it will just say look, we
- 3:43:50cannot continue here. So the rest of our
- 3:43:53program will also not be executed. So
- 3:43:55let's say you're building a data
- 3:43:57pipeline and you're getting information
- 3:43:59from let's say five systems. You're
- 3:44:01generating the reports. First you you
- 3:44:04look into system one. You perform the
- 3:44:05calculations. Once you create the
- 3:44:06report, they go to system two. That's
- 3:44:08your whole script. If now there's an
- 3:44:10issue with system one and the API there,
- 3:44:13system 3 4 5 6 and everything after that
- 3:44:15will also fail. That's where try and
- 3:44:17accept comes into play. And how it works
- 3:44:20is like this. We do try, then we do a
- 3:44:23colon, then we do an enter, and then we
- 3:44:25get to the new line, and we have the
- 3:44:27indent, similar to an if statement. And
- 3:44:30now you can still see there's a red
- 3:44:32squiggly line in here because it says a
- 3:44:34try statement must have at least one
- 3:44:36except or a finally clause. So um other
- 3:44:40than like an if statement that you can
- 3:44:41also use isolated with a try we need to
- 3:44:45have an except clause in here as well.
- 3:44:48And then we do it like this. So first we
- 3:44:50say look try to divide this by zero.
- 3:44:53This will fail but we will still print
- 3:44:56hide there. And we can also do it like
- 3:44:58this and it will work. So that's a basic
- 3:45:00try and accept structure and that will
- 3:45:02already get you a long way. Now you can
- 3:45:05also capture multiple errors. So
- 3:45:07depending on whether it's a file not
- 3:45:08found error, a value error, a serial
- 3:45:10division error, but in the beginning
- 3:45:12just focus on when you need to have some
- 3:45:15type of error handling, starting with a
- 3:45:16simple try and accept will really get
- 3:45:18you a long way. This is already more
- 3:45:20advanced. We can also add else clauses
- 3:45:22to it and even a finally clause which
- 3:45:24will always run. All right, and that
- 3:45:26brings us to the last section of the
- 3:45:29building program sections, and that is
- 3:45:31classes. And now, this is going to be
- 3:45:33the most advanced topic that we're going
- 3:45:35to cover in this Python course. And at
- 3:45:37this point, it will probably still be a
- 3:45:39little bit tricky. So, don't worry if at
- 3:45:42any point during my explanation of what
- 3:45:44classes are, how to use them, and even
- 3:45:45what inheritance is when you feel like,
- 3:45:48oh, this is going a little bit too fast,
- 3:45:49and I don't fully get it. That's also
- 3:45:51not the full goal right now. is just to
- 3:45:54get exposure to it so that you are
- 3:45:56familiar with the concept you've seen a
- 3:45:58couple of examples so that later down
- 3:45:59the line in your own learning journey
- 3:46:01whenever in another tutorial or another
- 3:46:04course that you're following when people
- 3:46:05mention classes you at least know oh
- 3:46:08yeah this was this thing that Dave was
- 3:46:09talking about that was a little bit
- 3:46:10tricky a little bit more advanced but I
- 3:46:11know conceptually what it is and I can
- 3:46:13also now use something like JBT to help
- 3:46:15me get a better understanding of what it
- 3:46:17is and fill in my knowledge gaps and
- 3:46:19what we're going to do right now is I'm
- 3:46:21going to introduce you to objectoriented
- 3:46:24programming which is really just a way
- 3:46:26to organize code by grouping related
- 3:46:28data and functions together. So one of
- 3:46:30the most important things to understand
- 3:46:32about classes is that everything that
- 3:46:34we've done up until this point you can
- 3:46:37totally do that without classes and you
- 3:46:40can solve almost any programming
- 3:46:42problems without classes but they are
- 3:46:44very useful but most specifically from
- 3:46:48an organization point of view. So you
- 3:46:50can actually create really clean code
- 3:46:53files by structuring classes in a good
- 3:46:57way and putting functions in there. And
- 3:46:58that is what I will show you in this
- 3:47:00section. But also just know that for
- 3:47:02example for the first like 3 to four
- 3:47:04years when I was working with the Python
- 3:47:06programming language, I didn't really
- 3:47:07use classes at all. So if you think
- 3:47:10about organizing your code like as a
- 3:47:12toolbox, if it's without objectoriented
- 3:47:16programming, tools are scattered
- 3:47:17everywhere. So, think of your project as
- 3:47:19like a big toolbox. And here you have a
- 3:47:21hammer, there you have a screwdriver,
- 3:47:23and there you have some some nails. It's
- 3:47:25all in there. You have all the tools.
- 3:47:27And tools really here are functions. And
- 3:47:29whenever you need something, you just
- 3:47:31look into the toolbox. You're like,
- 3:47:32"Okay, let's grab the hammer." And then
- 3:47:34you can start to work with the hammer,
- 3:47:36right? But when you are working uh with
- 3:47:39OOP, object-oriented programming, tools
- 3:47:42are organized in labeled compartments.
- 3:47:44So you have the toolbox, but within the
- 3:47:46toolbox you have specific sections. So
- 3:47:49you know that when you need the hammer
- 3:47:52that is over there. So you don't have to
- 3:47:54look, you don't have to grab in there.
- 3:47:55You can just grab the hammer. That's
- 3:47:57probably the best reference or mental
- 3:47:59model that I can give you about using
- 3:48:02classes. Can you still like grab the
- 3:48:04hammer and and jag in the nail without
- 3:48:06without the the organization? Yes. But
- 3:48:09it's easier if you need to grab it more
- 3:48:11often. Okay. So what is a gloss? First
- 3:48:13of all, a class is a blueprint for what
- 3:48:15we call creating objects in Python.
- 3:48:17Objects is just a place where we can
- 3:48:20store all kinds of information under and
- 3:48:22it defines attributes. So what kind of
- 3:48:24data we store in there and methods which
- 3:48:27are functions. So what the class can do.
- 3:48:30Now when you're learning classes right
- 3:48:32now, one of the most tricky things again
- 3:48:34is syntax and methodology. You have
- 3:48:38these things like attributes which is
- 3:48:40data, methods which are the functions.
- 3:48:41And then if I go over here, here you
- 3:48:43have the class definition. And similar
- 3:48:46to how I introduced you to functions,
- 3:48:48right, where we need function name,
- 3:48:50parenthesis, arguments, colon, classes
- 3:48:53also have a peculiar way of like a
- 3:48:56Python specific way of doing things. And
- 3:48:58it's just one of those things. Is it
- 3:49:00logic? I don't know. This is just how
- 3:49:02they came up with it. There are some
- 3:49:04things to it where it's like it's a
- 3:49:05little bit weird, but once you get used
- 3:49:07to it, that's just the way you do it. So
- 3:49:09you'll see things like these underscore
- 3:49:11inits. You'll see this notion of self.
- 3:49:13These are all things that I will explain
- 3:49:15to you and you just need to be aware of
- 3:49:17I need to remember this. This is the
- 3:49:19syntax. So why use classes? So classes
- 3:49:22can help you write more understandable
- 3:49:24programs specifically as they grow as
- 3:49:27they grow. So here's the typical
- 3:49:29progression as a Python developer. This
- 3:49:31is literally what I I went through and I
- 3:49:33want to I want to shortcut this for you.
- 3:49:35So we all start with single files. So
- 3:49:38that's what we've been working on,
- 3:49:39right? So I want to do something. I want
- 3:49:41to get some data. So okay, this is what
- 3:49:43I do. And then at the end I have my
- 3:49:45report and I export my CSV one file.
- 3:49:48That's where everyone starts because
- 3:49:49it's the easiest. And then you get into
- 3:49:51functions. This is where you are right
- 3:49:53now. So remember we created the helper
- 3:49:55functions, right? So now instead of
- 3:49:58doing these, so so actually this example
- 3:50:00was already Oh, sorry this what the
- 3:50:02helper function and the analyzer. So now
- 3:50:05instead of having everything in one
- 3:50:06file, you can see this is now already a
- 3:50:08little bit shorter because this contains
- 3:50:11the uh functions that we can import. So
- 3:50:14that's level number two. And we have
- 3:50:16level level number three. That is where
- 3:50:18you get organized with using multiple
- 3:50:20files. So what I just showed you and
- 3:50:23then in classes level four, that's where
- 3:50:25we'll get to right now where we're going
- 3:50:26to wrap certain functions even we're
- 3:50:30going to nest that inside classes one
- 3:50:32level deeper. Now, in the context of AI
- 3:50:35that you want to probably be working
- 3:50:37towards, you can build really clean
- 3:50:39interfaces, manage complex data
- 3:50:41pipelines, and create your reusable
- 3:50:43components and organize stateful
- 3:50:45operations all using classes. So, let's
- 3:50:48dive into building your first class.
- 3:50:51Let's actually come over here. We're
- 3:50:52going to hello.py. And now we're going
- 3:50:54to use our hello.py to create a class.
- 3:50:56So, to create a class, the syntax is
- 3:50:58first we type out clause. So, with the
- 3:51:00function, it's defaf. Now, it's clause.
- 3:51:03Let's say we want to create a class for
- 3:51:05a dog. So let's say we're creating a
- 3:51:07game and in the game we have a dog and a
- 3:51:09dog can do stuff and it has some
- 3:51:10attributes. So we do that and then we do
- 3:51:14a colon over here and then we get to the
- 3:51:16next line. This is the starting point
- 3:51:18and then we need to add an initializer.
- 3:51:21And this is just one of those things.
- 3:51:22It's a it's a Python function and in a
- 3:51:24class we call it a method but everything
- 3:51:26is exactly the same. This is just one of
- 3:51:27those things where whenever I explain it
- 3:51:29to new students, it's like look, you
- 3:51:31just need to see it a couple of times.
- 3:51:33This is just how we do things in Python.
- 3:51:34Does it look a little bit weird? Yes, it
- 3:51:36does. But just follow along with me. So,
- 3:51:38if I take just this snippet, let me show
- 3:51:41you what what this looks like. So, we go
- 3:51:43inside the class and then we have the
- 3:51:45function the init and then we always
- 3:51:47need to put the self in here and then we
- 3:51:49can plug in parameters there as well. So
- 3:51:52for example every dog when when we want
- 3:51:54to have a dog object it should have a
- 3:51:56name and it should have a breed and
- 3:51:58similar if I for example want to create
- 3:52:00a let's say a class we want to do with
- 3:52:02cat I can do I would do the same thing I
- 3:52:04would do dev I do underscore in it in it
- 3:52:07and then I would plug it in a self and
- 3:52:08let's say uh a cat has a name and in
- 3:52:11this case I want to do a caller and then
- 3:52:14we set those attributes on the class
- 3:52:17itself by setting that equal to what we
- 3:52:20want to plug in there. So, self.name and
- 3:52:22self doc color is color. And then here
- 3:52:26you can see there's an error because I
- 3:52:27forgot the colon. Okay. So, this is how
- 3:52:30you create classes fundamentally. But
- 3:52:32now let's understand what what they're
- 3:52:34doing because now you might be like,
- 3:52:35yeah, okay, but what is this and what
- 3:52:37can we do with it? So, now we have a dog
- 3:52:40and a cat. And similar to how when we're
- 3:52:43working with functions, we first create
- 3:52:45the function and then we use the
- 3:52:47function. With classes, you need to
- 3:52:49initialize them. So remember classes are
- 3:52:51objects and objects need to be created
- 3:52:55and this is a blueprint for creating a
- 3:52:58dog and within our program within our
- 3:53:00application let's say this is a game we
- 3:53:02can have multiple dogs. So we can for
- 3:53:04example get I don't know Jerry and Jerry
- 3:53:08is a dog and then in there we give him a
- 3:53:11name and the name is Jerry and the breed
- 3:53:15is let's say Jerry is a Labrador and now
- 3:53:19we have Jerry over here which is the
- 3:53:21claw's dog and what we can now do and
- 3:53:23now we can for example take Jerry and we
- 3:53:25can say what's Jerry's name and you'll
- 3:53:28find that it's Jerry and what's the
- 3:53:29breed it's a Labrador so you can see
- 3:53:33that Now by creating a class creating
- 3:53:35that blueprint we have now created an
- 3:53:36object and that object is an instance of
- 3:53:39the class dog and right now that class
- 3:53:42has attributes. It has a name and it has
- 3:53:45a breed and similar to how we need to be
- 3:53:49specific about what we put in there with
- 3:53:50functions. If I now for example try to
- 3:53:52create another dog. So let's say we have
- 3:53:54a dog and we call that dog Tim and we
- 3:53:58don't specify the breed. we'll get an
- 3:54:00error because it says look it's missing
- 3:54:02the breed. So this now all everything
- 3:54:05that we learned from functions is still
- 3:54:07does still apply here. So we can also
- 3:54:09for example put a default value in here
- 3:54:12of none of unknown for example and now
- 3:54:15when I create a dog now we can create a
- 3:54:17we can create a dog with just the name
- 3:54:19Tim. So that's how all of these things
- 3:54:21that we've learned so far stack on top
- 3:54:23of each other. So let's go a little bit
- 3:54:25deeper to understand more about uh what
- 3:54:28we can do with classes. So here you can
- 3:54:29see I walked through this example. We
- 3:54:31have the initializer. We can then create
- 3:54:34doc objects using positional arguments
- 3:54:36or with named arguments to be specific.
- 3:54:38And then we can access the the
- 3:54:40attributes and then here like this is
- 3:54:43what it comes out. Yes in it looks weird
- 3:54:44with those double underscores. This is
- 3:54:46in Python this is actually called a
- 3:54:47dunder method. you have like you in the
- 3:54:50beginning you won't encounter it that
- 3:54:52much but there are other places in
- 3:54:53Python where you use this as well double
- 3:54:56underscores it's just how Python works
- 3:54:58you'll need to type it exactly like this
- 3:55:00don't worry after writing it a few times
- 3:55:02it becomes second nature like okay
- 3:55:04clause defaf in it and then we do the
- 3:55:06self in there it's just it's just Python
- 3:55:08special's way of saying look this is a
- 3:55:10setup method right so now let's
- 3:55:11understand the other weird thing in
- 3:55:13there the self thingy because what's
- 3:55:15that why do we need to have self like
- 3:55:17three times in here in order to just
- 3:55:19create a class. So self refers to the
- 3:55:22current object. It's how an object keeps
- 3:55:24track of its own data. So remember
- 3:55:26classes are blueprints and we can have
- 3:55:27multiple dogs. And because of this, this
- 3:55:30is just Python's way to say look when we
- 3:55:33are working with Tim in this case
- 3:55:36self.name is just stored like look this
- 3:55:38is on the instance itself. This is Tim.
- 3:55:40This is not the class level. That's why
- 3:55:43we need to plug self in there. That's
- 3:55:45how Python works under the hood. So you
- 3:55:48can see over here if we have the class
- 3:55:49dog and we just have the name in there
- 3:55:51self.name belongs to this specific dog.
- 3:55:54So you can create buddy it's dog one and
- 3:55:56you can also have dog two call it max
- 3:55:59and then you have the different names in
- 3:56:00here. So you can try this out for
- 3:56:02yourself. Come in here and then you can
- 3:56:04see we have m we have buddy and we have
- 3:56:06max. So that's kind of like a a mental
- 3:56:08model that you can use to remember why
- 3:56:11is why we have the self in here because
- 3:56:13we can have multiple instances. Okay,
- 3:56:16let's continue to a real world example
- 3:56:18because also I remember when I was
- 3:56:21learning classes and you go through
- 3:56:23examples like this. You're like it's
- 3:56:25very hard to like make the connection
- 3:56:26between okay nice that I can give my dog
- 3:56:30a name and a breed but like what like we
- 3:56:32want to build AI programs, right? What
- 3:56:34what does it have to do with dogs? So
- 3:56:36here we go. In the real world when you
- 3:56:38are working with classes, a very common
- 3:56:40use case is to for example build an
- 3:56:42entire class around an API config. So
- 3:56:44when you're for example working with
- 3:56:46open AAI you can say look I want to
- 3:56:48store everything that we have. So the
- 3:56:50API key I want to store the model the
- 3:56:52max tokens the base URL I want to store
- 3:56:55that in a class. So let's actually come
- 3:56:57over here and just get rid of everything
- 3:56:59and plug this in. So now we can see we
- 3:57:02have a clause and we call it API config.
- 3:57:04So now we're getting a little bit more
- 3:57:05serious. So this is not just a dog. And
- 3:57:07now we have that same defaf in it and a
- 3:57:10self key in here but now we say look we
- 3:57:12need an API key. We want to have a
- 3:57:14model. We want to have max tokens. And
- 3:57:16again, don't worry about what this all
- 3:57:17is. This is just a way of look. We can
- 3:57:19now store information in here. So if we
- 3:57:21now have this class config and we have
- 3:57:25that over here, we can now for example
- 3:57:27say look, we can now create a dev
- 3:57:29configuration where we now have this
- 3:57:33class over here. And then if we want to
- 3:57:35have a production configuration with
- 3:57:37another production key, another model
- 3:57:39and other settings, we now have that.
- 3:57:41And I can now access all of this
- 3:57:43information by looking over here at the
- 3:57:45dev config. So in the dev uh config, we
- 3:57:47have GPT3.5 turbo which really cheap,
- 3:57:50it's fast, we can use to test it. But in
- 3:57:52in the production version of our app, so
- 3:57:54in the real world, I want to use a
- 3:57:56beefier model. So I want to use that. So
- 3:57:59now you can start to imagine like coming
- 3:58:01back to the example of the toolbox.
- 3:58:03Right? Now I have a very clean container
- 3:58:06called dev config which is an instance
- 3:58:08of the class API config. And in there I
- 3:58:11have specific settings. And if I want to
- 3:58:13have something else, I just create a new
- 3:58:14instance of this, a new instance of that
- 3:58:17class. And now within my code, I can
- 3:58:19just do oh this is proconfig. Oh, this
- 3:58:21is that dev config. And I can access the
- 3:58:24attributes from from there. Remember
- 3:58:26attributes are the data the data that
- 3:58:29you store on there. So hopefully by now
- 3:58:31you already start to get a little bit of
- 3:58:33a better understanding to where classes
- 3:58:35can fit in. And also you don't need
- 3:58:37them. you could perfectly like write
- 3:58:40everything out in variables and in
- 3:58:41functions and you would still be able to
- 3:58:43get the uh production configuration and
- 3:58:45the dev configurations. This is just a
- 3:58:47cleaner way a cleaner interface of doing
- 3:58:50it using objectoriented programming. And
- 3:58:52one important thing to keep in mind here
- 3:58:54is the difference versus a class and the
- 3:58:56instance because this can get tricky
- 3:58:57when you're working with it. So the
- 3:58:58class is the the specification the
- 3:59:02blueprint itself and then the instances
- 3:59:04are for example the dev config and the
- 3:59:06pro proconfig that you have over here.
- 3:59:08So a common mistake is that you for
- 3:59:10example have this and let's say you want
- 3:59:13to uh you want to use this and you do
- 3:59:16API config and you want to have the
- 3:59:18model and you want to do it like this
- 3:59:20and it's like look there is no model in
- 3:59:22here. I was like, wait what? But I I
- 3:59:24plugged the model in here, right? So I
- 3:59:25have the API config and I have the
- 3:59:27model. But this is the class. This is
- 3:59:29the class blueprint and you need to
- 3:59:31create an instance of that. Let's see.
- 3:59:33Let's get back. So you first need to
- 3:59:36create the instance of that. So that is
- 3:59:37the dev config. So this is now the
- 3:59:40instance. And now the def config has the
- 3:59:42model. So that's how that works. And now
- 3:59:44working with classes in the beginning
- 3:59:46can be tricky. So common mistakes
- 3:59:48forgetting the init. So not having that
- 3:59:50in there. uh not using the self,
- 3:59:52forgetting parentheses, and modifying uh
- 3:59:55the clause instead of the instance.
- 3:59:57Those are all things that you may run
- 3:59:59into. So those that was the introduction
- 4:00:02to classes. So really starting with the
- 4:00:04blueprint and then the attributes in
- 4:00:06there. So that's what we covered.
- 4:00:07Attributes are there to store data. But
- 4:00:10now class you can also add methods to uh
- 4:00:14methods to to classes and methods are
- 4:00:16simply functions. Again this is
- 4:00:17methodology. In clauses, we call it
- 4:00:19methods instead of function. That's just
- 4:00:21the way we do it. And they always have
- 4:00:23the self as the first parameter. So this
- 4:00:25is also something that's in there. And
- 4:00:27you can pretty much do anything with
- 4:00:30these functions in the in these methods
- 4:00:32inside a class. But you can also do
- 4:00:34outside of a class. So let's have a look
- 4:00:36at an example over here where we have a
- 4:00:38data validator. So now this is going to
- 4:00:40get pretty pretty cool. Again, it's a
- 4:00:42lot of code because I want to show you
- 4:00:44like I want to teach you this by reverse
- 4:00:46engineering this because typing all of
- 4:00:48this out right now is is still a lot. So
- 4:00:50you can see we have a data validator
- 4:00:53class over here and we do a very simple
- 4:00:56init. It only inits itself with errors
- 4:00:59and there's a list. So in the beginning
- 4:01:01there's nothing in there. So let's see
- 4:01:03whenever I start this up I have my data
- 4:01:05class and I create the instance of the
- 4:01:08class. Now we have a data validator and
- 4:01:10I can check inside this validator what
- 4:01:13it has. It has the errors which is
- 4:01:15currently an empty list but now instead
- 4:01:18of the attributes that we have in in
- 4:01:20here we also have methods. So you can
- 4:01:24see with this data validator we can
- 4:01:26validate an email we can validate an age
- 4:01:28and we can get the errors. So here is
- 4:01:31specific logic to see look how do we
- 4:01:34validate an email? Well, if the ad
- 4:01:36symbol is not in an email, we can say
- 4:01:38look, there is an error and we append it
- 4:01:40to our list and we return true or false.
- 4:01:43And in a similar way, we can validate an
- 4:01:45age to say look age needs to be between
- 4:01:47needs to be lower than zero uh it needs
- 4:01:49to be between zero and 150 and we check
- 4:01:52that. So what we can now do is we can
- 4:01:56use our data validator and then we can
- 4:01:59call a method. So we use validator and
- 4:02:02then what we can do is we do validate
- 4:02:04email which is the method in here and
- 4:02:06that takes email as a parameter and we
- 4:02:08say look this is a bad email. So what we
- 4:02:11can now do you'll see that this is
- 4:02:13returning false because it got in here
- 4:02:16if it's not in email we say look this is
- 4:02:18false and we can also validate the h. So
- 4:02:21this is now also false or using
- 4:02:24positional arguments where we do so this
- 4:02:26is here we say specifically we do email
- 4:02:28is age is we can also do it similar to
- 4:02:31how we saw with functions right uh where
- 4:02:33we don't specify the email or the h but
- 4:02:35I often say look you don't want to do
- 4:02:37this and then in here we can print the
- 4:02:39errors so now every time we run this and
- 4:02:42we validate the data and an error
- 4:02:44happens it goes into the if statement
- 4:02:45and it uses the errors and it appends
- 4:02:47that to the list that is a lot of
- 4:02:49information going on over here I'm fully
- 4:02:51aware of that. But it just goes to show
- 4:02:54that we can use our data validator and
- 4:02:57we can run it and then we can perform
- 4:02:59certain actions. And every time I run
- 4:03:01this, okay, I can say this is another
- 4:03:03bad email, another bad email. And I run
- 4:03:05this a couple of times. And now when I
- 4:03:07print the errors, you can see that this
- 4:03:08list is now getting very long because
- 4:03:10it's storing all of that information.
- 4:03:12And now you can see that this data
- 4:03:15validator on its own becomes a really
- 4:03:17powerful this validator becomes a really
- 4:03:19powerful object because it can save
- 4:03:21information. We can send new information
- 4:03:23to it and we can build entire data
- 4:03:26pipelines by just spec specifying
- 4:03:28functions over here and then calling the
- 4:03:30methods later down the line. So that was
- 4:03:33showing a pretty extensive example. And
- 4:03:36first I want to show you like look here
- 4:03:37is what the end could look like and now
- 4:03:39let's do a little bit of a simple
- 4:03:41example where we say look let's get back
- 4:03:42to the dog and we do the defaf init and
- 4:03:45this is also good for you as an exercise
- 4:03:47to follow along. So we init we remember
- 4:03:50we had selfname let's just give it a
- 4:03:53name uh we say is the name and then we
- 4:03:55need to plug that in as a argument as
- 4:03:58well and then also don't forget the
- 4:04:01self. So you see also as I'm doing this,
- 4:04:03it's it's one of those things. I know
- 4:04:05the syntax. I know what a clause looks
- 4:04:07like. But like even as you go through
- 4:04:09this, you're like usually you forget
- 4:04:11about these things because you think
- 4:04:12about the about the logic, right? Oh, I
- 4:04:15want my dog to have a name. But luckily
- 4:04:17that's where our uh editor comes in and
- 4:04:19says like look remember you need the
- 4:04:20self in there. And now we can have a dog
- 4:04:23and let's say we have uh let's let's
- 4:04:26have Jerry again. So we have Jerry. So
- 4:04:28we create the instance of the dog name
- 4:04:31is Jerry. So there's Jerry. We now know
- 4:04:35that Jerry has a name and we can print
- 4:04:38that and it's correct Jerry. But now
- 4:04:41let's give Jerry um a method. So Jerry
- 4:04:45can also do something. So now what we
- 4:04:47can do is we can come in here and we say
- 4:04:48look we also want a method and we say
- 4:04:51bark and we just plug in self and then
- 4:04:54let's see we do like this and then we do
- 4:04:56print and then we do bark. So now if we
- 4:05:00do this and we initialize Jerry one more
- 4:05:02time Jerry still has a name but look
- 4:05:05Jerry can now do stuff. Jerry can bark.
- 4:05:07So now Jerry can bark. All right so that
- 4:05:09is how you can add behavior to classes.
- 4:05:12So remember attributes for storing data
- 4:05:15and then methods adding behaviors that
- 4:05:18you can add to this as well. Now then
- 4:05:20the next section over here is class
- 4:05:22inheritance. Now here I want to like
- 4:05:25briefly touched upon this because this
- 4:05:26is definitely a more advanced uh an
- 4:05:29advanced thing in Python. But whenever
- 4:05:31we have a class we can use the concept
- 4:05:35of inheritance to take a class and to
- 4:05:37add more functionality to it. So let's
- 4:05:40have a look over here. So let's say we
- 4:05:42start with a basic clause of an animal.
- 4:05:45So let's come in here. So we have a
- 4:05:46clause. We have an animal. An animal has
- 4:05:49a name and an animal can eat and sleep.
- 4:05:52That's the that's the default class in
- 4:05:54here. Now what we can do is we can
- 4:05:56create a child class to create a
- 4:05:59specific animal. So this is now the
- 4:06:01parent clause and now we create the
- 4:06:03child class. So let me actually copy the
- 4:06:05whole example over here. It will make
- 4:06:06more sense. So in the beginning you're
- 4:06:09probably wondering like why would I use
- 4:06:11this? But with this you can make your
- 4:06:12code even more modular. So let's say you
- 4:06:15have an animal and now here over here
- 4:06:17you have the clause and you specify the
- 4:06:20dog similar to how you normally would
- 4:06:22specify the dog class that we just saw
- 4:06:25but you put animal in here. And what
- 4:06:27this tells Python is it says look take
- 4:06:29the animal class take everything that is
- 4:06:31in here but also add these specific
- 4:06:34functions. So if we have this here in
- 4:06:37memory, we can create a dog buddy and
- 4:06:40now we have the dog and we can add
- 4:06:42create dog number two and that is Max.
- 4:06:44And now you can see without specifying
- 4:06:47this at the at the dog level uh buddy
- 4:06:50and both uh Max can also eat. So they
- 4:06:54are eating, they are sleeping, but they
- 4:06:56can also bark. So that's class
- 4:06:57inheritance and that is really when you
- 4:07:00get to the level where your codebase
- 4:07:01grows and you have more and more uh
- 4:07:04modular bits and pieces and you want to
- 4:07:06extend the capability in there and
- 4:07:08that's all that I want you to know for
- 4:07:09now. So just the concept of inheritance
- 4:07:11let you create a new class based on
- 4:07:13existing ones. You have basic examples
- 4:07:16you can add attributes in the child
- 4:07:18classes that we saw right we added the
- 4:07:20bark to the animal class. You can also
- 4:07:22override methods. So you have the base
- 4:07:25class which already might have a method
- 4:07:27like make sound but then for a cat you
- 4:07:30really want to change that you can
- 4:07:31override things. So to summarize this
- 4:07:33section when to use classes and this is
- 4:07:37all about the programming paradigms. So
- 4:07:40functional programming is all about
- 4:07:42using functions to transform data.
- 4:07:44Object-oriented programming is using
- 4:07:47classes to bundle data and behavior. So
- 4:07:49here's the recap for now. So both
- 4:07:51approaches achieve the same result.
- 4:07:53Classes don't unlock new features in
- 4:07:55Python. They're just a different way to
- 4:07:57organize your code. Choose based on what
- 4:07:59makes your code cleaner and also uh the
- 4:08:02level that you're confident with when
- 4:08:04you're writing and working with your
- 4:08:05Python files. As a general rule of
- 4:08:07thumb, you want to use classes when you
- 4:08:09want to keep track of a state between
- 4:08:11operations. So you want to save data, h
- 4:08:13group related data and functions
- 4:08:14together for organization, create
- 4:08:16multiple instances with similar behavior
- 4:08:18or model real world objects or concepts.
- 4:08:20And you can use functions when it's
- 4:08:22about simple transformations, input,
- 4:08:23output, stateless operations, so it
- 4:08:25doesn't need to remember anything.
- 4:08:27one-off calculations or small scripts.
- 4:08:29And I recommend just start with
- 4:08:31functions. They're simpler often and
- 4:08:33often sufficient. And only you add
- 4:08:35classes when you find yourself passing
- 4:08:37the same data between multiple functions
- 4:08:39when you need to maintain information
- 4:08:41and a state. All right, and that wraps
- 4:08:42up the section on building programs. So
- 4:08:45in this section, we really accelerated,
- 4:08:47right? We went from getting started the
- 4:08:49Python basics, the fundamental building
- 4:08:51blocks to now putting some scripts and
- 4:08:53programs together where you can actually
- 4:08:55see how everything starts to working
- 4:08:57together and we even got into more
- 4:08:59advanced concepts like using classes.
- 4:09:02Now the final chapter of this course is
- 4:09:04all about common tools that you'll work
- 4:09:07with on a day-to-day basis when you are
- 4:09:09working with the Python programming
- 4:09:11languages. So instead of like going
- 4:09:13deeper on Python specific syntax and
- 4:09:15showing you more examples there, I'm
- 4:09:17going to give you really like the full
- 4:09:18toolkit that you need to go out in the
- 4:09:21real world, build things, follow
- 4:09:23tutorials, and you'll literally be
- 4:09:24prepared for everything. So that also in
- 4:09:26the follow-up recommendation courses
- 4:09:28that I have for you on either like the
- 4:09:30data science track or building agents,
- 4:09:32like you can exactly follow along.
- 4:09:33That's really the goal. So let's dive
- 4:09:36into the tools. All right, so let's dive
- 4:09:38into the final chapter of this full
- 4:09:41Python beginner course. And here we are
- 4:09:43going to cover some tools that you need
- 4:09:46when you are working in the day-to-day
- 4:09:48with the Python programming language. So
- 4:09:50I can guarantee you when you go out in
- 4:09:52the world, you'll follow tutorials,
- 4:09:54you'll thank me for this because beyond
- 4:09:56the Python basics, building programs,
- 4:09:58everything that there is to the
- 4:10:00language, these are also really things
- 4:10:02you need to understand and they are the
- 4:10:04following. So we are going to cover git
- 4:10:07and github. Now these are also things
- 4:10:09like if you're already familiar with
- 4:10:11them feel free to skip for all of these
- 4:10:12but you definitely need to understand
- 4:10:14them. So if you're completely new to
- 4:10:15this make sure to watch everything and
- 4:10:18understand it. We're all I'm also going
- 4:10:20to show you how to work with environment
- 4:10:21variables. What they are how to use them
- 4:10:24and then I'm going to introduce you to a
- 4:10:26modern Python tool that can replace pip.
- 4:10:28You remember the thing that we used to
- 4:10:30install packages? and I'm going to
- 4:10:32introduce you to UVI which is really
- 4:10:34awesome and it will make our life as
- 4:10:37Python programmers a lot easier. So
- 4:10:40let's dive in and we are going to start
- 4:10:43with Git and GitHub an absolute
- 4:10:45must-have when you start your
- 4:10:48programming journey. So for the very
- 4:10:50basics if you have never heard of git
- 4:10:52what it is it's like a safe uh system
- 4:10:55for your code. It can track all the
- 4:10:57changes that you make and let you go
- 4:10:59back to previous versions. So that when
- 4:11:01you are for example working over here,
- 4:11:04you create a snapshot and then when the
- 4:11:06next day you continue and you all of a
- 4:11:08sudden realize that you made a mistake
- 4:11:10and you want to go back. That's all
- 4:11:12possible through Git. Because if we're
- 4:11:14here on our file system, we can just
- 4:11:17save the file, right? But that saves the
- 4:11:19snapshot right now and it's not really
- 4:11:21easy to go back or to work on different
- 4:11:24versions or even to work with a team. So
- 4:11:26that's a problem that git uh solves. It
- 4:11:29allows us to go pre to go back to
- 4:11:31previous versions and also collaborate
- 4:11:33with others. You can really think of it
- 4:11:35like Google Drive or Dropbox with
- 4:11:37version control. So why you need it?
- 4:11:40save your progress, experiment with
- 4:11:42things knowing that you can always go
- 4:11:44back, share your projects with others,
- 4:11:45and also to use other AI tools, codes,
- 4:11:48and repositories from other people
- 4:11:50because whenever someone shares code
- 4:11:52online in a tutorial, 99% of the time
- 4:11:54they'll share it via GitHub. And knowing
- 4:11:56how to use git and then also what GitHub
- 4:11:59is will make all the difference. So,
- 4:12:01what we are going to cover is we're
- 4:12:03going to cover the fundamentals of git
- 4:12:05and then also I'm going to show you how
- 4:12:07you can set up GitHub. So, there's a
- 4:12:08difference between the two. That's also
- 4:12:10something you should be aware of. So
- 4:12:11we'll go over a basic setup all very
- 4:12:14quick. This is by no means like a full
- 4:12:16dedicated course on how to use GIP. But
- 4:12:18the thing is in the beginning you only
- 4:12:20really need to understand the
- 4:12:21fundamentals. There are only a hand few
- 4:12:23uh handful of things that you need to
- 4:12:25understand. So that's the nice thing
- 4:12:27about this and that's why I really
- 4:12:28wanted to be part of this course as
- 4:12:30well. Right. So let's start with what is
- 4:12:33version control. So like I've said, one
- 4:12:36of the main problems that GitHub can
- 4:12:38help solve is that we don't have to do
- 4:12:40something like this where we have your
- 4:12:42script and then you want to try
- 4:12:43something, you go to F2 and then you
- 4:12:45want to try final actually final and oh
- 4:12:47it still broke and then you need
- 4:12:48to create a backup. So that is the
- 4:12:51problem Git solves. So how it works, you
- 4:12:54can think of Git as taking a snapshot of
- 4:12:56your code. So you write your code, you
- 4:12:57make your changes, and then you can save
- 4:12:59the the snapshot. I'm going to show you
- 4:13:01how to do that. In Git, this is called a
- 4:13:03commit. So we commit our work and git
- 4:13:06remembers everything every snapshot who
- 4:13:08made it uh when and why. So when you
- 4:13:12when here's your code like for example
- 4:13:14on Monday you calculate the price over
- 4:13:16here and then on Tuesday your client
- 4:13:19says look we want to add a 25% markup.
- 4:13:22So you change it. So then on Wednesdays
- 4:13:24like hey can we actually go back to 20%.
- 4:13:27And in this case that's easy. You just
- 4:13:28go back to Monday's version. Now with
- 4:13:30this like tiny little change like
- 4:13:32changing one digit, it of course
- 4:13:34wouldn't be that big of a difference,
- 4:13:36right? But imagine you're having a big
- 4:13:37codebase, you are working on lots of
- 4:13:39stuff and then all of a sudden it
- 4:13:41doesn't work. Let's go back to the
- 4:13:42previous version. So that's really the
- 4:13:44key concept and a key problem that git
- 4:13:46solves. Uh let's go through a few
- 4:13:48fundamental concepts. This is really
- 4:13:49all. So this overview, this list, this
- 4:13:51is all that you need to know for now. So
- 4:13:54let's start with a repository. That is a
- 4:13:57project tracked by Git. That's why I
- 4:14:00also said that in the beginning when we
- 4:14:02were creating our projects right so when
- 4:14:04we were here when we were let me show
- 4:14:06you this in the finder when we were
- 4:14:09creating this project I already said
- 4:14:10look I recommend to do it with all like
- 4:14:13lowercase and dashes to make sure that
- 4:14:16also when we push this to GitHub that we
- 4:14:18can use the same repository name so
- 4:14:20that's where the repository come from
- 4:14:22that is simply a project tracked by git
- 4:14:25staging is a concept which allows you to
- 4:14:27choose which changes is to save. It's
- 4:14:30like selecting items to put in the box
- 4:14:32before shipping. So let's say you have
- 4:14:33all of your project and you say I want
- 4:14:34to save this, this, and this and this
- 4:14:36and maybe I would don't want to save
- 4:14:38that. Then we have the commit which is
- 4:14:41actually creating the snapshot of your
- 4:14:43code. Then we have pushing. This is
- 4:14:45uploading things to GitHub. So then now
- 4:14:48they also really become available
- 4:14:50online. Then we have pulling which is
- 4:14:52downloading the changes back. So let's
- 4:14:54say you are working with someone else on
- 4:14:56a team. They made some changes. They
- 4:14:58committed the changes. They pushed the
- 4:15:00changes. Now they are online. Now you
- 4:15:02can pull those changes and now you are
- 4:15:05at the same uh version again that they
- 4:15:07are. And we can also clone projects. So
- 4:15:10we can clone repositories from GitHub
- 4:15:12which I will also show you how to do. So
- 4:15:14this is if you're completely new and
- 4:15:16someone shares their work, you don't
- 4:15:18have it on your computer right now, you
- 4:15:19can clone it. So you'll find that Git
- 4:15:22has this like specific vocabulary, but
- 4:15:25it's nothing more than saving files,
- 4:15:27uploading them, and downloading the
- 4:15:29codes to your computer. That's all
- 4:15:32really there is to it. It just has its
- 4:15:34own specific vocabulary. All right, so
- 4:15:37first we're going to install Git on your
- 4:15:41computer. And first you need to check if
- 4:15:43you already have Git. So you can check
- 4:15:45out the Git version. So you can open up
- 4:15:47the terminal either on Mac or on
- 4:15:49Windows, doesn't matter. You do get git
- 4:15:51d- version. And here you can see on my
- 4:15:54laptop that it already says, look, you
- 4:15:56already have this version. So if it says
- 4:15:58something like this for you already, you
- 4:16:00can skip the installation phase. Now
- 4:16:02here are instructions for Windows, Mac,
- 4:16:05and Linux. It's pretty straightforward
- 4:16:07to go through. For Windows, you can just
- 4:16:08go to this website and you can download
- 4:16:10kit over here. You'll have the
- 4:16:12installer. And for Mac OS, there are a
- 4:16:13couple of options. So you can install it
- 4:16:15via homebrew if that's installed. You
- 4:16:17can also alternatively install it via uh
- 4:16:20Xcode command line tools. So if you do
- 4:16:22get desk version Mac, your MacBook will
- 4:16:24probably ask you, hey look, do you want
- 4:16:26to install git if it's not found, you
- 4:16:28can click install. You can wait a few
- 4:16:30minutes and otherwise you can also go to
- 4:16:32the official download page over here to
- 4:16:34find more information. So that should
- 4:16:37all be relatively straightforward by
- 4:16:39now. Oh, and then just make sure that
- 4:16:40git- version in the terminal uh works
- 4:16:43for you after the installation. All
- 4:16:46right, so now that git is installed on
- 4:16:48your system, let's go through how you
- 4:16:50can actually use it and work with this.
- 4:16:52And here is a very simple example, the
- 4:16:55most basic example of how git works. And
- 4:16:57I'm first going to show it here just
- 4:17:00conceptually. We're not going to work
- 4:17:01through it because we first need to set
- 4:17:03up GitHub uh on your end so that you can
- 4:17:05actually push the changes. But high
- 4:17:08level this is how git works. Whenever
- 4:17:10you're working on a project we first
- 4:17:12need to initialize the project. We need
- 4:17:15to create the project in git and we do
- 4:17:18this through git init. So this is these
- 4:17:21are terminal commands. So this is not
- 4:17:22something you run within your python
- 4:17:25script and then execute over here. This
- 4:17:27would be something where you open up a
- 4:17:29terminal and where within your folder
- 4:17:32you run these commands. Now the nice
- 4:17:34thing about uh VS code is that we can
- 4:17:38also do this through the UI. So there is
- 4:17:41a source control menu over here where
- 4:17:44you can for example see right now
- 4:17:45initialize repository. That would be the
- 4:17:48same as running git in it. So throughout
- 4:17:51this tutorial in this section I want to
- 4:17:53show you first how to use the commands
- 4:17:54because that's what's going on under the
- 4:17:56hood. But I always use the visual
- 4:17:59interface from Visual Studio Code
- 4:18:01because it's just a lot easier and you
- 4:18:02don't have to remember the commands. But
- 4:18:04you initialize the repository. That's
- 4:18:06step one. Then you're going to stage
- 4:18:08your changes. So you can say at get add
- 4:18:11and then the dot signals that you want
- 4:18:13to do everything. In most cases, this is
- 4:18:15what you want to do. You just want to
- 4:18:16save all your progress. So this is
- 4:18:18staging. That's how that works. Then we
- 4:18:20commit it. So then we can add a comment
- 4:18:24in there as well. So let's say we added
- 4:18:26or changed the price calculation. We can
- 4:18:28give a little comment for us later or
- 4:18:30for your team to know okay these are the
- 4:18:32changes that I made and then we push it
- 4:18:34to GitHub. So that's how git works. But
- 4:18:37now before running all of this let's get
- 4:18:40into the setup and then we can really
- 4:18:43run the end to end example because like
- 4:18:45you see you need to connect your GitHub
- 4:18:47first. All right. So let's get into the
- 4:18:50GitHub setup. Okay. So, if you don't
- 4:18:52have a GitHub account yet, go to
- 4:18:54github.com and sign up. So, let's see
- 4:18:57over here. I'm already logged in, but in
- 4:18:58here you can do sign up for GitHub.
- 4:19:00Create your account. You can use your
- 4:19:01Google account. Very straightforward.
- 4:19:04And then from there, pick a username,
- 4:19:06email, password, verify your account,
- 4:19:08you can set up your profile, profile
- 4:19:10picture, edit your name, image, whatever
- 4:19:12you want. This is one of the most
- 4:19:14important profiles as a developer. So,
- 4:19:16if you don't already have one, make sure
- 4:19:18to set it up. This is also literally
- 4:19:21what can get you hired. This this might
- 4:19:23be what people ask for on during
- 4:19:25interviews. Clients might want to see
- 4:19:27it. So this is going to be one of your
- 4:19:28most important profiles as a developer.
- 4:19:30More important than your LinkedIn
- 4:19:32profile for getting jobs and getting
- 4:19:34work. Okay. Now step number four is we
- 4:19:36now have your account created and we now
- 4:19:39need to create a link between your local
- 4:19:41computer and the uh online uh GitHub
- 4:19:45account really so that we have a link so
- 4:19:46that when we push the changes our
- 4:19:48computer knows where to send it. So you
- 4:19:51can first set up your name and your
- 4:19:54email. So this is a one-time setup that
- 4:19:56you need to do. So you can say get
- 4:19:58config global and you say your username
- 4:20:00and then you can say for example your
- 4:20:02name and also your email. This is a way
- 4:20:04for git to store all of the information
- 4:20:06so that when you do things on uh your
- 4:20:09computer, git essentially adds this
- 4:20:12information to all of the changes that
- 4:20:14you make. Okay? And then you so you do
- 4:20:16this in the terminal. So one more time,
- 4:20:18you open up the terminal and then it
- 4:20:20would be get config and then you would I
- 4:20:24would for example do eilar. That's how
- 4:20:26you set it up and you also do that for
- 4:20:28the email that you've used. That's a
- 4:20:30onetime setup. All right. All right. And
- 4:20:32then next we need to set up your
- 4:20:33authentication method to let your laptop
- 4:20:36know where your account is and how to
- 4:20:38authenticate so we can actually push
- 4:20:40changes. So the re my recommended
- 4:20:42approach is to do this through the
- 4:20:44GitHub CLI. So there are three ways to
- 4:20:45do it. You can do it with an HTTPS token
- 4:20:48SSH key, but the CLI is really the
- 4:20:50easiest one uh to do it. So on Mac OS
- 4:20:53you can do brew install um gh and then
- 4:20:56you install it. And on Windows, you can
- 4:21:00if you go you go in here, you can
- 4:21:01download for Mac and then you'll see
- 4:21:02download on Windows. And then you should
- 4:21:05that got get that up and running because
- 4:21:06what you can do then it's super easy.
- 4:21:09You can just open up a new terminal. I'm
- 4:21:12already uh authenticated. So I can for
- 4:21:14example do I can check this GH version.
- 4:21:17What's in here? Yes, you can do GH to
- 4:21:19see all of the commands that are in
- 4:21:21here. And then what you can do is you
- 4:21:24can do simply do gh login and there you
- 4:21:28can see where do you want to login. We
- 4:21:29do github.com. We go in here and then
- 4:21:32you can choose what's your preferred uh
- 4:21:33protocol. So you can choose uh SSJs
- 4:21:36which I recommend or http and then you
- 4:21:40can authenticate via the browser. So
- 4:21:41just follow the steps over here. And
- 4:21:43here's what that would look like. So you
- 4:21:45select SSH then you need to select the
- 4:21:47public key. So you can select one of the
- 4:21:48keys that is available there. Then you
- 4:21:50can give it the name. So for example,
- 4:21:52you can do MacBook Pro like 2023. That's
- 4:21:54my MacBook that I'm running this on. And
- 4:21:56then you select authenticate via the web
- 4:21:58browser and then a pop-up will open in
- 4:22:00the browser. You can log in. You'll find
- 4:22:02a one-time code that you then need to
- 4:22:04paste into the browser and then you just
- 4:22:06need to log in, select it, and then you
- 4:22:08should be good to go. You see all of the
- 4:22:10info here right now. This might be a
- 4:22:12lot, but when you go through it, it will
- 4:22:13just be step by step. Just so just to
- 4:22:15follow what the terminal is saying, hit
- 4:22:17enter and select what you want. So and
- 4:22:19otherwise always you can troubleshoot
- 4:22:21with uh JGPT in order to make the
- 4:22:24connection work. Okay. So now we have
- 4:22:26git installed. You understand high level
- 4:22:29how git works. We have authenticated
- 4:22:32your local git with your GitHub account.
- 4:22:35So we now have a sync. So now let's get
- 4:22:37into cloning and creating repositories.
- 4:22:40So two things you'll often do when
- 4:22:42working with git is downloading someone
- 4:22:45other someone else's work cloning and
- 4:22:47creating and starting your own projects
- 4:22:49and saving the progress. So let's learn
- 4:22:52both in this case and we are going to
- 4:22:54start by cloning a repository. So this
- 4:22:57means we can take a look at someone
- 4:22:59else's work and we can download that. So
- 4:23:03let's say we have the following file
- 4:23:06over here. So, you're looking online,
- 4:23:07you're following a tutorial, and you
- 4:23:09stumble upon the OpenAI quick start in
- 4:23:11Python from OpenAI. There are a bunch of
- 4:23:13examples in here, and you want to try
- 4:23:15and experiment with this. Now, what you
- 4:23:18can do with Git now that you have set it
- 4:23:19up correctly, we can easily take this
- 4:23:22project and download it to our computer.
- 4:23:25So, let's go through how you can do
- 4:23:28this. And we can execute a command
- 4:23:31through the terminal to download a
- 4:23:33repository. And in order to do that,
- 4:23:35what you want to do is you want to open
- 4:23:36up a terminal in the folder where you
- 4:23:39want to store the project. So if we come
- 4:23:41over to our Python projects, which is
- 4:23:42what I recommend to uh you have a single
- 4:23:45folder, right? What you can do on Mac,
- 4:23:47you can rightclick and if you go all the
- 4:23:49way to the bottom, so you can see
- 4:23:50services over here, you can see new
- 4:23:52terminal, add folder. What this will do,
- 4:23:55this will open up a new terminal. And
- 4:23:57we're already within this project. So
- 4:23:59you can see right now we are in this
- 4:24:01folder over here. So, we're already at
- 4:24:03the right uh point. And with in this
- 4:24:05case, we don't have to like do the CD
- 4:24:07and navigate through the terminal, which
- 4:24:09I always find a little bit annoying. On
- 4:24:11Windows, you can do the the same thing.
- 4:24:13If you right click a folder, file
- 4:24:14explorer, open in terminal. So, that's
- 4:24:17how to do it. And now, here's how you
- 4:24:19clone uh a repository. So, you don't
- 4:24:21have to do these commands over here. We
- 4:24:23can just go to the repository that we
- 4:24:26want to clone. We click on code over
- 4:24:28here and we copy the URL. So we copy
- 4:24:32this URL. Then we go to our folder over
- 4:24:36here and then make sure we have the
- 4:24:37terminal in here. And then you type in
- 4:24:39get clone and then you paste in the URL.
- 4:24:42Now when we do this, what you'll find is
- 4:24:44that now you can see OpenAI quickart
- 4:24:46Python is now downloaded in here. So now
- 4:24:49I can check in here and I can see
- 4:24:51everything that is within this
- 4:24:52repository. Now if you get an error over
- 4:24:55here, some type of a authentication
- 4:24:57error, just follow what is set in the
- 4:24:59terminal over here. It might be that
- 4:25:01because of how you set it up either
- 4:25:03through HTTP, SSH or GitHub CLI, there
- 4:25:05may be one additional authentication
- 4:25:08step that is required in here and this
- 4:25:10is just a first time setup that you need
- 4:25:12to do and if it then works you can also
- 4:25:14for example later use the SSH or the uh
- 4:25:17GitHub CLI uh command. So in my case
- 4:25:20this would also work. So let's see if I
- 4:25:22go in here and I for example remove this
- 4:25:25come in here one more time like this
- 4:25:27would do exactly the same thing and it
- 4:25:29would also download the repository in
- 4:25:32here. All right. So now the next thing
- 4:25:34that you can do here's quick little
- 4:25:36shortcut. So we now have the folder,
- 4:25:39right? And we could just as well like
- 4:25:41open up Visual Studio Code, create a new
- 4:25:43project, but there's actually a shortcut
- 4:25:44for this. And you can use the code uh
- 4:25:47command. And the first time you do this,
- 4:25:49you need to uh set this up. So in Visual
- 4:25:52Studio Code, if you are in here on Mac
- 4:25:55and you do commandshiftp and then you do
- 4:25:58shell command. So let's see in here. I
- 4:26:00do command shiftp and I do shell
- 4:26:03command. So I do install code command in
- 4:26:06path. If I click this, this is a
- 4:26:08one-time setup. Then what we can do now
- 4:26:11uh and with Windows it's uh it's the
- 4:26:13same thing during installation. Now what
- 4:26:15we can do is I can actually see the so
- 4:26:19let's see I mean change directory into
- 4:26:21this folder. So into the open AI and I
- 4:26:23can tap to autocomplete. I can now go
- 4:26:26into this folder. So now within the
- 4:26:27terminal I am here and then I can do
- 4:26:29code and I can do a dot and then this
- 4:26:32will open up this folder over here that
- 4:26:34you'll see. So in Visual Studio Code
- 4:26:37everything is in here and now I can
- 4:26:39simply just save it as a workspace. Save
- 4:26:42it in this folder. Everything that we
- 4:26:43learned right and now I can just close
- 4:26:45this out come in here and now I have
- 4:26:48this project and I can start working
- 4:26:50with this. So this is just also one of
- 4:26:52those things in the beginning you need
- 4:26:53to see it a couple of times. Uh you
- 4:26:55don't need to use the dot code. You can
- 4:26:57also what you can also even do like look
- 4:26:59I'll give you one more tip. You can also
- 4:27:01just take this you can on Mac you can
- 4:27:03drag it in here also works. So just
- 4:27:06click a little ways to make the whole
- 4:27:08process of getting projects onto your uh
- 4:27:11machine easier. So then coming back to
- 4:27:15the setup you now have it on your
- 4:27:17computer. What just happened? Get
- 4:27:18downloaded all of the files. get
- 4:27:20download all of the history and you can
- 4:27:22now run modify and learn from this code.
- 4:27:25So this is a very fundamental skill. So
- 4:27:27if you'll find that this might this
- 4:27:29video might be the starting point for
- 4:27:31you to do anything with Python. If you
- 4:27:33for example go to my you to my YouTube
- 4:27:35channel to my other videos, you'll find
- 4:27:37that every video where there is a an
- 4:27:40example I'll say look the link to the
- 4:27:42GitHub uh repository is in the
- 4:27:44description. You now know exactly what
- 4:27:46to do in order to get that codebase on
- 4:27:48your computer. and then to also follow
- 4:27:51along. Okay, so that was step number
- 4:27:52one, cloning, but we can also now create
- 4:27:56our own repository remember and now we
- 4:27:58can come back to the project that we
- 4:28:00were working on. So over here, so let's
- 4:28:02say we want to push this to we want to
- 4:28:05push this to GitHub. So let's see how
- 4:28:08that works. And before we're going to
- 4:28:11push everything, there's one more thing
- 4:28:13that we need to add and that is a git
- 4:28:15ignore file. And this is very important
- 4:28:17because there are some files that we
- 4:28:20just don't want to store to GitHub. And
- 4:28:22primarily this is going to be our
- 4:28:24virtual environment. So if I come over
- 4:28:26here and look at the virtual environment
- 4:28:28for example and I look at how big this
- 4:28:31is we can see this is uh this is 270 MBs
- 4:28:35and because this is because there's a
- 4:28:37Python installation in there and we
- 4:28:39don't want this in our version control
- 4:28:41and similar there are other files uh
- 4:28:43environment variables secrets cache the
- 4:28:46Macds store file we don't want that in
- 4:28:49there and git has a feature for that
- 4:28:51through git ignore how you can do that
- 4:28:53is you can come in here do create a new
- 4:28:55file and you do dot and you do get
- 4:28:58ignore and you hit enter. Now you can
- 4:29:00see VS code will also recognize this. So
- 4:29:02you will see a little icon in here for
- 4:29:05this file. And now what you want to do
- 4:29:06is you can copy paste this in here and
- 4:29:10save this. Now this I would say is the
- 4:29:13most minimal setup that you can go
- 4:29:15through. But there's actually a better
- 4:29:16way and something that we use for all of
- 4:29:19our projects. This is kind of like the
- 4:29:20starting point to set it, forget it. You
- 4:29:22never have to worry about it ever again.
- 4:29:24And that is available in the resource
- 4:29:26hub. So if you come in here and go to
- 4:29:28the resources, you see the git
- 4:29:30ignore.zip. So if you download this and
- 4:29:34then come let's see to the downloads. So
- 4:29:37let me actually show you what that looks
- 4:29:39like. We download that open in finder.
- 4:29:42What you can then do is you can unpack
- 4:29:44it. And this is also a hidden file. So,
- 4:29:46if you don't see it, what you can also
- 4:29:48do is just drag and drop the zip file
- 4:29:50into your project and then open it up in
- 4:29:53here. And then let's see. Let me
- 4:29:55actually get rid of this. And I'm moving
- 4:29:57a little bit quick in here, but I'm just
- 4:29:58like moving moving the file. And I'm
- 4:30:01going to unpack it here. And then you
- 4:30:03can see you have the zip. And then all
- 4:30:04you need to do because this depending on
- 4:30:06your system, this can be a little bit
- 4:30:08annoying because it will automatically
- 4:30:09give it a name. It doesn't need it needs
- 4:30:11to be exactly ignore. So it needs to be
- 4:30:14like this. And now you can see we have a
- 4:30:17whole list of all the files that we do
- 4:30:19not want in our version control. All
- 4:30:21right. So that's the get ignore file.
- 4:30:24It's one of those things in the
- 4:30:26beginning you set it, forget it, but if
- 4:30:27you don't do it, uh you'll run into all
- 4:30:29kinds of issues. So very important uh
- 4:30:32and useful feature and useful uh
- 4:30:34resource from the resource hub. So make
- 4:30:35sure you download that uh and we can use
- 4:30:38it for all your projects. So now we have
- 4:30:40our project locally, right? We have
- 4:30:42everything over here. But now what we
- 4:30:44need to do is we want to create a
- 4:30:46project on GitHub that we can send this
- 4:30:50to. So we now go to github.com and we're
- 4:30:53going to click on new. So over here I do
- 4:30:55new repository and then I'm going to
- 4:30:58call this Python for AI. So you can you
- 4:31:02can name it whatever you want but I
- 4:31:04recommend just following along with
- 4:31:05this. And let's see. You can decide if
- 4:31:09you want it to be public or private.
- 4:31:11This is really important. Not for this
- 4:31:13tutorial. You can totally set this to
- 4:31:15public. But this simply means that
- 4:31:16everything that you're going to save and
- 4:31:18store like everyone is going to see
- 4:31:20that. So of course when you are working
- 4:31:22on projects that are private projects
- 4:31:24that you don't want to share, I
- 4:31:25recommend always setting it to private
- 4:31:27as like a default and then only setting
- 4:31:29it to public if you really want to share
- 4:31:31stuff with like the world. Because if
- 4:31:33you want to share stuff with just your
- 4:31:35colleagues or friend, you can also
- 4:31:36invite them through a private
- 4:31:37repository. So this is important. So you
- 4:31:40can select you can select the owner if
- 4:31:42you have multiple uh repository names or
- 4:31:44like I I already have one. So let's for
- 4:31:46me I do like Python 4AI 2 just to show
- 4:31:49you what that looks like. And then you
- 4:31:51can leave everything as is. Make sure
- 4:31:52you set it to private. Uh this doesn't
- 4:31:54matter. And then you do create
- 4:31:56repository. Okay. So now we see this
- 4:31:59interface over here. And what we can now
- 4:32:01do is let's see we can do this. We can
- 4:32:05now connect our local project to this
- 4:32:08project that we just created. And how
- 4:32:11you can do that is through the following
- 4:32:14process. So we can come over here to our
- 4:32:17project. And I'm first going to show you
- 4:32:20how to do this via the terminal. But
- 4:32:22Visual Studio Code actually has a very
- 4:32:24nice interface for this where we can
- 4:32:27just initialize publish to GitHub. So
- 4:32:29this will make our life a whole lot
- 4:32:30easier. But I want to show you like the
- 4:32:33first time right now how to do it via
- 4:32:35the terminal just so you know what it is
- 4:32:37doing uh behind the scenes. So let's
- 4:32:39take things step by step and open up a
- 4:32:42new terminal over here. And then what
- 4:32:45you want to do is first we want to do
- 4:32:47the git init. So when we come in here we
- 4:32:50do get init. And this will create a
- 4:32:54github project with in the folder that
- 4:32:57we are working in. And you will see
- 4:32:59output in the terminal, but you won't
- 4:33:01see anything here in uh the explorer.
- 4:33:04But that is the thing there. This is
- 4:33:06also because it's a hidden file. So if I
- 4:33:08go in here, you can now see that there
- 4:33:10is a git folder with all of the
- 4:33:12information that git is going to keep
- 4:33:14track of. You don't have to do anything
- 4:33:16with this folder, but it's good to be
- 4:33:18aware that this folder is created
- 4:33:20because when it's hidden and you are,
- 4:33:22for example, moving files back and
- 4:33:24forth. If you make copies and you make
- 4:33:26changes and you forget to copy the uh
- 4:33:28git the git folder, then you can lose
- 4:33:30track of those changes locally. So
- 4:33:33that's important to keep in mind. Okay.
- 4:33:36Then what we are going to do is we're
- 4:33:38going to stage your files. So we're
- 4:33:40going to run the command get add. And
- 4:33:43add simply means we're going to stage,
- 4:33:45we're going to select which files we
- 4:33:46want to add, but we want to send to our
- 4:33:49online GitHub project. And the dot
- 4:33:51simply means that we want to do all the
- 4:33:53files. So this is very common. Um,
- 4:33:55unless you really know what you're
- 4:33:57doing, generally what you want to do is
- 4:33:58just want to add all the files. So let's
- 4:34:00do that right now. So we come in here,
- 4:34:02we do get add, and then we do a dot, we
- 4:34:05hit enter. So now it's going to add all
- 4:34:07of the files, and it's they are staged.
- 4:34:10And now the next step is we're going to
- 4:34:11commit our files. So this is actually
- 4:34:13where we're going to save save the
- 4:34:15snapshot. And the syntax for this is get
- 4:34:18commit. Then we do dash m and then we
- 4:34:19can leave a comment. So we can we can
- 4:34:22put anything in here. Initial commit
- 4:34:24would be fine. So I'm simply going to
- 4:34:25copy paste this. Come over here. And
- 4:34:27then I'm going to do let me actually
- 4:34:29clear this up. Uh get a fresh slate
- 4:34:32again. And then we do get commit-m
- 4:34:34initial commit. And now you can see look
- 4:34:37we have created all of these snapshots
- 4:34:39in here. All the information is now
- 4:34:41stored. everything that's in here except
- 4:34:43for the files that were in git ignore.
- 4:34:45All right. And now the next thing we
- 4:34:46want to do is rename our branch to main.
- 4:34:49So this is just a naming convention in
- 4:34:51git. So we make sure that we are on the
- 4:34:53main branch. You can see that over here
- 4:34:55in the lower corner right now. And then
- 4:34:57the final thing we want to do is we
- 4:34:59connect GitHub to our local project. So
- 4:35:02if you come over here to GitHub again
- 4:35:04where also all of these uh settings are
- 4:35:07depending on where you do HTTPS uh or
- 4:35:09SSH you can now add your remote. So you
- 4:35:12can also follow just the instructions
- 4:35:14over here. So I'm going to add the
- 4:35:16remote for my it will probably say it's
- 4:35:18already there but for you it will
- 4:35:19connect it and then the final thing that
- 4:35:22we can do is we push it. So get push u
- 4:35:24origin main. Now I know these these are
- 4:35:27a lot of steps right and when you do
- 4:35:29this for the first time let's see if it
- 4:35:30works. There we go. So, we have now
- 4:35:32pushed all of these changes to GitHub.
- 4:35:35So, congratulations. If you followed
- 4:35:37along, if I now uh when I'm here and I
- 4:35:39do a refresh, you can see look, we now
- 4:35:42have our own private project, our
- 4:35:43private repository with all of our
- 4:35:45files. And again, now coming back to
- 4:35:47this, this is a lot, right? So, but
- 4:35:50remember in this section of the course,
- 4:35:52if you if you've been following like
- 4:35:54from the start for GitHub, there were so
- 4:35:56many things like we created account, we
- 4:35:58did the setup to authenticate, we
- 4:36:00created the repository, now we do all of
- 4:36:02these commands. And you might feel like
- 4:36:04Dave, like working with Git, I'll rather
- 4:36:06just duplicate the folder and have a
- 4:36:08backup like that than doing all of this.
- 4:36:09But you don't want to do that. And like
- 4:36:1280% 90% of what we just did is just a
- 4:36:15one-time thing. And I'm actually going
- 4:36:17to show you how easy it is on a
- 4:36:19day-to-day using terminal commands and
- 4:36:22then later in the next step even how
- 4:36:23it's even easier if you just a visual
- 4:36:25UI. But now that everything is set up
- 4:36:28really the 90% of what you'll do with
- 4:36:30git in the beginning is look right now
- 4:36:32over here let's say we have our file
- 4:36:34over here and we say we have the
- 4:36:36analyzer and we make some changes. So we
- 4:36:39for example say I don't know let's let's
- 4:36:42even just put like a small comment in
- 4:36:45here. So we we make a change there and
- 4:36:47we do another print statement to print
- 4:36:50the uh grand total one more time over
- 4:36:53here. So we made some changes to our
- 4:36:56code. We can save it locally in here.
- 4:36:58But now what we can do is now if we can
- 4:37:00come into our terminal we can check
- 4:37:02using a git status to see what the what
- 4:37:05the changes are. So you can see look we
- 4:37:08have we have made some changes to this
- 4:37:10file over here which are not tracked. So
- 4:37:13now what we can do let's say it's you're
- 4:37:15working on a feature and you like want
- 4:37:17to save it right now or it's end of day
- 4:37:19and you just want to save your work
- 4:37:21right now we can do we can just follow
- 4:37:23the process over here. So we can just
- 4:37:25say look we want to do get add we want
- 4:37:27to add everything in between you can
- 4:37:29also always do a get status. So now you
- 4:37:31can see it's green. We stage the
- 4:37:33changes. Now you can do g commit-m
- 4:37:36and then we can say uh made some changes
- 4:37:40and we commit that. And now we do a g
- 4:37:42push and now it will send all of that
- 4:37:45information. And if we come over here
- 4:37:47you can now see that right now you can
- 4:37:50see it's updated right now. And the cool
- 4:37:52thing about git is now that everything
- 4:37:54is tracked because I can now come in
- 4:37:56here and I can see look made some
- 4:37:57changes and I can see exactly what I
- 4:38:01updated to these files. So that's on a
- 4:38:04day-to-day now that you have set it up
- 4:38:06all really that you need to do with git.
- 4:38:08You just work on your project and then
- 4:38:10whenever you want to save things you do
- 4:38:13a simple update. But there is an even
- 4:38:15better way to work with git and that is
- 4:38:17just using the UI in VS code. So this is
- 4:38:20how I always work with Git. It's super
- 4:38:22easy and it's available from this
- 4:38:25section over here. So you can click on
- 4:38:27the little version control icon and let
- 4:38:30me show you what that looks like. So now
- 4:38:32let's say I want to refer to changes. So
- 4:38:34I want to go back to let's say we want
- 4:38:36to read data and we also don't need this
- 4:38:39in here. We made some changes. You can
- 4:38:41see right now here on the left you can
- 4:38:43see one there's one change meaning we
- 4:38:46changed one file. And if I change other
- 4:38:49files as well. So let's say in the
- 4:38:50helper functions uh I do like um let's
- 4:38:54say I put functions here just just to
- 4:38:57make a quick change you'll find that
- 4:38:58look this is now updating to a two. So
- 4:39:01you can now see git will now tell us
- 4:39:03like look you have two changes in here.
- 4:39:06And now one of the cool things that you
- 4:39:08can do right now is uh you you don't
- 4:39:11really have to stage changes in here or
- 4:39:15uh even come up with your own commit
- 4:39:16messages nowadays in Visual Studio Code.
- 4:39:18You can just click on this and then if
- 4:39:20you uh sign up with GitHub Copilot, you
- 4:39:23can even let AI create messages for you.
- 4:39:25So if you want that like let's see, we
- 4:39:27can skip that for now. That's a very
- 4:39:29nice feature to do because what it will
- 4:39:31do is will look at your files. it will
- 4:39:33look at the changes and it will just
- 4:39:34create a descriptive message for you
- 4:39:36because coming up with commit messages
- 4:39:38is probably one of the hardest things to
- 4:39:40do as a developer and this just make the
- 4:39:42whole process easier. So I recommend to
- 4:39:44check out GitHub copilot. But let's uh
- 4:39:46for now say we made some updates. And
- 4:39:49what I can do right now I can simply
- 4:39:52come in here and I can either hit
- 4:39:53commit. So this would be the same as
- 4:39:55running the git commit with the message.
- 4:39:57But I can also click on here and I can
- 4:39:59do commit and push. And if I do it like
- 4:40:01this you can say look there are no stage
- 4:40:04changes. And I can say look I want to do
- 4:40:06this always. So I want to before doing
- 4:40:07this I want to stage all changes. So
- 4:40:10when this is set up now you can see we
- 4:40:14have successfully let's see made another
- 4:40:17commit with the updates and now all you
- 4:40:20really have to do is come in here make
- 4:40:22changes and whenever you uh and whenever
- 4:40:25you want to push them let's see let's
- 4:40:27come over here whenever you want to push
- 4:40:29them so now the function or the comment
- 4:40:31here is is gone whenever you want to
- 4:40:33push them says removed comment come over
- 4:40:36here get push done okay so hopefully Now
- 4:40:40it's a little bit less scary, right? We
- 4:40:42went from a lot of controls to like how
- 4:40:43do we set this up and all kinds of
- 4:40:45commands to now literally giving a
- 4:40:47comment and then clicking on one button
- 4:40:48in order to save our work and make it
- 4:40:51available uh via git. So this is one of
- 4:40:53those things I know we spend uh quite
- 4:40:56some time here on working with git but
- 4:40:58if this the is this is the first time
- 4:41:00that you're working with code the first
- 4:41:02time programming like this look took
- 4:41:04really long for me to actually figure
- 4:41:06out how to do properly because there's
- 4:41:08just so much that you can do if you go
- 4:41:10over to the resource hub uh and actually
- 4:41:12go to the git cheat sheet you can find
- 4:41:14everything that you can do with git
- 4:41:16there's really a lot to it but what I've
- 4:41:19just shown you on a day dayto-day is
- 4:41:21really like the 80 80 90% that you'll uh
- 4:41:25that you have to do. Now there's one
- 4:41:27more quick thing that I uh want to show
- 4:41:29you and that is also you can also very
- 4:41:31easily create GitHub repositories from
- 4:41:35within git. So for example, if I'm here
- 4:41:37in my Python projects folder and I want
- 4:41:38I have a new idea and I want to start a
- 4:41:40new project, I can create a new folder
- 4:41:42here. Let's say I want to build an AI
- 4:41:44agent. So we we create an AI agent
- 4:41:46folder and now what I can do is I can
- 4:41:49open up uh this folder in a terminal. So
- 4:41:51I go to services, new terminal over here
- 4:41:54and then I can do code to open it up or
- 4:41:58just simply drag and drop it in here. So
- 4:41:59now this is a completely empty uh empty
- 4:42:02folder, completely empty repository. But
- 4:42:04what I can do if I come in here I can
- 4:42:07click on here and look I can now say
- 4:42:09look I can initialize a repository. So
- 4:42:12we create an repository and then uh
- 4:42:14let's say I just do a first file in
- 4:42:16here. So let's say we do just do a
- 4:42:18readme.m MD which is going to be uh my
- 4:42:22awesome agent project. Now we save that.
- 4:42:26So you can now see we have a file in
- 4:42:29here. And now what what the nice thing
- 4:42:31is about Visual Studio Code, we can just
- 4:42:32say do like first init. And then I can
- 4:42:36do commit and push. And what it will now
- 4:42:38do, it will say look there is no remote
- 4:42:41in here. Do you want to add a remote?
- 4:42:43And if we actually cancel out of this uh
- 4:42:46just cancel it, it will say publish. Do
- 4:42:48you want to publish the branch? And then
- 4:42:50we say yes. And then we say there is no
- 4:42:52uh GitHub extension. Do you want to sign
- 4:42:53in? So we do yes. Follow uh with this.
- 4:42:56And then let's see, we open it up again.
- 4:42:58So this is also just a one-time sync.
- 4:43:00And now what you can see now we can say
- 4:43:02look do you want to push this to a
- 4:43:04private or to a public repository? Say
- 4:43:06okay, I want this to be a private
- 4:43:08repository. And now we are going to
- 4:43:10create. Now we have everything set up.
- 4:43:13So now we have really like boiled it
- 4:43:15down to we can just open up a folder
- 4:43:17within Visual Studio Code like try to
- 4:43:20make a change save something uh and then
- 4:43:22it it will like essentially error and
- 4:43:24then we can create the project or we can
- 4:43:26also do it from uh from the beginning
- 4:43:28but this is the process. This is how I
- 4:43:29always do it. So whenever I have a new
- 4:43:31project and now we just come in here and
- 4:43:33if I now like uh make changes in here
- 4:43:36say let's start git will now simply like
- 4:43:39kick into action and say look now we
- 4:43:41have changes in here. Uh so we do the
- 4:43:44quick update do commit push and that's
- 4:43:47all there is to it. So now you can see
- 4:43:49it automatically updates. So for now let
- 4:43:53me go in here. You can also manage all
- 4:43:55of your settings. You change your
- 4:43:56visibility and I'm going to actually
- 4:43:58delete this repository. just get out of
- 4:44:00this. Uh so that's also how you can do
- 4:44:02that if you have a project that you
- 4:44:04don't want anymore. Just wrapping this
- 4:44:05up, but I'm just showing you from like a
- 4:44:07more practical point of view how this
- 4:44:09works in the day-to-day because again
- 4:44:11for me in the beginning it was so weird
- 4:44:13like all of these commands that you
- 4:44:15needed to remember. This is really what
- 4:44:16it comes down to. So this section was
- 4:44:18really important. And that wraps up the
- 4:44:20Git and GitHub portion. You now know the
- 4:44:2390% that you need to know to confidently
- 4:44:26follow all of my tutorials and tutorials
- 4:44:28from other people as well. You know how
- 4:44:30to create repositories, what they are.
- 4:44:33You know how to use Visual Studio Code
- 4:44:34and the terminal in order to manage all
- 4:44:36of this. So now let's get into
- 4:44:39environments and secrets. All right. So
- 4:44:41now that you understand how you can work
- 4:44:43with git and how you can also send
- 4:44:45information and store information to
- 4:44:46GitHub, it's important to understand how
- 4:44:49you can keep your own data safe because
- 4:44:52when you are working on serious
- 4:44:54applications, there are always going to
- 4:44:55be credentials in the form of API keys,
- 4:44:58passwords, and connection strings for
- 4:44:59example to a database. And from a uh
- 4:45:02security perspective, you want to keep
- 4:45:04this as private as possible because for
- 4:45:06some applications with just a single API
- 4:45:09key, someone can have like full access
- 4:45:12to a system. It can pull all your
- 4:45:14customer information. It can send
- 4:45:16messages to customers. For example, if
- 4:45:18you have an API key for a CRM system. So
- 4:45:21you want to be really careful with that
- 4:45:23and you don't want to push that to your
- 4:45:25version control. So you don't want to
- 4:45:27have that in in GitHub really or in git.
- 4:45:30you don't but you just want it to be
- 4:45:31locally only where the application needs
- 4:45:34it. So this is something you'll
- 4:45:36literally find in almost all of my
- 4:45:38tutorials when we are working with AI
- 4:45:40models like OpenAI or Entropic and we
- 4:45:43need the need the API keys. So in order
- 4:45:46to um have a workaround so that we can
- 4:45:49use these these files without pushing
- 4:45:52them to our version control let's
- 4:45:54understand environment variables and
- 4:45:56then the env file in Python and how we
- 4:45:58use them. So let's start with the
- 4:46:00environment variables. So environment
- 4:46:03variables are stored outside of your
- 4:46:05code. So you can think of these as a
- 4:46:07configuration that your program can
- 4:46:09read. So let's say you have an API key
- 4:46:11or a database. We don't really want to
- 4:46:14hardcode that within our file. So let's
- 4:46:17say for example, let's come over here.
- 4:46:19We don't want to do this. So let's say
- 4:46:21let's come over here. We do get our
- 4:46:23data. Uh we don't want let's say this uh
- 4:46:26this this API would need an API key. We
- 4:46:29don't want to do this because right now
- 4:46:31anyone that would have access to this
- 4:46:34file could simply like take this extract
- 4:46:37it and then use it in their own files in
- 4:46:39order to access your system. So this is
- 4:46:42hard coding private or secret
- 4:46:44information. We don't want that. We
- 4:46:46don't want this showing up in our Python
- 4:46:48files. So we want to store them in
- 4:46:50environment variables. And how they are
- 4:46:53how they work behind the scenes is they
- 4:46:56live in your system, not in your code.
- 4:46:58And we can use the OS library in order
- 4:47:01to safely read the API key from our
- 4:47:04environment. So it's only within the
- 4:47:06environment that we need it. And we use
- 4:47:08that by with the following syntax. So we
- 4:47:10import the OS library and then we say
- 4:47:12osenvironment.get
- 4:47:14and then we do for example API key and
- 4:47:16then we can print it. But before we can
- 4:47:19do that, we first need to uh set up the
- 4:47:22environment variables. So let's show how
- 4:47:25this works. So let's see. We can come in
- 4:47:28here. Let's go to our hello.py file.
- 4:47:31This is currently empty. If we come in
- 4:47:33here and let's say I come over here and
- 4:47:35just import this. We can now see look we
- 4:47:38have an API key and we have a database
- 4:47:40and that is the API key, database name.
- 4:47:42We can even set default values. If I now
- 4:47:45run this, what you'll find is that
- 4:47:47database will have a default value of
- 4:47:49DB. But if we go to the API key, it is
- 4:47:52going to say look this is none. There is
- 4:47:55no API key because it is not set.
- 4:47:58Similar if we let's say we remove the
- 4:48:00default value in here and we say again
- 4:48:04the database same thing it will say look
- 4:48:07there is no uh there is no database
- 4:48:09connection key over here. So how do we
- 4:48:12then set that? Well we can do that
- 4:48:15coming over here using an export
- 4:48:18statement. So if we come over here and
- 4:48:22we export this in the terminal session.
- 4:48:25So coming over here to our our project,
- 4:48:28we can actually open this up and then
- 4:48:32set this and we can export it. So we've
- 4:48:34now exported the API key. So this is now
- 4:48:36available within our system. But let's
- 4:48:38have a look at if we now change this to
- 4:48:41API key and we run this file. So we do
- 4:48:45run the Python file. We run it over
- 4:48:47here. You'll still see that it prints
- 4:48:49none over here and the API key is not
- 4:48:52available and similar if we do that over
- 4:48:54here and just for the print statement.
- 4:48:56So no API key also not here. But now if
- 4:48:59I do the export one more time. So I
- 4:49:02export it here in the terminal session
- 4:49:04and I use that same session to run this
- 4:49:06Python file one more time. Now you can
- 4:49:08see that it correctly has access to the
- 4:49:12API key in here. Let me actually save
- 4:49:14that. So now if you save that it should
- 4:49:16also uh print. So now it should also
- 4:49:18print the API key. So you can see that
- 4:49:21through this we can actually make
- 4:49:23information available within our
- 4:49:26terminal session in our system and then
- 4:49:28our Python files can use this. But you
- 4:49:30can see this is a little bit cumbersome
- 4:49:32because now if I like X out of this and
- 4:49:35remove this it's now it's not available
- 4:49:37within the interactive session. And if I
- 4:49:40start a new fresh terminal in here, you
- 4:49:43still find that it prints none because
- 4:49:45now we would have to export it one more
- 4:49:47time. So we export it one more time and
- 4:49:50then it's available. So now if we
- 4:49:51continue to work in here, it's
- 4:49:53accessible. So this is fundamentally how
- 4:49:56it works and how we can make it
- 4:49:57available. But there is a much better
- 4:49:59way to to do this in a much more
- 4:50:01effective way that like takes care of
- 4:50:03this process. We need to set it up once
- 4:50:05and then never have to worry about it
- 4:50:07ever again. And that is through using
- 4:50:09the env file and environment variables.
- 4:50:12So you you'll notice that I follow a
- 4:50:14simil similar uh approach over here as
- 4:50:16to git and github. I first show you kind
- 4:50:18of like the more complex way how it
- 4:50:20works under the hood and then I'm going
- 4:50:22to show you the the simple way that
- 4:50:24makes it really easy to do this. So
- 4:50:27instead of doing the exports all the
- 4:50:29time, what is very common in Python is
- 4:50:32to use files. So what we can do is if we
- 4:50:35come over to our project I can do new
- 4:50:37file I I can do env and you'll find that
- 4:50:40in the git ignore file that we created
- 4:50:43the env file is also already excluded
- 4:50:46out of here. So uh this will not be
- 4:50:48tracked in version control. So you can
- 4:50:50see that even though I added the file it
- 4:50:52only says look only the only changes we
- 4:50:55have is to hello.py Pi and if I create
- 4:50:58for example an env let's say txt file
- 4:51:02and I come over here you'll find that
- 4:51:04this is tracked. So now if I push this
- 4:51:07it will be added to to GitHub which is
- 4:51:10not the case for the file because it's
- 4:51:12in the git ignore. So what we can now do
- 4:51:15over here is we can come in here and
- 4:51:17this is a place where we can now store
- 4:51:19secret information. So all of the stuff
- 4:51:22that we don't want to include in our
- 4:51:23version control which can be things like
- 4:51:25let's see like API keys database URLs
- 4:51:27app settings file paths all stuff that
- 4:51:30we can dump in here. So now what we can
- 4:51:33do let's take this over here this line
- 4:51:36plug that in. So we create our env file
- 4:51:39and now we can use a Python library
- 4:51:42python. M which we can pip install to
- 4:51:45safely load this information. So what I
- 4:51:47can do right now pip install and coming
- 4:51:50back to let's say let's get to hello.py.
- 4:51:53So remember right how do we install
- 4:51:54packages we go to terminal we open up a
- 4:51:56terminal or we do a new terminal and
- 4:51:58then make sure our virtual environment
- 4:52:00is selected which should already
- 4:52:02automatically applied. If you have any
- 4:52:04errors make sure that is selected over
- 4:52:07here and then we can do a pip install.
- 4:52:10So let me actually show you what happens
- 4:52:11if you don't install it correctly. So
- 4:52:12it's going to be from.f
- 4:52:14import load.nf.
- 4:52:18So if I now try to run this, it will
- 4:52:21tell me look there is no module. And the
- 4:52:24way you install this is by doing pip
- 4:52:26install python.n. So now it's installed.
- 4:52:29And now if I run this, we should find
- 4:52:32that we now get the green check mark and
- 4:52:34we can import it. Okay. So what we can
- 4:52:36then do is let's see we can now use this
- 4:52:41simple uh function over here that we
- 4:52:43import from the module and this is going
- 4:52:46to load our env file and it will
- 4:52:48automatically try to find it. So let's
- 4:52:50see what that looks like if we do that
- 4:52:52over here. You can see it says true if
- 4:52:56it cannot find the env file. So for
- 4:52:58example, if I put this in here and move
- 4:53:01this and I do this one more time, it
- 4:53:02will probably say that it cannot find it
- 4:53:05in here. Look, it says false. So this
- 4:53:08has some capabilities behind it where it
- 4:53:10will automatically look in the current
- 4:53:12folder and it will also it's some
- 4:53:14sometimes it's a little bit annoying.
- 4:53:16Sometimes I feel like it works also in
- 4:53:18uh folders above, but sometimes it can
- 4:53:19also get confused. So uh sometimes you
- 4:53:22have to specifically select the path but
- 4:53:24out of the box when it's in the same
- 4:53:26folder over here in the root of your
- 4:53:28project it generally tends to work but
- 4:53:31this is a check that you need to be
- 4:53:32aware of you can also do it explicitly
- 4:53:35right so if I let's say I have another
- 4:53:36folder and I'm just showing this because
- 4:53:38this is stuff that you can encounter in
- 4:53:39the real world and for example you want
- 4:53:41to have your env file here if I now run
- 4:53:44this it will say false and then what I
- 4:53:47can do is I can specify the path so I
- 4:53:49can say look it's in folder and then
- 4:53:51forward slash env. And now you can load
- 4:53:55it. So if you ever run into an issue
- 4:53:57where it cannot find it, just point to
- 4:53:59it specifically. And this just works the
- 4:54:02same way that we learned with the path,
- 4:54:04right? So you can also go up. So let's
- 4:54:06say you were in some folder and you need
- 4:54:07to go up one level. This is how it
- 4:54:10works. So generally you want to keep
- 4:54:12that at the root of the project. Let's
- 4:54:14move that over here. And now from within
- 4:54:16this hello.py Pi file we can simply run
- 4:54:20this. So what it is now doing behind the
- 4:54:23scenes now it is loading these variables
- 4:54:27that we have in here this secret
- 4:54:28information into our session and we can
- 4:54:30now use the OS library to retrieve
- 4:54:33those. So now if I look at this you can
- 4:54:35see look we can now access our API keys
- 4:54:38and now it works regardless of whether I
- 4:54:41am using the interactive session or the
- 4:54:43terminal. So let's see I think the
- 4:54:44database we need to database let's do
- 4:54:46database let's actually change this to
- 4:54:49database URL because it is a URL in this
- 4:54:51case and now we can simply say look we
- 4:54:54have the database using database and
- 4:54:58then database. So now I can run this and
- 4:55:01it will load the API key it will load
- 4:55:03the database and if I run this in here
- 4:55:06you can also see that also through the
- 4:55:08terminal you will get the correct
- 4:55:10information. So, this is the
- 4:55:12introduction to working with
- 4:55:14environments and secrets. It's a little
- 4:55:16hack that you need to know, a little
- 4:55:17trick that you'll see in almost any AI
- 4:55:20video where they're using the Open SDK
- 4:55:23because you need an API key. And this is
- 4:55:25how you do it. You don't want to
- 4:55:26hardcode that. Make sure you create an
- 4:55:28ENV file. You have the right git ignore
- 4:55:30file and then you plug in your API key
- 4:55:33in here. And then in your file, you just
- 4:55:35import the load. Mf library. Make sure
- 4:55:37it's installed via pip. you call the
- 4:55:40load.n function and now you can use the
- 4:55:43OS library to retrieve it from your
- 4:55:45system. Now next up in the Python tools
- 4:55:48section I want to introduce you to rough
- 4:55:51which is a really cool tool that we can
- 4:55:53use to format and lint our code. So this
- 4:55:56is going to make making writing pretty
- 4:55:59code and adhering to certain standards
- 4:56:01and style guidelines super easy and
- 4:56:04convenient. So with Rough you'll get
- 4:56:06three tools in one which I will show you
- 4:56:08right now. that is linting, formatting
- 4:56:10and import sorting. So let's go through
- 4:56:12this. First we have to do a quick setup.
- 4:56:15So we can actually install it in visual
- 4:56:17studio code and what we can do is we can
- 4:56:19go to the extensions one more time
- 4:56:21remember. So go over here extensions. We
- 4:56:24can search for rough. So in here it will
- 4:56:27be this one from Astral. You can click
- 4:56:29here on install. So I I'm also going to
- 4:56:31do a fresh install in here. So that
- 4:56:33takes a couple of seconds. Okay. Now it
- 4:56:36is installed. Let's see. Come back over
- 4:56:38here. So that's the installation. Super
- 4:56:40simple. And now what we can do is we can
- 4:56:42enable formatting on save. And this lets
- 4:56:45FS code automatically format your code
- 4:56:46when you save it. So this is available
- 4:56:48from the settings. So we can open it up
- 4:56:51and then search for format on save. So
- 4:56:54you can either go to the gear icon over
- 4:56:56here, go to settings or do command or
- 4:56:58control and then a comma which will open
- 4:57:01it up. And I will search for format on
- 4:57:02safe. And then you want to check this
- 4:57:04box over here. And then the next thing
- 4:57:06you want to search for is the default
- 4:57:08formatterater. And we're going to set
- 4:57:09that to rough. So here you find default
- 4:57:11formatterater. You'll find a list and
- 4:57:13rough should be in here if you installed
- 4:57:15the extension. So we'll plug that in
- 4:57:18there as well. And now you've
- 4:57:19successfully installed and configured
- 4:57:21rough. So now let's see it in action. So
- 4:57:24what does formatting mean? Well, in the
- 4:57:25beginning we talked about syntax, right?
- 4:57:28So spec there are certain rules in
- 4:57:30Python that you just need to follow
- 4:57:31otherwise you'll run into errors. But
- 4:57:34there are also style guidelines. And
- 4:57:36remember how I talked about the PEP 8
- 4:57:37style guidelines, right? Rough is a tool
- 4:57:39that can help us to adhere to these
- 4:57:42style guidelines. So if I have this
- 4:57:44messy code over here, you can follow
- 4:57:46along by simply copy and pasting this.
- 4:57:48Like we know right now this doesn't look
- 4:57:50good, right? There are too many spaces
- 4:57:52in here. There should be a white line in
- 4:57:55here. Here we have a bunch of here we
- 4:57:58have a dictionary where it's pretty hard
- 4:58:00to read what's in here. So we can
- 4:58:02improve that. and even the spacing in
- 4:58:04between. So, let's take a look at this.
- 4:58:05Now, if I come over here to our editor,
- 4:58:08I plug it in. You'll find that this is
- 4:58:10now a little bit messy, but watch what
- 4:58:12happens when I do command save.
- 4:58:15That's cool, right? The first time that
- 4:58:17I saw that was like, oh, this is so
- 4:58:19awesome. So, now you can just go about
- 4:58:21writing your writing your code and then
- 4:58:24whenever So, let me see. So whenever you
- 4:58:26like make a mistake, you don't add
- 4:58:28whites space, you don't add a space or
- 4:58:30the indentation or anything that is
- 4:58:32weird that is not a syntax error, boom,
- 4:58:34rough will fix that. So that's the auto
- 4:58:37formatting. And you'll find that if you
- 4:58:40use this, all the files that you are
- 4:58:42working with will have a similar setup
- 4:58:44and your code becomes very readable
- 4:58:46because it will also take care of line
- 4:58:48length. will make sure that when you
- 4:58:50have a list with dictionary items in
- 4:58:52here for example that it places nice and
- 4:58:54neatly on new lines. We can even go as
- 4:58:56far and adding adding a comma over here
- 4:58:59and then what it will do it will even
- 4:59:01split that and make it even more split
- 4:59:03up into more new lines. So these are all
- 4:59:05things that you can play with and we
- 4:59:07never have to think or worry about the
- 4:59:09formatting ever again. So let's see
- 4:59:11formatting and that's the most obvious
- 4:59:12one and also the most convenient one.
- 4:59:14But let's have a look at linting and
- 4:59:16import sorting. So linting is finding
- 4:59:18issues and potential errors. So these
- 4:59:21are the yellow squiggly lines that you
- 4:59:23sometimes see that our editor already
- 4:59:24gave through pylons. But rough takes
- 4:59:27this a step further. So if I now for
- 4:59:29example come in here, you can see that
- 4:59:31we have these yellow lines over here
- 4:59:33under OS. And if I scroll on that, for
- 4:59:36example, you can see pilance is giving
- 4:59:39an error or giving a suggestion over
- 4:59:41here. But then rough is also saying look
- 4:59:43we have an uh we have OS but it's
- 4:59:45imported but we don't use it. So these
- 4:59:48are little hints where it doesn't break
- 4:59:50your code but it's overall much cleaner
- 4:59:52if we get rid of this. So now one of the
- 4:59:55cool things that you can do with rough
- 4:59:56is we can form auto correction. So we
- 4:59:59can do this through the command pallet
- 5:00:00and that is command shiftp or control
- 5:00:02shiftp if you're on windows. You can
- 5:00:04type in rough and you'll find that there
- 5:00:06are a couple of actions that you can
- 5:00:08select from here. So one is for example
- 5:00:10fix all autofixable problems. So if I
- 5:00:12click on this you'll find that it
- 5:00:14automatically gets rid of the import OS
- 5:00:17that was in there and now we have
- 5:00:18cleaned up our Python file in just two
- 5:00:21actions. We save it and we also try to
- 5:00:23fix all autofixable problems. Now
- 5:00:26there's one more thing and that is
- 5:00:27import sorting and this is just if you
- 5:00:29like want to really be nice and neat
- 5:00:31when you're working on your Python
- 5:00:32projects. So if I come over here let's
- 5:00:34see if there's an example in here where
- 5:00:36we have some imports. So you can see the
- 5:00:38helper. Let's see. Let's actually get
- 5:00:41into the get data. Yes, over here. Here
- 5:00:43we have a bunch of imports. If I open up
- 5:00:45the command pallet one more time,
- 5:00:46control shiftp or command shift P and I
- 5:00:49do rough. I can also do format imports.
- 5:00:52And what you'll find over here is it
- 5:00:54will it will format the imports in a
- 5:00:56very specific way. And this will just
- 5:00:58help to make all of your code and all
- 5:00:59your imports very similar so that
- 5:01:01whatever file you open there is a
- 5:01:03similar structure and everything reads
- 5:01:05very similar. So that's what Rough can
- 5:01:06do and I absolutely love it. Linting,
- 5:01:08formatting, and import sorting. All
- 5:01:10right. And my final gift to you in this
- 5:01:13full Python beginner course is a tool
- 5:01:16called UV. And this is a more modern way
- 5:01:19to to work with Python and to manage
- 5:01:21your packages and environments. And it's
- 5:01:23a super awesome tool. And all the top
- 5:01:25developers and top teams are adapting
- 5:01:27it. So I really want you to learn it as
- 5:01:29well. And I wanted to start with the
- 5:01:32fundamentals, right? Because as a Python
- 5:01:34developer, you need to understand what
- 5:01:36pip is. You need to know how to work
- 5:01:37with the requirements.t txt. You need to
- 5:01:39know how to manage virtual environments.
- 5:01:42But UI can do all of that and you can do
- 5:01:45it much faster with just a few simple
- 5:01:48commands. So, I won't go into all of the
- 5:01:50details as to why it's so awesome. You
- 5:01:52can read more about this, what it does,
- 5:01:55but I'm just I'm just going to show you.
- 5:01:56And if you want to learn more, they I
- 5:01:58even have an entire video on Yui on my
- 5:02:00channel. And you can also in the
- 5:02:02handbook check why it's so awesome and
- 5:02:05what you can do with it. But let me
- 5:02:07scroll down. I'm going to go to
- 5:02:09installing UVI. So this is what I want
- 5:02:11you to do right now. So on Mac or Linux,
- 5:02:14you can use a curl command and you can
- 5:02:16actually open this up in a terminal. So
- 5:02:18you can copy this and then uh create
- 5:02:20open up a terminal session and just plug
- 5:02:23that in and run it. And on Windows you
- 5:02:26can do it via the PowerShell. So after
- 5:02:29uh instart restart your terminal and now
- 5:02:31here's what you can do with UV. So first
- 5:02:35of all it can help you to go all the way
- 5:02:38from starting a project to creating
- 5:02:40environments to managing packages and to
- 5:02:43even managing versions of Python and
- 5:02:45running scripts. So let me show you uh
- 5:02:48if you have UV now installed and let's
- 5:02:51see let me open up another terminal. you
- 5:02:54know, you can check if it's installed
- 5:02:55correctly by simply doing UV and then it
- 5:02:58should not give you an error, but it
- 5:02:59should give you all of the things that
- 5:03:01you can do with it. If you go, let's
- 5:03:03see, UV Python, you can also just go to
- 5:03:07the official website. So, they have a
- 5:03:09whole bunch of documentation that you
- 5:03:11can go through as well. But as with
- 5:03:13everything in this course, I'm going to
- 5:03:15show you the only thing that you need to
- 5:03:16only things that you need to know right
- 5:03:17now. So all the way back to the
- 5:03:20beginning. If we go to our project
- 5:03:23again, project folder and let's say I
- 5:03:26want to start a new project. I can even
- 5:03:28do that with UI and it's also going to
- 5:03:30allow me to set up a some boilerplate
- 5:03:33that I can use. So I don't have to
- 5:03:35create the same files over and over
- 5:03:36again. So let me show you how to do it.
- 5:03:38I can come in here and then I can go new
- 5:03:41terminal at folder. Again, you can do
- 5:03:43this on Windows and on Mac. And I can do
- 5:03:46UV in it as a starting point. And then
- 5:03:48say, let's say my new project. And what
- 5:03:52you'll find is now it will create this
- 5:03:53project. And in here, there is already a
- 5:03:55bunch of information, already a bunch of
- 5:03:57files. So now what I can do, I can do cd
- 5:03:59into my project. So now we're in this
- 5:04:01folder. And then I can open up, I do
- 5:04:04code, and I do dot. So now I open up
- 5:04:07this project in here. I say I trust it.
- 5:04:10And now you can see that out of the box
- 5:04:12we already have a bunch of files in
- 5:04:14here. So we have a git ignore file which
- 5:04:16is very minimal. I still recommend using
- 5:04:18the one that I shared from the resource
- 5:04:19hub. It puts a python version in here.
- 5:04:21You have a simple main.py file uh that
- 5:04:24you can use to start working in. We have
- 5:04:26a piprotoml in here. And we have a
- 5:04:28readme file. And this piprotoml file is
- 5:04:32is a really interesting file. And next
- 5:04:35uh before I showed you how you can use a
- 5:04:37requirements.txt, txt right where you
- 5:04:39can keep track of everything that you
- 5:04:41installed. So if you go over here to the
- 5:04:42getting started was the packages and pip
- 5:04:45scrolling all the way down. So we went
- 5:04:47through a look we can have a
- 5:04:49requirements.txt or an environment and
- 5:04:51then we can do a pip freeze and it will
- 5:04:53create a snapshot like this and then we
- 5:04:56can install that. Now the tricky thing
- 5:04:58is that every time you install something
- 5:04:59you manually have to make sure to freeze
- 5:05:02it and pip freezes also it adds
- 5:05:06everything in all the packages and also
- 5:05:08all of the dependencies. So it can
- 5:05:09quickly get messy. This is something
- 5:05:10that has always annoyed me about using
- 5:05:13pip and working with Python. But let's
- 5:05:15have a look at how UV handles this. So
- 5:05:18if I come in here and I scroll all the
- 5:05:20way down to okay, we have it installed.
- 5:05:22We're now inside our project. What we
- 5:05:25can now do I can now simply come in here
- 5:05:28and let's say I am working on this
- 5:05:30project and I want to add pandas and I
- 5:05:33want to add numpy. I can do uv at I can
- 5:05:36do pandas I can do numpy and what it
- 5:05:39will do look at what's going on behind
- 5:05:41the scenes. It's first going to install
- 5:05:44everything and it's automatically
- 5:05:46creating a virtual environment and it's
- 5:05:48storing it in the dependencies here as
- 5:05:50well just with one simple command and
- 5:05:52super fast. So now we took care of
- 5:05:55virtual environments of dependencies and
- 5:05:59whenever I want to remove something I
- 5:06:01can do u remove pandas and you can see
- 5:06:04pandas is now gone and I can add it one
- 5:06:06more time uv pandas and it's there again
- 5:06:09and now within here I can simply come in
- 5:06:12here and I can now run this file and it
- 5:06:14will now use the virtual environment
- 5:06:17that is created in here called my new
- 5:06:19project or I should select that. So
- 5:06:21that's one thing you should make sure
- 5:06:22make sure you select it and now we can
- 5:06:24use this in here. So now I can come in
- 5:06:26here and I can import pandas and this
- 5:06:29will now run totally fine. This will not
- 5:06:32give an error. Now if you try this in
- 5:06:33the interactive session it will give an
- 5:06:35error because it will say look we need
- 5:06:37to install the kernel. So that's
- 5:06:39something that you remember right? We
- 5:06:41also need to add yui at ipi kernel. This
- 5:06:45is something you always want to have in
- 5:06:48your project whenever you want to use
- 5:06:49the interactive session. But it's super
- 5:06:51easy to manage and everything is taken
- 5:06:53care of. Now, one of the other awesome
- 5:06:56features of UV is is let's say you add
- 5:07:00this to uh a GitHub repository. So, you
- 5:07:02push this and someone else wants to work
- 5:07:04on this. So, let's say they clone this
- 5:07:06as a fresh repository. We remove this
- 5:07:09and they open up this project completely
- 5:07:12from scratch. UV even even has a
- 5:07:14command. It's called UV sync to come in
- 5:07:17here do UV sync and it will look into
- 5:07:20the project and it will just like
- 5:07:21instantly create everything that's
- 5:07:23needed in order to run over here. So now
- 5:07:26we come back to Python, we can select
- 5:07:28our project and we're good to go again.
- 5:07:31So this is really why you should use UV
- 5:07:34and why it is so awesome. So there's a
- 5:07:37lot more that you can do with it but at
- 5:07:39the most fun fundamental level is you
- 5:07:42can create a project with it. You can
- 5:07:44then use it to uh manage your project
- 5:07:47with the pi project autotoml file and on
- 5:07:49a day-to-day basis this is all you have
- 5:07:51to do. You add packages and you remove
- 5:07:53packages. That's really all that there
- 5:07:55is to it. And you can completely forget
- 5:07:57about pip. You can completely forget
- 5:07:59about like how to set up uh virtual
- 5:08:01environments. Everything will be managed
- 5:08:03in here. So that's why I love using UV
- 5:08:06and why a lot of Python developers are
- 5:08:08adopting this. So as you go through
- 5:08:10tutorials online also from like the big
- 5:08:12firms from OpenAI and Tropic. If you
- 5:08:14look into their tutorials there, they're
- 5:08:16also using UV to like run code and to
- 5:08:18add packages. So that was the
- 5:08:20introduction to UV. And like I've said,
- 5:08:22there is actually a lot more that you
- 5:08:24can learn about it if you go to the
- 5:08:26official documentation, but this is what
- 5:08:28you need to know for now. And then if we
- 5:08:30zoom out a little bit again, right, and
- 5:08:33look at uh all the tools that we've
- 5:08:35learned to use right now, Git and
- 5:08:36GitHub, working with secrets and uh
- 5:08:38within your environment and then also
- 5:08:40using UV in a very short period of time,
- 5:08:43we have covered so much information that
- 5:08:46right now it may feel a little
- 5:08:48overwhelming. Um meaning that as you go
- 5:08:51through as as you go through this with
- 5:08:53me step by step, you can follow along.
- 5:08:55But then if you zoom out and like try to
- 5:08:57understand the bigger picture, you might
- 5:08:59be like, "Oh, it still feels like I need
- 5:09:01to understand how to connect the dots."
- 5:09:03And that's why I created this final uh
- 5:09:06page over here which is a complete
- 5:09:08workflow. And I want you to go through
- 5:09:10this right now as an exercise because
- 5:09:13let's see there's step one all the way
- 5:09:14to let me scroll down all the way to the
- 5:09:18final tips and strategies in there and
- 5:09:21step nine to create a new project to
- 5:09:25install the packages to manage your
- 5:09:26virtual environment and to get it to a
- 5:09:28GitHub repository. Everything is
- 5:09:30explained and repeated one more time and
- 5:09:33this will really bring everything
- 5:09:35together. Also knowing that if you can
- 5:09:37follow this step-by-step page here and
- 5:09:39you successfully do this once, you can
- 5:09:41literally always come back to this page
- 5:09:44and follow it one more time to create
- 5:09:46your new project. And the the setup in
- 5:09:49the beginning is the most annoying part.
- 5:09:51Once you have it set up and you have the
- 5:09:54Visual Studio Code workspace file, so
- 5:09:56you just save save the workspace file.
- 5:09:59Once you have that, it's literally as
- 5:10:01easy as double clicking the file. You
- 5:10:02can go and you just need to push your
- 5:10:04changes to GitHub. But I know like so
- 5:10:06well in the beginning if you don't
- 5:10:08understand this you always feel like you
- 5:10:12have to you have you you're missing lots
- 5:10:14of pieces that connect the dots whenever
- 5:10:16you're following a tutorial online. So
- 5:10:18you'll see someone writing out a Python
- 5:10:21snippet. You understand what it is but
- 5:10:23then you cannot like translate that to
- 5:10:25wait but I'm working on my own project.
- 5:10:27Where do I put this? How do I open that?
- 5:10:29How do we manage that? What is GitHub?
- 5:10:31And this is really really what I wish I
- 5:10:34learned in the beginning because what
- 5:10:35you see right here, the tools, this
- 5:10:37setup, this complete workflow, this is
- 5:10:39the exact process that we use for our
- 5:10:42agency for literally all of our clients
- 5:10:44and these are typically like five figure
- 5:10:46deals. So these come in, clients ask us,
- 5:10:48hey Dave, can you build us this AI
- 5:10:51automation? Can you integrate with our
- 5:10:52CRM and automate our customer support?
- 5:10:54This is the starting point and a lot of
- 5:10:56tutorials and courses on YouTube don't
- 5:10:59show you that because they are just
- 5:11:01working on toy projects and just doing
- 5:11:03it for to create a quick and easy
- 5:11:05tutorial. But I really wanted to give
- 5:11:07you the full playbook to see what it's
- 5:11:09like when you work with Python in the
- 5:11:11real world when you're working on
- 5:11:13serious projects. Congratulations. You
- 5:11:15made it to the end of this course. I
- 5:11:17know this was a big one and really this
- 5:11:20is how I'm feeling for you right now and
- 5:11:22I hope you share that feeling. So let's
- 5:11:24quickly go over what we've learned and
- 5:11:26then let's wrap up this course and show
- 5:11:28you how you can continue your learning
- 5:11:30path and learn all about building AI
- 5:11:32agents. So when you started this course
- 5:11:35you were new to Python, maybe even new
- 5:11:38to programming overall and by now you
- 5:11:41know how to install the Python
- 5:11:43programming language, how to work with
- 5:11:44variables, data types, control flow. We
- 5:11:46looked at organizing your code with
- 5:11:48functions and data structures. Then you
- 5:11:51uh understand right now how to set up
- 5:11:53Python environments and manage
- 5:11:54dependencies. We first saw that how we
- 5:11:56can do that with pip and vans but then
- 5:11:58later I showed you how to do it with UV.
- 5:12:00You know how to use git, GitHub and the
- 5:12:02professional developer tools. And you
- 5:12:04can also connect to APIs, handle errors
- 5:12:06and work with files. You are now no
- 5:12:09longer a beginner. You now have the
- 5:12:11skills to really confidently work with
- 5:12:13Python and tackle real projects. That
- 5:12:16was really my goal with this entire
- 5:12:18video. So you can now go out on your own
- 5:12:20and it doesn't I can guarantee you it
- 5:12:22doesn't matter which video on YouTube
- 5:12:24for example you'll dive into there will
- 5:12:27be no surprises. You'll be able to
- 5:12:29follow along confidently. So
- 5:12:32congratulations. Like I said I'm really
- 5:12:33excited about this that you made it to
- 5:12:35this point and the fact that you are
- 5:12:36still here. You should really be proud
- 5:12:39of yourself because this is a long video
- 5:12:41and there are going to be a lot of
- 5:12:42people watching this video that like
- 5:12:44only watch half an hour, an hour and
- 5:12:47then they think, hm, you know what? This
- 5:12:49is not for me. But you made it all the
- 5:12:51way to the end and I congratulate for
- 5:12:54you for that. You are awesome. Now,
- 5:12:56there's one thing that I'm going to ask
- 5:12:58from you. So, this course is completely
- 5:13:00free. So, if you enjoy if you enjoyed
- 5:13:03it, what my goal with this course is to
- 5:13:05like share my knowledge about Python
- 5:13:07with as many people as possible. And
- 5:13:09now, here's how you can help more people
- 5:13:11discover this course. What I want you to
- 5:13:13do right now, this is the only thing
- 5:13:14that I ask from you is scroll down below
- 5:13:17below this video and please leave a
- 5:13:19comment about your thoughts about this
- 5:13:21course, what you learned, what you are
- 5:13:23going to build next. just make sure that
- 5:13:25you leave a comment. So, because this
- 5:13:27will let the YouTube algorithm know that
- 5:13:29people are interested in this and this
- 5:13:31will really help to push it. Now, while
- 5:13:33you're doing that, also make sure to hit
- 5:13:35the like button and also subscribe to
- 5:13:37the channel like if you're serious about
- 5:13:39learning AI because I'm dropping new
- 5:13:40videos all the time. That's really what
- 5:13:42I ask for you because through that we
- 5:13:44are going to spread this video and we're
- 5:13:46going to push it really far and
- 5:13:48hopefully it will reach a lot of people.
- 5:13:50So, that's all I ask. And then to really
- 5:13:54wrap it up, really this is the last
- 5:13:56thing over here. What's next, right?
- 5:13:58What do we want to do right now? So, if
- 5:14:00you're serious about AI and specifically
- 5:14:02about Genai and you want to learn how to
- 5:14:04build AI agents using the skills that
- 5:14:07you've just learned, I have something
- 5:14:09really cool for you. So, you made it to
- 5:14:11the end. Are you ready to build AI
- 5:14:13agents? when you downloaded the
- 5:14:15resources which by now you should have
- 5:14:17downloaded and if not this is another
- 5:14:19reminder to do it because as a bonus by
- 5:14:22just through downloading the resources
- 5:14:24over here. So you can see download this
- 5:14:26over here. You can plug in zero or any
- 5:14:28tip you want but with zero it's
- 5:14:29completely for free. You download the
- 5:14:31resources and you also get access to the
- 5:14:33data luminina academy and in here I have
- 5:14:36a special surprise for you because if
- 5:14:38you go in here and if you go to the
- 5:14:39courses you'll find the Python course
- 5:14:42over here. If you click on that, you'll
- 5:14:44find bonus videos as well as the
- 5:14:46follow-up course on building AI agents
- 5:14:49and you can access that completely for
- 5:14:51free and you can continue learning here
- 5:14:53inside the data luminina academy. All
- 5:14:55right, and with that we have come
- 5:14:56officially to the end of this full
- 5:14:59Python for beginners course. I hope that
- 5:15:02you found it useful. I'm really glad
- 5:15:04that you are here at the very end which
- 5:15:07shows your commitment again. Now go make
- 5:15:09sure to check out the data luminina
- 5:15:11academy. then I can catch you there and
- 5:15:13you can continue your learning journey.
- 5:15:15And then I hope that you're off to doing
- 5:15:18great things with these skills and
- 5:15:19hopefully you can use them to make the
- 5:15:21world a little bit of a better place and
- 5:15:24we can all navigate this AI revolution
- 5:15:26together because it's super exciting and
- 5:15:28this is only just the kidding.
About this transcript
This page contains the full transcript of Python for AI - Full Beginner Course by Dave Ebbelaar, generated from the public captions YouTube serves with the video. The transcript has 64,485 words across 8,455 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.