YouTube2Text

Python for AI - Full Beginner Course — Transcript

by Dave Ebbelaar · 64,485 words · 8,455 segments · language en · Watch on YouTube

Full transcript

  1. 0:00If you want to learn the Python
  2. 0:01programming language specifically to
  3. 0:03build AI applications, then this video
  4. 0:05is for you. We're going from absolute
  5. 0:07beginner to writing real Python code for
  6. 0:08AI applications all in one video. And
  7. 0:11right now, Python is the language for
  8. 0:13artificial intelligence. So whether you
  9. 0:14want to build your own AI apps, get into
  10. 0:16data science, or simply become more
  11. 0:18valuable in your career, this is one of
  12. 0:20the most in demand skills you can learn
  13. 0:22right now. And now there are already a
  14. 0:24ton of learned Python tutorials and
  15. 0:26courses out there, right? You're
  16. 0:27probably wondering which one should I
  17. 0:29follow and why should I watch this
  18. 0:30video? Well, most of the videos out
  19. 0:32there actually waste your time on a lot
  20. 0:34of stuff that you actually don't need to
  21. 0:36know if you want to use Python
  22. 0:38specifically for AI. So, this video is
  23. 0:40different. We'll start from the basics
  24. 0:42and I'll make sure to explain everything
  25. 0:43step by step so you can follow along.
  26. 0:45Then, I'll teach you all the core
  27. 0:47concepts you need to understand in order
  28. 0:49to learn Python fast. We'll build up in
  29. 0:51complexity, work with data, and create
  30. 0:53reports. And as a final exercise, you're
  31. 0:55going to build your own AI chat
  32. 0:56assistant that can chat with your data.
  33. 0:58My name is Dave Ealar. I'm the founder
  34. 1:00of Datal Lumina, an AI development
  35. 1:01company where we built custom AI
  36. 1:03solutions for clients across many
  37. 1:05industries now. I've been using Python
  38. 1:06almost every single day for over a
  39. 1:08decade, and I already taught this
  40. 1:10language to more than 35,000 students
  41. 1:12worldwide. So, if you're looking to
  42. 1:14learn Python from a professor who only
  43. 1:15teaches, this is not the course for you.
  44. 1:17Everything that we'll be doing in this
  45. 1:18course is practical, battle tested, and
  46. 1:21it's based on real work in the AI field.
  47. 1:23The stuff companies and clients are
  48. 1:25paying for right now. And look, it
  49. 1:27doesn't matter what your background is.
  50. 1:28You're never too young, too old, or too
  51. 1:30late to start. If you can follow simple
  52. 1:33explanations and have a bit of
  53. 1:34curiosity, that's important. You can do
  54. 1:36this. So, grab a coffee and take out
  55. 1:38your notes. This is Python for AAI, the
  56. 1:40course I wish I had when I started.
  57. 1:43Let's dive in. All right, so let's get
  58. 1:45started. I am super excited to go
  59. 1:47through this entire course with you and
  60. 1:48to teach you everything that you need to
  61. 1:50know about Python to build AI
  62. 1:51applications. Before getting started and
  63. 1:53installing Python, let me give you a
  64. 1:55quick overview in 30 seconds how to get
  65. 1:57the most out of this course. What you
  66. 1:58are looking at right now is the handbook
  67. 2:00which I will make available for you link
  68. 2:03in the description. It's hosted under
  69. 2:04python.dataluminina.com.
  70. 2:06All of the other information, links,
  71. 2:07codelocks that you need will be in here.
  72. 2:10So use that to your advantage. Now,
  73. 2:12whenever I go too fast, you can go back
  74. 2:14here, find more information. And
  75. 2:16whenever you feel like I'm going too
  76. 2:17slow, use the chapters below this video
  77. 2:19to skip ahead or use the speed controls
  78. 2:21below this video to increase the speed
  79. 2:23of the video. And now, what's going to
  80. 2:24make this course different from a lot of
  81. 2:26other Python courses out there beyond
  82. 2:28just the focus on AI. In the beginning,
  83. 2:30we're going to spend a lot of time on
  84. 2:31setting up a professional work
  85. 2:33environment for you. You see, most
  86. 2:35Python tutorials and courses go through
  87. 2:37the Python setup and then they
  88. 2:38immediately jump into writing out
  89. 2:40isolated Python code examples. But what
  90. 2:42I found over the years teaching
  91. 2:44thousands of students this language is
  92. 2:46that in the beginning, writing the code
  93. 2:48itself isn't the hardest. And especially
  94. 2:50nowadays with AI, you can literally ask
  95. 2:52JPT to come up with anything and you can
  96. 2:55plug it into your code editor. What you
  97. 2:56need to focus on in the beginning is
  98. 2:58having a solid understanding of the
  99. 3:00tools you use, how to set up your
  100. 3:02environment, how to manage package and
  101. 3:03dependencies and how you can create
  102. 3:05projects so that whenever you go out in
  103. 3:07the real world beyond this course and
  104. 3:09you want to build something or follow a
  105. 3:10course or tutorial, you know exactly
  106. 3:12what it is that you need to do and
  107. 3:13you'll have a professional coding setup
  108. 3:15exactly the same as what I am using
  109. 3:17right now and what you would actually
  110. 3:19use when you get a job and work with
  111. 3:20Python in the real world. So just know
  112. 3:22that we're going to spend quite some
  113. 3:24time there in the beginning. That's the
  114. 3:25whole getting started chapter and it's
  115. 3:27there in the beginning for a reason. You
  116. 3:29don't want to skip this if you're not
  117. 3:30familiar with these concepts. So, we'll
  118. 3:32get into all of the installations,
  119. 3:34setups, and configurations that you need
  120. 3:36in order to work professionally with
  121. 3:37Python. Then, in the Python basics,
  122. 3:39that's where we actually get into the
  123. 3:41programming language. And now, even if
  124. 3:42you already have some coding skills or
  125. 3:44you're coming from a different
  126. 3:45programming language, I still highly
  127. 3:46recommend to go through this entire
  128. 3:48getting started chapter with me because
  129. 3:50I will show you the exact setup that I
  130. 3:52am using right now so that if you follow
  131. 3:53through with the course, everything that
  132. 3:55you see will be exactly the same on my
  133. 3:57screen as well as on your screen. All
  134. 3:58right, so let's get started. The first
  135. 4:01thing that we are going to do is install
  136. 4:04Python on your machine. So following the
  137. 4:06handbook, I am here in the section
  138. 4:08installing Python to get it up and
  139. 4:10running on your computer. So, I'm first
  140. 4:12going to walk through the Windows setup.
  141. 4:13If you're on Mac, you can use the
  142. 4:15timestamps below to skip ahead. So, the
  143. 4:17first thing that you need to do is you
  144. 4:19can go to python.org/d downloads or
  145. 4:22follow the link over here. Then you will
  146. 4:24find this page where you can simply
  147. 4:27click on download python. And then once
  148. 4:29that's uh completely done, you can
  149. 4:31doubleclick on it to start the
  150. 4:33installer. Now, here is a very important
  151. 4:36thing. When you go through the
  152. 4:37installer, you should check the
  153. 4:39following box. When it asks, should you
  154. 4:41add Python to the path? You should check
  155. 4:43mark that. It will look somewhat like
  156. 4:46this. So, you can see it over here. Let
  157. 4:47me add a little bit smaller for you.
  158. 4:48Now, this is an older version of Python,
  159. 4:50but the setup will look something like
  160. 4:52this. And you should add Python to your
  161. 4:54path. Then, you can just follow through
  162. 4:56with the installer. Do not customize
  163. 4:58anything unless you know what you're
  164. 5:00doing. All right. And that's it for the
  165. 5:01quick installation. Super easy to
  166. 5:03follow. So now next in this video I will
  167. 5:04show you how to do this on Mac but
  168. 5:05you're on Windows. So make sure to skip
  169. 5:07to the next chapter where we're going to
  170. 5:08install your code editor. All right. So
  171. 5:10now I'll show you how you can install
  172. 5:12Python if you are on Mac. And the first
  173. 5:14thing that we need to check here is
  174. 5:16check whether Python is maybe already
  175. 5:17installed on your system because for a
  176. 5:19lot of Mac systems this is already the
  177. 5:21case. So what we are going to do is
  178. 5:23we're going to open up the terminal. And
  179. 5:25don't worry if you've never used the
  180. 5:26terminal. We just use it to type in a
  181. 5:28command and it's not that scary. So what
  182. 5:30we can do is we can open up Spotlight.
  183. 5:32And you can do that by hitting command
  184. 5:34and spacebar. Then this will show up and
  185. 5:37you can type in terminal. So if I open
  186. 5:39that up, you'll see this console coming
  187. 5:42up over here. This is a terminal where
  188. 5:45we can run commands. And all you need to
  189. 5:47do right now is come over here to the
  190. 5:49documentation and you should type in
  191. 5:50Python 3 space- version. So you can type
  192. 5:54it out or you can copy paste it like I
  193. 5:56do over here. Come to the terminal and
  194. 5:58then I'm going to paste that in with
  195. 6:00command V. And what I can now do is I
  196. 6:02can hit enter. Now you can see on my Mac
  197. 6:04it is already installed because it's
  198. 6:06showing me a Python version meaning it's
  199. 6:08installed. If you also see a version
  200. 6:11over here that also means Python is
  201. 6:13installed. If you get an error over here
  202. 6:15mentioning like look Python is not
  203. 6:16available or it's not recognized then
  204. 6:18you still need to install Python and you
  205. 6:20can continue with the rest of the
  206. 6:21instructions in here. So in case you do
  207. 6:23need to install it you can scroll down
  208. 6:24over here on this install Mac page and
  209. 6:26you can go to python.org/d downloads
  210. 6:28which we have open over here. You can
  211. 6:30click the big download button. It
  212. 6:32doesn't matter if it's a different
  213. 6:33version. If you watch this in the
  214. 6:35future, it will be different. So, you
  215. 6:36click the download button and then over
  216. 6:38here it will start to download. So, then
  217. 6:41while you wait for that to finish, you
  218. 6:43can go to your download folders. Simply
  219. 6:45doubleclick on it and install Python
  220. 6:48like any other app. All right.
  221. 6:49Congratulations on installing Python on
  222. 6:52your machine. Now, the next step is to
  223. 6:54install an application that actually
  224. 6:56allows us to work with the Python
  225. 6:57programming language. So, we are going
  226. 6:59to install my favorite code editor to
  227. 7:01work with the Python programming
  228. 7:02language, and that is Visual Studio
  229. 7:04Code. And that is really all you need.
  230. 7:07I've been using this application for the
  231. 7:08past 5 years already. I love it. It's
  232. 7:11completely free. It's super extensible,
  233. 7:12and it's really it got it's got
  234. 7:14everything that you need to
  235. 7:15professionally work with the Python
  236. 7:17programming language. And nowadays,
  237. 7:19there are, of course, a lot of AI
  238. 7:20assisted code editors out there. Cursor
  239. 7:22being one of the most popular ones right
  240. 7:24now. The good thing is that everything
  241. 7:25that you do in setup within Visual
  242. 7:27Studio Code can also be done exactly the
  243. 7:29same and imported within Cursor because
  244. 7:31cursor is built on top of VS Code. So
  245. 7:34let's get into how to set up Visual
  246. 7:36Studio Code. So I come over here to the
  247. 7:38install VS Code tab and again depending
  248. 7:40on whether you're on Windows or Mac OS,
  249. 7:43it's a little bit different, but you can
  250. 7:44just go to the website and this big
  251. 7:46download button over here, it will be
  252. 7:48dynamic for the operating system that
  253. 7:50you're that you're on. So for me, it
  254. 7:51will say Mac. for you. If you're on
  255. 7:53Windows, it will say Windows. So again,
  256. 7:55download it. It will go to your download
  257. 7:57folder. Click on it and follow the
  258. 7:59installation in there. One more time.
  259. 8:02It's important that you add it to your
  260. 8:04path on Windows. And then you just click
  261. 8:06install, finish when done. Process is
  262. 8:08exactly the same for Mac OS. You can
  263. 8:11keep it in your doc. There might be some
  264. 8:13security questions that pop up where you
  265. 8:15need to give it permission. So just
  266. 8:17follow that. It's completely safe. The
  267. 8:18application is for Microsoft. And then
  268. 8:21we can go and verify the installation.
  269. 8:24So what we can do right now is we're
  270. 8:26going to open it. And there we go. So
  271. 8:28this is the first screen that I see
  272. 8:30right now with versions updates, a
  273. 8:32welcome screen, and now since Visual
  274. 8:35Studio Code is so extensible and it it
  275. 8:37can work with a lot of programming
  276. 8:38languages out of the box, there's not
  277. 8:40much there. So, what we're going to do
  278. 8:42right now is I'm going to share my exact
  279. 8:45setup with all the extensions and
  280. 8:47settings that I use to work on all of my
  281. 8:50Python projects that I've been doing for
  282. 8:52the past 5 years. This is really a
  283. 8:54professionalgrade environment that we're
  284. 8:56going to set up. And this is so so
  285. 8:58crucial to spend a little bit of time
  286. 8:59here to understand this tool because
  287. 9:02what you'll find on this journey of
  288. 9:05learning Python is that actually the act
  289. 9:08of writing code, writing out the like
  290. 9:11line by line sentences and the
  291. 9:12characters like you will quickly get a
  292. 9:14hang of that and AI can work really well
  293. 9:17with that. AI can help you as well, but
  294. 9:19you need to be able to know where to
  295. 9:20find it, how to set it up, how to create
  296. 9:22a new project, how to add new things to
  297. 9:24it, how to run code, how to debug code.
  298. 9:27So, that's also going to be a a big
  299. 9:29difference between a lot of the other
  300. 9:31Python tutorials and courses that you'll
  301. 9:33find out there. And I know that in the
  302. 9:35beginning when I was learning Python,
  303. 9:36this was so annoying to me where always,
  304. 9:38yeah, I would get it on like a single
  305. 9:40file. I could follow a tutorial, but
  306. 9:42then when I was on my own project,
  307. 9:44things looked different and I just
  308. 9:45didn't have the full system and it just
  309. 9:47didn't understand the full process. So
  310. 9:49that's what we're going to spend some
  311. 9:50time on right now. Okay. And the first
  312. 9:51thing that we're going to do is we're
  313. 9:52going to install the Python extension.
  314. 9:54So I can click on the link over here to
  315. 9:57see where this is going. But we can also
  316. 9:59do this directly from Visual Studio
  317. 10:01Code. So what I'm going to do is we're
  318. 10:03going to the extensions tab and then
  319. 10:05we're going to search for Python. So let
  320. 10:07me walk you through that. Here is Visual
  321. 10:09Studio Code completely empty. You can
  322. 10:11see the extensions over here. So, it's
  323. 10:13this little icon. There's also a
  324. 10:15keyboard shortcut to it. And you can see
  325. 10:17it's already recommending something to
  326. 10:19me. Python over here. But in case this
  327. 10:21is not there for you, you can type in
  328. 10:23Python. And then it should show you
  329. 10:25exactly what's over here. Python. It
  330. 10:27should be from Microsoft. You see the
  331. 10:29blue check mark over here. You can click
  332. 10:31on it or directly install here or over
  333. 10:33here. So what this is going to do, this
  334. 10:35is going to behind the scenes install
  335. 10:37the Python extension so that when we
  336. 10:39work with Python files, our editor, our
  337. 10:42code editor can recognize it. So this is
  338. 10:44an essential extension that we need.
  339. 10:46Okay, so that was the Python extension
  340. 10:48and now we're going to change a quick
  341. 10:50setting. We're going to use this later.
  342. 10:52Don't worry about it for now. All you
  343. 10:53need to do is go to the settings of
  344. 10:56Visual Studio Code and you should copy
  345. 10:58paste this or search for this. So Python
  346. 11:00terminal execute in file directory. This
  347. 11:02is really useful for later down the
  348. 11:04line. So I can come in here. I go to
  349. 11:06settings. And then you can search for
  350. 11:08this. And you want to make sure that
  351. 11:09this is checked on a fresh new install.
  352. 11:12It's like this. And you want to click
  353. 11:13this. And that's it. You can just X out
  354. 11:15of it. It will automatically save. So
  355. 11:17this will make sure that later when
  356. 11:18we're going to execute Python files, the
  357. 11:20editor will execute the file from the
  358. 11:22directory instead of the workspace
  359. 11:23route. So when we're going to reference
  360. 11:25files, it will be a lot easier. All
  361. 11:26right. Then next, there are two more
  362. 11:28extensions that I recommend to install.
  363. 11:30The first one is pylance and the other
  364. 11:32one is Jupiter. So let's start with P
  365. 11:34lens first. We do exactly the same
  366. 11:36process. We come in here. We search for
  367. 11:37pilance. We see it pop up over here also
  368. 11:40from Microsoft. And you can see it's
  369. 11:42it's actually already installed by
  370. 11:44installing Python. But you can double
  371. 11:46check this. So make sure that if you go
  372. 11:48to Pilance it it if it says install you
  373. 11:51should click it. And then we go to
  374. 11:53Jupiter which is something we are going
  375. 11:55to heavily use throughout this course
  376. 11:57but I will show that later. For now, we
  377. 11:59can just click install and then we
  378. 12:02should be good. This takes a couple of
  379. 12:04seconds. Now, coming back to the
  380. 12:07instructions over here. What we're going
  381. 12:09to do right now is we're going to
  382. 12:10customize the code editor. And this is
  383. 12:13completely optional. This is not going
  384. 12:15to change anything about how the code
  385. 12:17editor works, but I like to set up uh my
  386. 12:19environment in a specific way. So, for
  387. 12:22the past years, I've been using this uh
  388. 12:25theme and I really like it, the Atom one
  389. 12:27dark. So, let me show you how to install
  390. 12:28that and what that looks like. And you
  391. 12:30can also search for other teams that you
  392. 12:32like. So, this is really just like the
  393. 12:34coloring, the fonts. You'll see it in a
  394. 12:36bit. So, I can search for Atom one dark
  395. 12:38team. Hit install. Trust publisher and
  396. 12:40install. There we go. And it
  397. 12:42automatically right now it already sets
  398. 12:44the coloring. You saw it, right? So,
  399. 12:46yeah, you can see right over here it now
  400. 12:48asked, do you want dark modern or Adam
  401. 12:51one dark? So, I set this over here. You
  402. 12:53can also click on set the color team. So
  403. 12:55that's now installed. You can also at
  404. 12:58any point come all the way to the bottom
  405. 13:01over here where you see the little gear
  406. 13:03icon and you can see themes over here
  407. 13:05and there you can see the color theme
  408. 13:07and the file icon. So if I click on this
  409. 13:09the color theme you can see everything
  410. 13:11that is currently installed. So if you
  411. 13:14for example let's click on the Kimi dark
  412. 13:16you can see this is a very different
  413. 13:18look to what we had right. So this is
  414. 13:20for you a way to go through it and to
  415. 13:23pick a theme that you like. All right.
  416. 13:24Now, there's one more setting, the three
  417. 13:26indentation, but we'll actually get back
  418. 13:27to that in a couple of minutes because
  419. 13:29then I can actually show you what it
  420. 13:31does. So, for now, we are going to go to
  421. 13:33the next section, and that is creating
  422. 13:35projects. One of the most important
  423. 13:38things in the beginning to fully
  424. 13:40understand because this is really the
  425. 13:43point where look, you see examples
  426. 13:45online, you see me go through this
  427. 13:47tutorial, but now you're in the real
  428. 13:48world and you have an idea, you want to
  429. 13:50try some. Where do you start? Right? We
  430. 13:52have Python installed. We have a code
  431. 13:54editor, but how does it work? How where
  432. 13:56are the projects? So, let's set that up
  433. 13:58right now. So, what I recommend you to
  434. 14:01do is creating a folder somewhere on
  435. 14:04your computer. Doesn't matter if it's in
  436. 14:06your documents, in your home directory,
  437. 14:08any type of place where we are going to
  438. 14:10store all of our Python projects. So,
  439. 14:12for the sake of demonstration, I'm going
  440. 14:14to create one on our data luminina drive
  441. 14:16over here. So, I'm going to call it
  442. 14:18Python projects. All right. And now what
  443. 14:21I want you to do next is inside this
  444. 14:23folder. So this will be the master
  445. 14:24folder. And in here we can do we can
  446. 14:26create all kinds of folders for all the
  447. 14:28projects. So first we're going to create
  448. 14:30a folder for this course and we're going
  449. 14:32to call it Python for AI. But whenever
  450. 14:34you have another ID you want to try
  451. 14:36something else I invite you to do that
  452. 14:39in that same folder and follow a similar
  453. 14:41structure and a similar setup so that
  454. 14:43you work very organized and you always
  455. 14:45know where all of your Python projects
  456. 14:47are. Now for the main folder, it doesn't
  457. 14:50really matter what type of naming
  458. 14:51convention you use, whether you use
  459. 14:53capital letters or not. But for the
  460. 14:55project folders itself, I recommend to
  461. 14:57use all lowercase and dashes. And why
  462. 15:00this is the case, this is actually
  463. 15:01called kebab case. And this is going to
  464. 15:04match how projects are going to appear
  465. 15:06on GitHub. This is something we'll cover
  466. 15:08later. But this is just a best practice
  467. 15:10that I always do and I recommend you to
  468. 15:12do as well. So what it then looks like
  469. 15:14if I come in here Python projects I'm
  470. 15:16going to create a new folder and I'm
  471. 15:18going to plug in Python for AI all
  472. 15:20lowerase and dashes using the kebab
  473. 15:23case. So now we have that created. What
  474. 15:25we can do right now is now from Visual
  475. 15:28Studio Code we can open up this folder.
  476. 15:30So let me come back over here. This is
  477. 15:32what your Visual Studio Code should look
  478. 15:34like right now. If you go over here to
  479. 15:36the explorer. So before we were
  480. 15:38installing all of the extensions. Now we
  481. 15:40can go to the explorer and you can see
  482. 15:42this is empty. You have not opened a
  483. 15:44folder yet. So we can click on that
  484. 15:46click on open a folder and then we go to
  485. 15:48the place where we just created our
  486. 15:50Python projects and then Python 4AI. So
  487. 15:52depending whether you're on Mac, Windows
  488. 15:54is a little bit different but make sure
  489. 15:55to navigate through the explorer or the
  490. 15:58finder to this folder. And then what you
  491. 16:00can do right here is you can click on
  492. 16:01open. And now what you can see is now
  493. 16:05this folder is opening. And the first
  494. 16:07time you do this, Visual Studio Code
  495. 16:09will ask, do you trust the outers of
  496. 16:10this file? We created it. So yes, should
  497. 16:12be good. Okay. So now we have this empty
  498. 16:15screen over here. And now there's one
  499. 16:17more important step that you need to do
  500. 16:19for every project that a lot of
  501. 16:20beginners forget. And that is creating a
  502. 16:23workspace in Visual Studio Code. Because
  503. 16:26what we do right now, we open up a
  504. 16:28folder and now we need to save that
  505. 16:30folder and everything in there as a
  506. 16:31workspace. A workspace is Visual Studios
  507. 16:34Code way of defining projects. And why
  508. 16:36we want to do that is in this way we
  509. 16:38create a single file that we can
  510. 16:40doubleclick it will open and everything
  511. 16:42will be there. So when you're working on
  512. 16:44something, you hit X, you shut down your
  513. 16:47computer, you restart it, you can
  514. 16:48doubleclick on one file and everything
  515. 16:51will be there exactly how you left it.
  516. 16:54That's what the workspace is about. It's
  517. 16:56like a bookmark. It remembers
  518. 16:57everything. So now what you want to do
  519. 16:58is you want to save the workspace. So
  520. 17:01within Visual Studio Code, we go over
  521. 17:03here, we go to file and then over here
  522. 17:05you should see save workspace as. So we
  523. 17:08can click on this and it will by default
  524. 17:10open up the the explorer or the finder
  525. 17:13in the same folder that you are
  526. 17:15currently in and it will also give it a
  527. 17:17default name. It will say save as
  528. 17:19Python4i.code
  529. 17:21test-workspace. This is the VS code file
  530. 17:24extension that you need. So if you set
  531. 17:26it up like this, there's no need to
  532. 17:28change anything about this. So this
  533. 17:29folder is already selected and I can
  534. 17:31just hit save. So what you now see is
  535. 17:33you should now see this workspace folder
  536. 17:36show up over here and we can also
  537. 17:38confirm that by going over to the finder
  538. 17:41or explorer and in the folder we now see
  539. 17:44the following workspace. Right. So now
  540. 17:45we can test this if this works correctly
  541. 17:48because what we can do is we can close
  542. 17:49out of video code. So now it's gone. We
  543. 17:51can even quit it. And now we can go to
  544. 17:53the finder Python projects Python for
  545. 17:54AAI and then we double click it. And
  546. 17:57there we go. We are back in our folder
  547. 17:59now with the workspace file in here. All
  548. 18:01right. So now with the workspace set up,
  549. 18:03it's time to create your first Python
  550. 18:05file. What we're going to do is we're
  551. 18:07going to create a new file and call it
  552. 18:08hello.py. So let's come back to Visual
  553. 18:12Studio Code. And what we can do over
  554. 18:13here is we can either use the buttons
  555. 18:16over here. So you can click a new file
  556. 18:17over here, but I can also rightclick and
  557. 18:19say new file. So let's come in here and
  558. 18:22let's type in hello.py. Now please be
  559. 18:24mindful of the extension that you have
  560. 18:26over here. So right now you can see that
  561. 18:29here if I type in hello.py you will see
  562. 18:31that Visual Studio Code displays the
  563. 18:33Python logo over here. So it recognizes
  564. 18:36that this is a Python file. Now this is
  565. 18:39very important. It doesn't matter what
  566. 18:41name you give it in here. That doesn't
  567. 18:43matter. But the extension should be.py
  568. 18:45if you want to work with Python files.
  569. 18:48Now you can also uh for example do a txt
  570. 18:50to do a text file or you can do a
  571. 18:52markdown file or you could do a
  572. 18:55JavaScript file. Visual Studio Code is
  573. 18:57flexible enough to understand that based
  574. 19:00on the file extension. So for now do
  575. 19:02hello.py and hit enter. Now we can open
  576. 19:05up this file in our editor and see it
  577. 19:07pop up over here. So on the left you
  578. 19:09have your files and now you can see the
  579. 19:10file over here hello.py. So this is
  580. 19:13where we can now actually start to write
  581. 19:15Python code. And the first thing that I
  582. 19:16want you to do is write a simple print
  583. 19:19statement similar to how we did that in
  584. 19:21the terminal at the beginning of this
  585. 19:23tutorial. Right? Remember? So we do
  586. 19:25print and then we do an opening bracket
  587. 19:28and Visual Studio Code will
  588. 19:30automatically just by hitting the
  589. 19:31opening bracket will already create the
  590. 19:33closing bracket. You can also see how we
  591. 19:35have different colors in there. This is
  592. 19:37all possible because of the Python
  593. 19:38extension and pyance that we have
  594. 19:40installed. Then we can do double quotes
  595. 19:42and we type in hello world and an
  596. 19:44exclamation mark. So we now have pretty
  597. 19:46much the most basic Python script that
  598. 19:48you can think of only with a simple
  599. 19:51print statement. So let's actually see
  600. 19:53how we can run this because in the
  601. 19:55terminal we would type this out and we
  602. 19:57would hit enter right but if I hit enter
  603. 19:59right now I will simply go to the next
  604. 20:01line similar to what you have in word or
  605. 20:04any other text setter and I can write
  606. 20:06more print statements. So now let's
  607. 20:08cover how we can run this file over
  608. 20:10here. And before running your Python
  609. 20:12file, there's one thing that you should
  610. 20:14always do at the beginning of every
  611. 20:15project. And this is also one of those
  612. 20:17things that in the beginning you often
  613. 20:19forget it. You just have to double check
  614. 20:20it. But don't worry throughout this
  615. 20:21course. We will cover it lots of times
  616. 20:23so you'll remember. And that is setting
  617. 20:26the correct Python installation because
  618. 20:28we have installed Python on our machine.
  619. 20:31But we also need to tell Visual Studio
  620. 20:33Code which Python version to use. Now
  621. 20:36out of the box generally nine out of 10
  622. 20:38times this in right now automatically
  623. 20:41goes correct because you can see right
  624. 20:44now here in the bottom screen you can
  625. 20:45see 3.13.5.
  626. 20:48So right now you can see it is using
  627. 20:50this Python installation on my machine.
  628. 20:52If I click on this you can see I have
  629. 20:54more Python installations over here. If
  630. 20:57you use virtual environments, something
  631. 20:59we will cover later in this program,
  632. 21:00which is a core skill that you need to
  633. 21:02understand, you'll end up with multiple
  634. 21:05Python versions that you can select. So,
  635. 21:07for now, it's important that we select
  636. 21:10the default one. If you've just
  637. 21:11installed Python, there's likely only
  638. 21:13just one version here, but make sure
  639. 21:15that you refer to the Python
  640. 21:17installation that you installed at the
  641. 21:19beginning of this session. So I click on
  642. 21:21this and now Visual Studio Code knows
  643. 21:23okay if I want to run this this Python
  644. 21:25file here is the installation that I
  645. 21:27need to use. And now in order to
  646. 21:29actually run the Python file and execute
  647. 21:31the code what you need to do is you go
  648. 21:32to the top right corner over here and
  649. 21:34click on the play button. So what this
  650. 21:35will do is this will open up the
  651. 21:37terminal window within Visual Studio
  652. 21:39Code and it will point to the file on
  653. 21:42our system. So you can see the full pot
  654. 21:44over here and then it will use your
  655. 21:46Python installation to run this. And you
  656. 21:48can now see that when we run this, you
  657. 21:50first see the line over here. Where is
  658. 21:52the Python file located? And then you
  659. 21:54can see hello world over here. Now I can
  660. 21:56simply close this out. I can also click
  661. 21:58in here and I can do run Python file in
  662. 22:00dedicated terminal. You'll find that
  663. 22:02this is exactly the same. It create it
  664. 22:04will create a new terminal session. The
  665. 22:06easiest way for now is just to remember
  666. 22:08when I want to run the script, I can
  667. 22:10click on this. And now what is actually
  668. 22:12going on here behind the scenes is
  669. 22:13something I want to explain. Because
  670. 22:15when we click on this play button, what
  671. 22:17our editor does for us, it executes a
  672. 22:20command. But if we were to not use an
  673. 22:23editor like this and simply run this
  674. 22:24file via the terminal, how would we do
  675. 22:26it? So let's show uh let's have a look
  676. 22:29at what what is actually happening. So
  677. 22:31right now we can also execute this file
  678. 22:34by saying look we want to use Python and
  679. 22:37then we point to our hello.py pi file
  680. 22:39and we simply run that. So you can see
  681. 22:42that right now this is also executing
  682. 22:44this file and it's printing this hello
  683. 22:46world in here. So if we now close this
  684. 22:49out and one more time click on this. So
  685. 22:51let's have a look at what's going on
  686. 22:52here in the terminal because it's a lot
  687. 22:53of information but all that there is to
  688. 22:55it is first of all it says look we're in
  689. 22:58this current folder. So we go within our
  690. 23:00terminal, we go into this folder where
  691. 23:02we were currently at. Then we point to
  692. 23:04the specific Python location and before
  693. 23:07in the example I just did Python, right?
  694. 23:09But in the terminal when we do this via
  695. 23:11editor, it's explicit. So it completely
  696. 23:13says, look, we're using this version of
  697. 23:15Python. And then we point to the Python
  698. 23:17path. So here you can see even though
  699. 23:19let's see, it's cut off a little bit,
  700. 23:20but you can see it's pointing to this
  701. 23:22hello.py file over here. So that is just
  702. 23:26what you should know about what's going
  703. 23:28on behind the scenes when you click on
  704. 23:29that play button because you could also
  705. 23:32do this within the terminal without
  706. 23:34needing Visual Studio Code and you can
  707. 23:36do it by simply checking look I have the
  708. 23:39Python command this is available I can
  709. 23:41do that and I can quit out of that and I
  710. 23:43can use that Python command to reference
  711. 23:45certain files you need to write out the
  712. 23:47entire file path and now because we're
  713. 23:49in this folder already we can execute
  714. 23:52it. So as you are learning the Python
  715. 23:54programming language, this is really a
  716. 23:55fundamental skill and an idea that you
  717. 23:57need to understand. But luckily when we
  718. 23:58are using an editor, we can just hit the
  719. 24:00play button. So we don't have to do it,
  720. 24:02but we need to understand what's going
  721. 24:04on behind the scenes. There's also a
  722. 24:05default keyboard shortcut that you can
  723. 24:07use and that's Ctrl F5 or CMD F5 on Mac.
  724. 24:11I actually like to change this. So let's
  725. 24:14do that right now to see. You can set it
  726. 24:16to anything you want. So if I come over
  727. 24:17here to the settings and then go to
  728. 24:19keyart keyboard shortcuts and then type
  729. 24:22in run python you can find the python
  730. 24:24run python file over here and then under
  731. 24:26the key binding column if I click in
  732. 24:28here I can now plug in any keyboard
  733. 24:29combination that I want. I actually like
  734. 24:31to do cmd enter and then overwrite that.
  735. 24:34There are already commands in Visual
  736. 24:36Studio Code that have that as well but I
  737. 24:38find if that you have it like this I can
  738. 24:40simply now hit cmd enter or control
  739. 24:43enter if you're on Windows and I can now
  740. 24:45run this. If this is causing any issues
  741. 24:47for you or you want another shortcut,
  742. 24:49feel free to change it or just use the
  743. 24:51play button over here. One more thing
  744. 24:52that you should also know right now is
  745. 24:55that if you click on this play button or
  746. 24:56run the code, this terminal will open up
  747. 24:59over here. And this terminal that we're
  748. 25:01seeing right here is exactly the same as
  749. 25:04the terminal we used before, right? So
  750. 25:06here on Mac you have the terminal, on
  751. 25:08Windows you have the Windows terminal.
  752. 25:09So I can do here python- version and it
  753. 25:13will show the Python version that I'm
  754. 25:14using. In a similar way, I can do that
  755. 25:16here as well. So I can do python-
  756. 25:18version and I can also run that here. So
  757. 25:21that's something important to keep in
  758. 25:22mind. Whenever we're working with Python
  759. 25:24code over here and we send it to the
  760. 25:26terminal, all the things that we can do
  761. 25:28in a regular terminal, we can also do
  762. 25:31that here in here right from Visual
  763. 25:33Studio Code. So we don't have to leave
  764. 25:35it when later we have to install certain
  765. 25:38things. So generally, especially in the
  766. 25:39beginning, you actually don't have to
  767. 25:41deal a lot with the terminal. you just
  768. 25:43close it, delete it and then whenever we
  769. 25:45need to run something, it will open and
  770. 25:48then occasionally we need to install
  771. 25:50some things or tweak some settings and
  772. 25:52that's where the terminal will come into
  773. 25:53play. And whenever the terminal is gone,
  774. 25:55so for example, you X out of it or you
  775. 25:57lose it. You can also go always go to
  776. 25:59the top uh menu bar, click on terminal
  777. 26:01and then for example do new terminal.
  778. 26:03Now it will show up again. There's also
  779. 26:05a default command. It's either cmd or
  780. 26:08controll J. So I can hit that and that
  781. 26:10will just like it will not close it but
  782. 26:11it will hide it. So now if I come in
  783. 26:13here and I do python d- version one more
  784. 26:16time I show it I do uh command j I can
  785. 26:19hide it and then here you see I have the
  786. 26:21exact same terminal session still open.
  787. 26:24All right so now as an exercise you can
  788. 26:26give this a try and experiment with some
  789. 26:28different print statements just to get a
  790. 26:30feel for what it's like writing code
  791. 26:32hitting command or control enter and
  792. 26:35sending it to the terminal. So coming
  793. 26:37back over here every print line that we
  794. 26:39have in here will be a new print. So I
  795. 26:41can come in here and I say print and
  796. 26:43then I say I am learning AI. And now
  797. 26:47when I run this you'll find that first
  798. 26:49you see hello world and then you see I
  799. 26:51am learning AI. So whenever you are
  800. 26:53writing Python scripts you should
  801. 26:55remember that code gets executed from
  802. 26:57top to bottom and from left to right.
  803. 27:00It's pretty much exactly the same to how
  804. 27:01you read a book. All right. So you can
  805. 27:03play with it, get a feel for it, and
  806. 27:05just know that a simple print statement
  807. 27:07like this isn't really programming, but
  808. 27:10it's the first time that you executed a
  809. 27:12Python file, send it to the terminal,
  810. 27:14and everything is running. So if you
  811. 27:16made it to this point in the course
  812. 27:17already, that is already a huge
  813. 27:19milestone because if we actually come
  814. 27:21back to the handbook and see what we've
  815. 27:23learned and say always save your work,
  816. 27:25this is important as well. So come in
  817. 27:27here, I can hit command controls or you
  818. 27:29can go to file save. What this will do,
  819. 27:32it will save everything, all the files,
  820. 27:34all your work. Uh we have the workspace
  821. 27:36in here. So now I can simply close this
  822. 27:38out and then remember right, I can come
  823. 27:40to my Python projects, Python for AAI
  824. 27:42and now I can open up the workspace over
  825. 27:44here. So this is already such a big
  826. 27:47milestone because by now we have
  827. 27:48installed Python on your system. You
  828. 27:50created your first Python file, selected
  829. 27:52the interpreter. So we know we have the
  830. 27:54installation, we have the app, we know
  831. 27:56how to sync them and how to point them
  832. 27:57into the right direction. We created a
  833. 27:59Python program. Remember, we do
  834. 28:01hello.py. The pi extension tells us that
  835. 28:03it's a Python file. And now we
  836. 28:05understand how to run it and send it to
  837. 28:07the terminal as well. All right. And now
  838. 28:08there's one more quick setting that I
  839. 28:11want to do with you. And that is the
  840. 28:13following. If we go to settings over
  841. 28:15here and then search for tree indent. So
  842. 28:19you'll find this setting over here. The
  843. 28:20default is eight. I like I personally uh
  844. 28:24recommend I like to set this to 20. So
  845. 28:26look at what's happening over here in
  846. 28:28the uh explorer over here. If I set this
  847. 28:30to 20, you'll find that you have a
  848. 28:33little bit more indentation in here. Now
  849. 28:34you might be wondering Dave like what is
  850. 28:36this about? But is this is primarily if
  851. 28:38we're going to work with different
  852. 28:39folders. So let me actually uh if we
  853. 28:42have a folder in here and let's say I
  854. 28:43put this in here and I move it and now I
  855. 28:46want to see what's in this folder. Look,
  856. 28:48you can see there is a tree structure in
  857. 28:50here where you can clearly see the
  858. 28:52hierarchy. All right, so that was a lot
  859. 28:53of setup, right? and you are doing
  860. 28:55awesome and the good thing is that this
  861. 28:56is just stuff that we have to do once
  862. 28:58but I fully understand that as you are
  863. 29:00going through this with me you might be
  864. 29:01wondering like Dave I get all of this
  865. 29:03but how does it all fit together trust
  866. 29:05me I felt exactly the same way when I
  867. 29:07was learning all these new things in the
  868. 29:09beginning but trust me it will get
  869. 29:11better we just need to set up a few more
  870. 29:13things cover some core concepts and then
  871. 29:15you are actually fully prepared to
  872. 29:16actually start writing code which from
  873. 29:18there will actually become a lot easier
  874. 29:21all right so we're making great progress
  875. 29:23now the next tab. What I have for you,
  876. 29:25this is really cool. I have some
  877. 29:27resources on a resource hub that I
  878. 29:29created for this course that I want you
  879. 29:32to download right now because we will
  880. 29:33use most of them later. So, if you
  881. 29:35follow the handbook, you have the
  882. 29:37resources in the course resources. And
  883. 29:38now then, if you click on here, you will
  884. 29:40go to this page. You'll see Python fori
  885. 29:42resource hub and community access. Now,
  886. 29:44this is important because this is where
  887. 29:45you can access all the resources. So,
  888. 29:46the templates, files, and cheat sheets
  889. 29:48that you will need for this course. And
  890. 29:49don't worry, this is all completely for
  891. 29:51free. And on top of that, you'll also
  892. 29:53get exclusive community access to the
  893. 29:55data luminina academy where you'll find
  894. 29:57bonus lessons, advanced tutorials, and
  895. 29:59also free follow-up courses to continue
  896. 30:01your AI learning journey. Now, I am
  897. 30:03hosting this on Gumroad, which made it
  898. 30:04really easy for me to host these
  899. 30:06resources, and I can also update them,
  900. 30:08and then you will get a notification.
  901. 30:09Now, the only thing is I couldn't select
  902. 30:11free. I can just do zero. So, don't
  903. 30:13worry, you don't have to pay anything.
  904. 30:14You can just put in zero or any tip you
  905. 30:16want. If you want to give me a tip or a
  906. 30:17coffee, that's totally welcome. But also
  907. 30:19if you want to do zero that's totally
  908. 30:20fine. You click on I want this and then
  909. 30:23here you see the Pyth resource hub and
  910. 30:25community. You'll see an overview and
  911. 30:26then you just need to plug in your email
  912. 30:28address and you can get access. So
  913. 30:29throughout this course I will sometimes
  914. 30:31refer to files from the resource hub. So
  915. 30:33make sure you download that right now.
  916. 30:35And then the first thing you can check
  917. 30:36out is this Visual Studio Code cheat
  918. 30:38sheet with all of the keyboard
  919. 30:40shortcuts. There's one for Mac OS and
  920. 30:41for Windows. And in here are all the
  921. 30:44default keyboard shortcuts. But this
  922. 30:46will also give you an ID into all of the
  923. 30:48actions that are available within the
  924. 30:50code editor and that you can also
  925. 30:52change. This is really fun to play
  926. 30:54around with and you can really like make
  927. 30:56it your own. All right. And with the
  928. 30:58resources downloaded, we can now
  929. 31:00continue. And now before we get into the
  930. 31:01Python basics, which you can see over
  931. 31:03here is the next chapter within this
  932. 31:05course where we're actually going to
  933. 31:06write code, execute it, build cool
  934. 31:08things, and see how all of this come is
  935. 31:10coming together. On the getting started
  936. 31:12page, there's one more section over here
  937. 31:14called Python environment. And I want to
  938. 31:16go through this first because it's so so
  939. 31:18important and it will really help you to
  940. 31:21better understand what's to come and how
  941. 31:23it would also translate to other videos
  942. 31:25and tutorials you see. So I know that
  943. 31:27this this is a lot of setup but it is so
  944. 31:30so crucial and it's that is really what
  945. 31:33makes all the difference in my opinion
  946. 31:34from just a a basic Python course that
  947. 31:37shows you look here's how you can write
  948. 31:38Python. Yes, we know chatbt can do that
  949. 31:41as well, but how does everything work
  950. 31:43together? And virtual environments is a
  951. 31:46key component of that. So what we've
  952. 31:49seen right now, right, we installed
  953. 31:50Python, we then opened up Visual Studio
  954. 31:53Code and we selected the Python
  955. 31:55interpreter that we wanted to use,
  956. 31:56right? So remember when we were working
  957. 31:58in our project over here, you have this
  958. 32:00whole I have this list over here. You
  959. 32:02probably have one or two and we selected
  960. 32:04a a Python version in there. What you
  961. 32:06should know is that when you are working
  962. 32:08with Python in the real world, you're
  963. 32:10often working on multiple projects side
  964. 32:13by side. And next to Python having a
  965. 32:17version like 3.13 within the Python
  966. 32:21programming language, what we also do is
  967. 32:23we work with a lot of packages. We can
  968. 32:26use packages code that someone else has
  969. 32:28written written and we take that and we
  970. 32:30import it into our project and then we
  971. 32:32can use that. These packages also have
  972. 32:34version. So now we have our Python
  973. 32:36installation and we have our packages.
  974. 32:38Now what happens if you're working on
  975. 32:40project A and it needs version 1.0 of a
  976. 32:43tool and you're working in project B and
  977. 32:46that needs version 2.0 of a certain
  978. 32:48package. If you now install version two
  979. 32:50for project B, you just broke project A.
  980. 32:53So now you might be working on
  981. 32:55something. You run your code, everything
  982. 32:58works. then you like end of the day the
  983. 33:01next the next day you open up another
  984. 33:03project you try to run it and now you
  985. 33:04get an error we don't want that of
  986. 33:06course so that's where virtual
  987. 33:08environments come in so these are
  988. 33:12separated private copies for each
  989. 33:14project now before getting into that you
  990. 33:17need to understand uh packages and what
  991. 33:20they are about so I already gave a
  992. 33:22little bit of an introduction right
  993. 33:23these are uh literally pieces of code
  994. 33:25code snippets and files that other
  995. 33:27people created where we now don't have
  996. 33:30to start from scratch and that is one of
  997. 33:32the most amazing things about Python is
  998. 33:35its like developer ecosystem and all the
  999. 33:37packages that we can already use out of
  1000. 33:39the box where now with typically just a
  1001. 33:42few lines of Python we can do incredibly
  1002. 33:45powerful things and we can create in
  1003. 33:47incredibly powerful automations. So a
  1004. 33:50very common one is the request library
  1005. 33:52which we'll be using in this course the
  1006. 33:54pandas library for working with data or
  1007. 33:56the openi library to work with the
  1008. 33:58models from openai. So to create your
  1009. 34:00first virtual environment in our own
  1010. 34:03project that we're currently working on.
  1011. 34:05What we can do is we can use two
  1012. 34:07methods. I'm going to show both of them
  1013. 34:09to you. We have an easier method and we
  1014. 34:10can do it via the terminal. So let's do
  1015. 34:12the easy method first and this is
  1016. 34:15through the command pallet. So within
  1017. 34:17Visual Studio Code, if you do cmd or
  1018. 34:19control shift +b, you'll open up the
  1019. 34:22command pallet. Let's see what that
  1020. 34:23looks like. If I now do cmd shiftp,
  1021. 34:26you'll see the command pallet pop up. So
  1022. 34:29if I now do python create environment,
  1023. 34:32you can see this one over here, create
  1024. 34:33environment, right? And then I get two
  1025. 34:35options over here. So fanf or cond. If
  1026. 34:37you don't have cond installed, you will
  1027. 34:39probably only see f for now. Don't worry
  1028. 34:41about what is and just click on fanf.
  1029. 34:43And now what you can see over here is
  1030. 34:45here you can see all of the Python
  1031. 34:47versions that I have installed on my
  1032. 34:48system. So you can even see that there
  1033. 34:50are some more some older versions 3.9 in
  1034. 34:53here. What I'm going to do is I'm going
  1035. 34:54to select the latest version. And for
  1036. 34:57you there will probably only be one or
  1037. 35:00two. I recommend just picking the
  1038. 35:01highest version. So we click on that.
  1039. 35:03And now what's going to happen is Visual
  1040. 35:06Studio Code is going to create a virtual
  1041. 35:08environment for us. So you can see it
  1042. 35:09happening over here. We now have this
  1043. 35:11folder. It's called Fenf. And if I open
  1044. 35:14this up, you can see files and folders
  1045. 35:16in here. And what we've we've now done
  1046. 35:18is we created a local copy of the Python
  1047. 35:22installation. And if I now come back to
  1048. 35:26hello.py, what I can now do, you can see
  1049. 35:28it's already selected over here. Visual
  1050. 35:30Studio Code does an excellent job at
  1051. 35:33autodetecting the environment when it's
  1052. 35:35uh within your project. But you can see
  1053. 35:37that we now have the ven over here and
  1054. 35:40which stands for virtual environment.
  1055. 35:41And you can select that and what we can
  1056. 35:43do right now if we now click on the play
  1057. 35:46button one more time we will execute the
  1058. 35:48code and we will execute it using our
  1059. 35:50own environment. So I get it this is
  1060. 35:52again this is abstract right at this
  1061. 35:54point but think of it like this when
  1062. 35:56you're working on different projects you
  1063. 35:57really want to isolate everything and
  1064. 35:59this is a way to get Python within our
  1065. 36:01project in that folder in that folder
  1066. 36:03that we could just created defense and
  1067. 36:06we can make all the changes and all the
  1068. 36:08updates just there. And this is also one
  1069. 36:11of those things that's the nice things.
  1070. 36:13This is like set it forget it once on a
  1071. 36:15new project. And because we save it in
  1072. 36:17the workspace right now the virtual
  1073. 36:19environment is there. We've selected it.
  1074. 36:21Now if I come back to uh the project
  1075. 36:24over here I save this and I just close
  1076. 36:27out of this. I can come to the folder
  1077. 36:28over here. Open up the project and then
  1078. 36:31you can see that it correctly selected
  1079. 36:33the virtual environment and I can just
  1080. 36:34come in here and run it without a
  1081. 36:37problem. It is now using our virtual
  1082. 36:39environment that we just created. All
  1083. 36:40right. So that was method number one to
  1084. 36:42create a virtual environment. The easy
  1085. 36:44method. Now I'm going to show you the
  1086. 36:45second method which is through the
  1087. 36:47terminal. And I'm going to show you this
  1088. 36:49so you understand it that whenever you
  1089. 36:51see a tutorial you understand, oh
  1090. 36:53they're creating a virtual environment
  1091. 36:54using the terminal, but I never use
  1092. 36:56this. So I'm just going to come over
  1093. 36:58here and I'm going to copy this line. So
  1094. 36:59python- mf and then the name of the
  1095. 37:02folder. And let's close all of this out.
  1096. 37:04I'm going to completely remove the
  1097. 37:05folder again. Now I'm going to open up a
  1098. 37:08new terminal and I'm going to paste the
  1099. 37:10command in here and run it. And what
  1100. 37:13you'll find is that right now you can
  1101. 37:15see we have created a similar folder. So
  1102. 37:17this is what h what's happening behind
  1103. 37:18the scenes when you do the command
  1104. 37:20pallet python create environment. And
  1105. 37:23now because we have created the new
  1106. 37:24folder in here we should select it one
  1107. 37:27more time just to make sure that we
  1108. 37:29refresh it and we should be good to go
  1109. 37:31again. So that's another way to set up a
  1110. 37:33virtual environment. All right. Now then
  1111. 37:35a quick note about Anaconda because I
  1112. 37:36want this to be a complete course and
  1113. 37:38whenever you encounter it maybe in
  1114. 37:40another tutorial I want you to be aware
  1115. 37:42of it. So Anaconda is another way of
  1116. 37:44managing Python distributions and
  1117. 37:46virtual environments on your machine.
  1118. 37:48It's very popular in the data science
  1119. 37:50world and right now I would say I
  1120. 37:52actually don't recommend using it. So I
  1121. 37:54used this earlier on in my career but
  1122. 37:56now when you want to focus on AI there's
  1123. 37:59actually a much better way to manage
  1124. 38:01Python environments and packages. So
  1125. 38:03later on I'm going to introduce you to
  1126. 38:05UV. Don't worry about that for now, but
  1127. 38:07that's now my go-to. So Anaconda is a
  1128. 38:09whole other application that you need to
  1129. 38:11download and install on your system.
  1130. 38:12It's free, but for now you just need to
  1131. 38:14be aware of it. So whenever you
  1132. 38:15encounter it and someone mentions using
  1133. 38:17Anaconda, you can literally just replace
  1134. 38:20that with using a virtual environment
  1135. 38:21and just install the packages in there.
  1136. 38:23It's exactly the same. You can so you
  1137. 38:25can still follow along with that
  1138. 38:26tutorial or course wherever they're
  1139. 38:28using Anaconda. All right. And with
  1140. 38:30virtual environments covered, let's get
  1141. 38:32into Python packages. Another very
  1142. 38:34important concept to understand because
  1143. 38:36out in the world, whatever tutorial or
  1144. 38:39course you'll follow, there is a high
  1145. 38:42chance that at the beginning of the
  1146. 38:44file, they will do some kind of imports
  1147. 38:46and use some kind of packages and I can
  1148. 38:48explain you everything about Python and
  1149. 38:49how it works and how to write and what
  1150. 38:51it means. If you don't understand this,
  1151. 38:53you will run your code and you will
  1152. 38:55still get an error. That's why I want to
  1153. 38:57start here. So I already gave the
  1154. 38:59introduction, right? Packages are
  1155. 39:00collections of Python code that solve
  1156. 39:02specific problems that other people
  1157. 39:05created and that we can now very easily
  1158. 39:07download and use for free. It's really
  1159. 39:10awesome. And in order to get those
  1160. 39:12packages and get them into our project,
  1161. 39:15we can use pip. And pip installs these
  1162. 39:18Python packages. It can manage all of
  1163. 39:20that. So we don't have to go to a
  1164. 39:21website. We don't need to do uh go
  1165. 39:23through an install menu. We can simply
  1166. 39:25run commands from the terminal and it
  1167. 39:28will pull it straight into our project
  1168. 39:30and specifically into our virtual
  1169. 39:33environment. So pip is a command that
  1170. 39:35you need to be f familiar with. So now
  1171. 39:38let's install your first Python package.
  1172. 39:42And to do that we're going to go through
  1173. 39:44the terminal again. So open up the
  1174. 39:46project and let's see. You can open up a
  1175. 39:48new terminal or I can also do command J
  1176. 39:51to pull up the one that I have active
  1177. 39:53over here. So you can see I have
  1178. 39:54previous sessions. You can close and
  1179. 39:56manage them over here. And if I want to
  1180. 39:58clear it out, I can do clear on Mac or
  1181. 40:00cls on Windows which is not recognized
  1182. 40:03over here. This is the starting point.
  1183. 40:06This is now going to be the input for
  1184. 40:09which we're going to use pip in order to
  1185. 40:11pull those packages from the internet.
  1186. 40:13So let's continue. So we understand the
  1187. 40:16terminal right now and we are we want to
  1188. 40:19make sure this is important that we are
  1189. 40:21in our virtual environment. So let me
  1190. 40:23actually check if I did that correctly
  1191. 40:24as I am uh walking you through this and
  1192. 40:27no I did not because I used a terminal
  1193. 40:29session that was already open and later
  1194. 40:32we installed the environment. So let me
  1195. 40:34show you what I mean with this because
  1196. 40:35this is a very common uh mistake. I just
  1197. 40:38like click on the trash bin icon and now
  1198. 40:40I go to new terminal. I open it up. This
  1199. 40:42will activate it. Look what you can see
  1200. 40:45right now over here. This means that we
  1201. 40:48have a terminal open and it signals that
  1202. 40:51it's using this virtual environment
  1203. 40:53because remember right we have all of
  1204. 40:55the different isolations. Whenever we
  1205. 40:57want to install something we need to
  1206. 40:59tell our terminal it needs to be in this
  1207. 41:01particular folder. So Visual Studio Code
  1208. 41:03will handle all of that automatically
  1209. 41:05for us. So right now whenever this is
  1210. 41:07available, this is active, it will show
  1211. 41:09up using the virtual environment. One of
  1212. 41:11the most common errors that you run into
  1213. 41:13if you install packages and if it
  1214. 41:15doesn't work if this wasn't correctly
  1215. 41:17configured. So then you just need to go
  1216. 41:19to okay which is the environment make
  1217. 41:21sure to close it out and then create a
  1218. 41:23new terminal. I'm being a little bit
  1219. 41:25redundant over here but these are the
  1220. 41:26things that will actually give you a lot
  1221. 41:28of headaches when you are working in the
  1222. 41:31real world. So make sure to take notes
  1223. 41:32and refer back to this video and then
  1224. 41:34you can say ah they've already told me
  1225. 41:36this is exactly because you will make
  1226. 41:38the these mistakes trust me. Now let's
  1227. 41:40install your first package. And we're
  1228. 41:42going to install the requests library.
  1229. 41:44And the how to do that is really simple.
  1230. 41:46It's pip install and then the name of
  1231. 41:49the package. And in this case, we're
  1232. 41:50going to install the requests library.
  1233. 41:52Let's come over here. Let's clear this
  1234. 41:54out. We do pip install requests. And
  1235. 41:57then we hit enter. It doesn't take that
  1236. 41:59long. Now we have downloaded the
  1237. 42:00package. What just happened? Well,
  1238. 42:02through the terminal and through the pip
  1239. 42:04command, we connected to the Python
  1240. 42:06package index, which is a huge websites
  1241. 42:08where developers share their code. Then
  1242. 42:10we downloaded a package, which are
  1243. 42:12really just a bunch of Python files that
  1244. 42:14someone else wrote, and we saved it to
  1245. 42:16your virtual environment. So, let me
  1246. 42:18also show you what's going on behind the
  1247. 42:19scenes because now if we go into our
  1248. 42:22virtual environment folder over here, we
  1249. 42:24can come in here and we go to library
  1250. 42:27and then we scroll down, you can see
  1251. 42:29requests. So, this is the folder. So
  1252. 42:31this is the package that we installed.
  1253. 42:32And now you can see this is what we just
  1254. 42:35pulled in here. Really just a bunch of
  1255. 42:37Python files that someone else wrote
  1256. 42:39that we can now use. You never have to
  1257. 42:42like look in here. You rarely touch
  1258. 42:44this, but just know that that's where
  1259. 42:46it's installed and that's where it's on
  1260. 42:48your system. And now then in order to
  1261. 42:50use a package, what you can do in any
  1262. 42:52Python file, you can start with an
  1263. 42:54import statement. And later in this
  1264. 42:56course, we'll go much deeper into this.
  1265. 42:58Right now it's just about like showing
  1266. 43:00you how to do it. So you've seen it once
  1267. 43:03and later like comes the understanding.
  1268. 43:05So right now we can simply copy paste
  1269. 43:08this whole snippet over here to import
  1270. 43:09the request library and try to download
  1271. 43:12the content of a web page. So if I now
  1272. 43:15come back to my project let's see
  1273. 43:16hello.py. So this is the same file that
  1274. 43:18you should have in here. We can remove
  1275. 43:20everything here and plug this in. And
  1276. 43:22now you can see it is still giving
  1277. 43:23squiggly lines. Uh, and that can
  1278. 43:26sometimes happen in the beginning. If
  1279. 43:27you selected the right environment and
  1280. 43:29you installed it correctly, this should
  1281. 43:31all work. So now if I run this, we
  1282. 43:34should see that this is now going to
  1283. 43:36run. And there we should get a 200 back.
  1284. 43:39So this is just a status code. So we're
  1285. 43:40just literally like pinging the website.
  1286. 43:42Again, doesn't matter what that means.
  1287. 43:44You can now see we've imported the
  1288. 43:46request library and it works. So the
  1289. 43:49squiggly lines tells you that there is
  1290. 43:52potentially an import error. And how to
  1291. 43:54usually fix this is if I now close out
  1292. 43:57this project and I open it up one more
  1293. 43:59time. So come in here and let's open up
  1294. 44:01the workspace. You can see that now it's
  1295. 44:02gone. So sometimes this is a little bit
  1296. 44:04of a bug where it tells you it's not
  1297. 44:06installed correctly. Just reopen your
  1298. 44:08Visual Studio Code. It should be gone.
  1299. 44:09And let's see. We can run it one more
  1300. 44:11time and everything still works. All
  1301. 44:13right. And that's all you need to know
  1302. 44:14for now about using Python packages. If
  1303. 44:17you look into the handbook, there's more
  1304. 44:19information on this list, but don't
  1305. 44:21worry about it for now. We'll get back
  1306. 44:22to that later. So now the final thing
  1307. 44:24that I want to walk you through as part
  1308. 44:26of the getting started section is
  1309. 44:28interactive Python. And this is going to
  1310. 44:31be really cool. This is actually one of
  1311. 44:32my favorite ways to work with Python.
  1312. 44:35And when I discovered this, I pretty
  1313. 44:37much never went back. And to this day,
  1314. 44:40almost every day, someone on my YouTube
  1315. 44:42channel, like in in one of the comments
  1316. 44:44on one of the many videos that I have,
  1317. 44:46someone asked me, "How do you do that?"
  1318. 44:48I have multiple videos on this already,
  1319. 44:50but like this really changed the game
  1320. 44:52for me and how fast I can work and how
  1321. 44:55much fun it is to work with the Python
  1322. 44:56programming language. So, let's set it
  1323. 44:58up. Right now, I've shown you how you
  1324. 45:01can execute Python code using the
  1325. 45:03terminal. Right, we have this over here.
  1326. 45:04We hit command enter or we do run Python
  1327. 45:08file and it runs. But to me, this always
  1328. 45:11really bothered me a lot because pretty
  1329. 45:14much look at it right now. What's all
  1330. 45:15this mess going on right here? Right, we
  1331. 45:18get a 200 as an output. But there's just
  1332. 45:20so much stuff uh going on. And there's
  1333. 45:24actually in my opinion a much easier way
  1334. 45:26to work with Python and that is using
  1335. 45:28interactive mode. So let's first set it
  1336. 45:30up and then I'll explain what it is. So
  1337. 45:32there's one prerequisite and we need to
  1338. 45:34install a package and that's why I
  1339. 45:36wanted to share how you can install
  1340. 45:38packages because you need this one. So
  1341. 45:41what you can do is right now you can
  1342. 45:42simply click on copy or like follow the
  1343. 45:44command pip install IPI kernel. That's
  1344. 45:46the one we need. So coming back to our
  1345. 45:48editor to a terminal session. All right,
  1346. 45:51let's come in here and do pip install
  1347. 45:53ipi kernel. So this will install
  1348. 45:55everything in there. Takes a couple of
  1349. 45:57seconds. And this will also work with
  1350. 45:59the Jupiter extension that we have
  1351. 46:00installed in Visual Studio Code as well.
  1352. 46:02So we have that and we have the IPI
  1353. 46:04kernel. And now what we can do, we need
  1354. 46:07to change a setting to make this super
  1355. 46:09easy. So the easiest way to do this is
  1356. 46:11simply copy this whole line because
  1357. 46:14there are a lot of settings in Visual
  1358. 46:15Studio Code. So Jupyter inter so copy
  1359. 46:17this whole line and then come over here
  1360. 46:19to the gear icon to the settings and
  1361. 46:21then I just plug that in there and then
  1362. 46:23you should see this Jupyter interactive
  1363. 46:25window text editor execution selection.
  1364. 46:27So here you can see when pressing shift
  1365. 46:29enter send selected code in Python file
  1366. 46:32to the Jupiter interactive window as
  1367. 46:34opposed to the Python terminal and we
  1368. 46:36select that. That's it. Now if I close
  1369. 46:39out on this. So we have the same script
  1370. 46:42over here. And now what I can do is
  1371. 46:44instead of hitting command and enter to
  1372. 46:47like run it in the terminal, right?
  1373. 46:48That's the uh hotkey that I set in the
  1374. 46:50beginning. What I can also do is I can
  1375. 46:53select a certain section of the code. It
  1376. 46:55can either be everything or a single
  1377. 46:57line. And then I do shift enter and a
  1378. 47:00window to the right will open. And now
  1379. 47:02you can see the 200 status over here as
  1380. 47:04well. So the difference is is that
  1381. 47:07instead of like taking the entire file
  1382. 47:09and sending it to the terminal and then
  1383. 47:11all of the outputs showing up in my
  1384. 47:13opinion in kind of like a messy way with
  1385. 47:15a lot of like noise in there, now we
  1386. 47:17have this very clean window here on the
  1387. 47:19right where we can see the output. But
  1388. 47:21it even gets better because instead of
  1389. 47:22just running the entire file from like
  1390. 47:25top to bottom, what we can also do is we
  1391. 47:27can also execute certain sections or
  1392. 47:29certain lines or pieces of the code
  1393. 47:32itself. So I can come in here and when I
  1394. 47:34am on a single line, so I'm now on line
  1395. 47:36one and I do shift enter. You can see
  1396. 47:38that we only run import request. So now
  1397. 47:40we import the library and I can for
  1398. 47:43example also just run the request over
  1399. 47:46here. So just do that. So I just get the
  1400. 47:48response and then finally I do the print
  1401. 47:51statement. So, not only does it allow us
  1402. 47:54to have a cleaner interface on the
  1403. 47:56right, it also allows us to go through
  1404. 47:58our code more in a more granular fashion
  1405. 48:01and highlight certain section of this.
  1406. 48:03So, as we go through this course and as
  1407. 48:06we start to actually work with the
  1408. 48:07Python programming language, this will
  1409. 48:09really become apparent to you as to why
  1410. 48:11this is nice and why this is so useful
  1411. 48:13because we can check back and we can
  1412. 48:15actually go here and say, look, we can
  1413. 48:17even select partial lines. So, not even
  1414. 48:19a full line, but I can do a selection
  1415. 48:21and I can use the shift and the uh alt
  1416. 48:23and option keys to go through this and
  1417. 48:25even look at specific variables in here.
  1418. 48:28All right, so that was the getting
  1419. 48:29started section. Congratulations. We
  1420. 48:31already covered a lot. Now, this would
  1421. 48:33also be a good moment to take a break
  1422. 48:35and to really think about what we've
  1423. 48:38learned so far. So, let me quickly walk
  1424. 48:39you through it. Right. So, when you
  1425. 48:42started with this course, you did not
  1426. 48:44have a Python installation. So, we got
  1427. 48:46that onto your system. We got Visual
  1428. 48:48Studio Code. You have the application.
  1429. 48:50You now know how to create projects in
  1430. 48:52there. Save them as a workspace and then
  1431. 48:54you also understand the importance of
  1432. 48:56virtual environments to create isolated
  1433. 48:59in instances of the Python programming
  1434. 49:01languages so that we can install the
  1435. 49:03packages. You've seen how to work with
  1436. 49:05the basics of Visual Studio Code, the
  1437. 49:07extensions, how to style it. You know
  1438. 49:09how to run Python files either using the
  1439. 49:12terminal or using the interactive window
  1440. 49:14which I am a big fan of. So right now
  1441. 49:17you really have all the tools to start
  1442. 49:19to get to work and you are so much
  1443. 49:22better prepared than pretty much anyone
  1444. 49:25else trying to learn Python because this
  1445. 49:27really is a cheat code. Everything that
  1446. 49:29I shared in here and that I boiled down
  1447. 49:31into this step-by-step format, this all
  1448. 49:33really took me years to learn. And I
  1449. 49:35really wish someone in the beginning of
  1450. 49:37my Python programming journey like
  1451. 49:38literally over 12 years ago, I wish
  1452. 49:40someone would have shown me this
  1453. 49:42approach because it's a complete
  1454. 49:45gamecher. And now if you're up for an
  1455. 49:47exercise to really check if you
  1456. 49:49understand this, here's what you can do.
  1457. 49:51And I in the beginning this is tricky
  1458. 49:53because I've given so many Python
  1459. 49:55trainings already and students follow
  1460. 49:57along up until this point. But then when
  1461. 50:00they start again from scratch and they
  1462. 50:02have to do it on their own with without
  1463. 50:04essentially me like holding their hands
  1464. 50:05and showing everything step by step, it
  1465. 50:07can get tricky. So here's what I want
  1466. 50:09you to do. Go to your Python projects
  1467. 50:11folder and create a new project. So in
  1468. 50:13there, create a new folder, give it a
  1469. 50:15name, and then I want you to open it up
  1470. 50:17in Visual Studio Code and go through the
  1471. 50:19entire process. Everything that you need
  1472. 50:21to do in order to set up to create a
  1473. 50:23file, put some Python code in there. You
  1474. 50:25can do a simple print statement similar
  1475. 50:26to what we already did. use a virtual
  1476. 50:28environment. Make sure you select it and
  1477. 50:30make sure that you can run it both in
  1478. 50:32the terminal and in the Jupyter
  1479. 50:34interactive session. Make sure you save
  1480. 50:36everything to a workspace and then close
  1481. 50:38it out to see if you can open it up
  1482. 50:39again. If you can follow along with
  1483. 50:41that, you pass this first section of the
  1484. 50:43course and you're ready for the next
  1485. 50:44stage. All right, so welcome to the
  1486. 50:47Python basics chapter. We are now
  1487. 50:50actually going to start writing Python
  1488. 50:53code and learning the language, learning
  1489. 50:55what this is all about and how we can
  1490. 50:56use it. So now with our environment set
  1491. 50:59up, VS Code ready, our everything
  1492. 51:02installed, we can use our Hello Pi file.
  1493. 51:04And this is going to be the file that
  1494. 51:06I'm going to continuously to work in.
  1495. 51:08You can use this as a scratch pad,
  1496. 51:10right? You so you can be sloppy in here.
  1497. 51:12You can put some code in there. We can
  1498. 51:14run it and then the next example, we can
  1499. 51:16get back to this and we can keep using
  1500. 51:19this. So we don't have to worry about
  1501. 51:21managing all of the files. So what I'm
  1502. 51:23going to do for now is I'm also going to
  1503. 51:24close the sidebar over here to create a
  1504. 51:27little bit more real estate on the
  1505. 51:29screen here. And the command for that is
  1506. 51:31command or control D to show the
  1507. 51:33explorer. But for now, this is what we
  1508. 51:35need to do. Okay. So coming back to the
  1509. 51:39foundations, we're going to start with
  1510. 51:41really the very basic building blocks of
  1511. 51:43the Python programming language like
  1512. 51:45variables, data types, operators. But
  1513. 51:47before getting into that, I want to give
  1514. 51:49you a little bit of an understanding
  1515. 51:51like to understand the bigger picture of
  1516. 51:53what programming is all about. Now, if
  1517. 51:55you're coming from a different language,
  1518. 51:57you can skip this part because you're
  1519. 51:58already fully aware with this. But if
  1520. 52:00you're completely new to programming, I
  1521. 52:03this is a great moment to take a step
  1522. 52:05back and to explain you what we're
  1523. 52:07fundamentally doing. Because when you
  1524. 52:08are following this program like step by
  1525. 52:11step, action by action, you are so
  1526. 52:13zoomed in into following exactly what I
  1527. 52:16do, right? Installation, I get it. The
  1528. 52:18app, I get it. An environment and but
  1529. 52:20you need to understand what's the goal
  1530. 52:23of all of this. What are we trying to
  1531. 52:25do? And programming is all about writing
  1532. 52:28instructions for computers. And
  1533. 52:31computers are very literal. So you need
  1534. 52:34to tell them exactly what it is that you
  1535. 52:37want them to do. So if you for example
  1536. 52:39tell a friend of yours like hey go make
  1537. 52:41a coffee like internally they understand
  1538. 52:44that they need to get a cup add coffee
  1539. 52:46grounds pour hot water wait a couple of
  1540. 52:48minutes the whole process right a
  1541. 52:50computer doesn't understand this so when
  1542. 52:52we want to try and accomplish something
  1543. 52:54when we are trying to automate something
  1544. 52:56where where when we try to create an AI
  1545. 52:58agent or build a model we need to be
  1546. 53:00very specific and we need to instruct
  1547. 53:02the computer in such a way to follow the
  1548. 53:05exact order of operations in order to
  1549. 53:07accomplish our goal and there are many
  1550. 53:10ways to do that and many ways and many
  1551. 53:12programming languages to accomplish that
  1552. 53:14and Python is one of them. So that's the
  1553. 53:16first thing that you keep in mind. We
  1554. 53:18are working on all of these isolated
  1555. 53:20bits and pieces that in isolation don't
  1556. 53:23mean a thing and are pretty useless. But
  1557. 53:25when once we start to understand all of
  1558. 53:27these building blocks and we start to
  1559. 53:29combine them in different ways like Lego
  1560. 53:31blocks, we can now all of a sudden
  1561. 53:34create an AI chatbot. We create an AI
  1562. 53:36agent. we can uh create a simple script
  1563. 53:39that can take a document, extract
  1564. 53:41information, give a summary and put it
  1565. 53:42into a CRM. It open up opens up a whole
  1566. 53:45world of possibilities which we can all
  1567. 53:47do through the Python programming
  1568. 53:49language. So that's what I want you to
  1569. 53:51keep in mind as we start with these
  1570. 53:53really really fundamental concepts.
  1571. 53:56They're isolated. They're small. On
  1572. 53:57their own, they mean nothing. And you're
  1573. 54:00probably wondering like what can I
  1574. 54:01automate this? What does this have to do
  1575. 54:03with AI? But once we start to layer
  1576. 54:05them, that's where everything starts to
  1577. 54:07click. And with all programming
  1578. 54:09languages, there are only a handful of
  1579. 54:12basic operations that we do over and
  1580. 54:15over again. So here the first one, a
  1581. 54:17very common one is storing information.
  1582. 54:19We want to get some type of data and we
  1583. 54:20want to store that information so that
  1584. 54:22we can process it. Let's say we have an
  1585. 54:24age 25, a name is Sarah. Now later we
  1586. 54:28can use that. We can reference Sarah by
  1587. 54:30using the name variable. We can also
  1588. 54:32make decisions. we can use if and else
  1589. 54:34statements. So if this happens, we do
  1590. 54:36that. But if that is the case, we do
  1591. 54:38that. This allows us to make smart
  1592. 54:41programs that don't only do just one
  1593. 54:43thing, but based on the data and the
  1594. 54:45information that is coming in, we can
  1595. 54:47make decisions. Programs can also repeat
  1596. 54:50actions. So they can repeat things 10
  1597. 54:52times. So when a document is coming in
  1598. 54:55maybe it has like 10 pages and for every
  1599. 54:57page we want to do something maybe
  1600. 55:00scrape the data extract it and then
  1601. 55:02calculate things. So what's the total
  1602. 55:04price? We have numbers. We want to add
  1603. 55:05them, subtract, sub subtract them, apply
  1604. 55:07any kind of math. And through this
  1605. 55:10storing information, making the
  1606. 55:12decisions, repeating the action and
  1607. 55:13calculating things, we can solve a lot
  1608. 55:16of problems actually using a programming
  1609. 55:18language. All right. And then now let's
  1610. 55:20get to the next section which is called
  1611. 55:22Python syntax. This is all about how we
  1612. 55:25properly write Python code. And similar
  1613. 55:27to the English language where we have
  1614. 55:30grammar, Python and every other
  1615. 55:32programming language for that matter
  1616. 55:34also follows follows certain rules. And
  1617. 55:36instead of grammar, we call it syntax.
  1618. 55:39So this is an important topic to
  1619. 55:42understand. Even though Python is known
  1620. 55:43for being very clean and readable,
  1621. 55:46right? We saw that in the beginning. It
  1622. 55:47pretty much just reads like plain
  1623. 55:49English, there are still rules that we
  1624. 55:51need to follow. And this is good of
  1625. 55:53course because otherwise all the code
  1626. 55:55from everyone would look different and
  1627. 55:56it would all be messy. So throughout all
  1628. 55:59of the following examples I will refer
  1629. 56:01to the specific syntax and just know
  1630. 56:04that if you ever run into an error there
  1631. 56:06is a high chance that you will have some
  1632. 56:08type of syntax error. Maybe it's a
  1633. 56:10bracket that did not close. Maybe there
  1634. 56:12is a quote missing. Maybe the
  1635. 56:14indentation and the spaces are off. It's
  1636. 56:16literally that tricky. So remember that
  1637. 56:18for now. Syntax is all about how you
  1638. 56:20write Python code and the rules you need
  1639. 56:22to follow. And now as you go through
  1640. 56:23this course, syntax is something I will
  1641. 56:25bring up all the time because whenever I
  1642. 56:27introduce a new concept, we will start
  1643. 56:29with the syntax first. How to write it
  1644. 56:31and what are the rules. And one of the
  1645. 56:33most important things there which is
  1646. 56:34also unique to Python is the indentation
  1647. 56:37which is the spacing that we use to
  1648. 56:39separate blocks of code and to bundle
  1649. 56:41pieces of code together. So if you for
  1650. 56:44example look at a JavaScript language
  1651. 56:45you can for example use curly brackets
  1652. 56:47and that signals look everything between
  1653. 56:49these curly bracket belongs together.
  1654. 56:51With Python we solely do that through
  1655. 56:53indentation. So we'll go through
  1656. 56:55indentation rules which we will
  1657. 56:56constantly use and our editor will also
  1658. 56:58help us with this because whenever we go
  1659. 57:00to a new line where we need an
  1660. 57:02indentation VS code will automatically
  1661. 57:04do this for us. Now don't just worry
  1662. 57:05about that right now. It will all become
  1663. 57:07more clear as we go through the
  1664. 57:08examples. But just know that indentation
  1665. 57:10rules and using those four spaces is
  1666. 57:12important in Python. Now, beyond just
  1667. 57:14syntax rules that make your code run,
  1668. 57:16Python also has style guidelines that
  1669. 57:18make code more readable. And we as
  1670. 57:20developers have agreed to a certain
  1671. 57:22standard and these this is called PEP 8
  1672. 57:24or the Python enhancement proposal 8.
  1673. 57:26This is the official style guide for
  1674. 57:28Python code. It covers things like that.
  1675. 57:30We use four spaces instead of taps. We
  1676. 57:32limit lines to 79 characters, naming
  1677. 57:35conventions like using underscores
  1678. 57:37lowercase instead of using camelc case
  1679. 57:39and where to put spaces around
  1680. 57:41separators. And now as we go through
  1681. 57:43this course, I will follow these PEP 8
  1682. 57:44style guidelines so you don't have to
  1683. 57:46worry about them right now. But just
  1684. 57:48know that there are rules for
  1685. 57:49indentation for how we work with spaces,
  1686. 57:51blank lines, and even line length. And
  1687. 57:54at the end of this course, I'm even
  1688. 57:55going to introduce you to a tool that
  1689. 57:56can automatically take care of that. All
  1690. 57:59right. So now let's have a look at what
  1691. 58:00happens when you don't follow the syntax
  1692. 58:03and you break your code. So let's say we
  1693. 58:05do another print statement. Then we type
  1694. 58:07hello world but then we remove the final
  1695. 58:11quote over here. And you can already see
  1696. 58:13that our editor is giving us these red
  1697. 58:15squiggly lines indicating that something
  1698. 58:17is wrong. So the string literal is
  1699. 58:19unterminated meaning it is opened but
  1700. 58:21it's not closed. But for the sake of
  1701. 58:23demonstration I am going to run this
  1702. 58:24code. So what I'm going to do in this
  1703. 58:26case I'm going forward. You will see me
  1704. 58:28do this over and over again. My cursor
  1705. 58:30is here on this line and I am
  1706. 58:31controlling that with the arrow keys
  1707. 58:33left and right. And now on this line I
  1708. 58:35simply press shift enter. And what this
  1709. 58:37will do is it will open up the
  1710. 58:39interactive window over here. And now
  1711. 58:41here you can see the error. So you can
  1712. 58:42see the line on which the error
  1713. 58:44occurred. You can see it starts here. We
  1714. 58:46opened up a string and then you see this
  1715. 58:48syntax error. So now you know what
  1716. 58:49syntax means and where this is coming
  1717. 58:51from. So it says unterminated string
  1718. 58:53literal detected which is just Python's
  1719. 58:56way of explaining you opened up the
  1720. 58:58string but you're missing a closing
  1721. 59:00quote. So if we plug that in here and
  1722. 59:03run it one more time, you'll find that
  1723. 59:05the code will now run without any errors
  1724. 59:07and we will get the hello world
  1725. 59:09statement. And now reading errors is
  1726. 59:12something you have to become good at
  1727. 59:14because errors do not only happen when
  1728. 59:16you're a beginner. Trust me, making
  1729. 59:19errors is literally part of programming.
  1730. 59:21even like the best programmers in the
  1731. 59:23world, you build programs by trying
  1732. 59:25things out, breaking things, and then
  1733. 59:26fixing the bugs. So, it's a core part of
  1734. 59:28the development process. So, how you
  1735. 59:31read Python errors is something you get
  1736. 59:34more and more used to, but there is a
  1737. 59:36general principle that you can follow
  1738. 59:37and it's in the documentation over here
  1739. 59:39as well. So, first you'll see where the
  1740. 59:41error happened. So, here you can see
  1741. 59:42this is in line one. We're running the
  1742. 59:44interactive session with this file. So,
  1743. 59:46this is where it happened. Then, next
  1744. 59:48you can also see what went wrong. So all
  1745. 59:51the way at the bottom of the error and
  1746. 59:53this is right now in this example this
  1747. 59:55is a pretty short error. There can be a
  1748. 59:57lot of information all the way at the
  1749. 59:59bottom the final line you'll see in this
  1750. 1:00:01case the syntax error. So Python will
  1751. 1:00:03tell you what went wrong. And then the
  1752. 1:00:05third component is the arrow pointing
  1753. 1:00:07exactly to the spot where it happened.
  1754. 1:00:09So following this three-step process to
  1755. 1:00:12debug your code whenever something goes
  1756. 1:00:14wrong. Look at what happened. Syntax
  1757. 1:00:16error. Okay. Where line one and then you
  1758. 1:00:18can see the exact snippet. Oh, it is
  1759. 1:00:20something to do with a string. Now, in
  1760. 1:00:22the beginning, all of these syntax
  1761. 1:00:24errors right now, they will seem very
  1762. 1:00:26alien to you. Unterminated string
  1763. 1:00:29literal detected at line one. Pretty
  1764. 1:00:32abstract, right? This is a great spot.
  1765. 1:00:35This is a great time to plug that into
  1766. 1:00:38your AI assistant or just plug it into
  1767. 1:00:40chat GPT and ask, look, I'm writing a
  1768. 1:00:42Python program and I get this error.
  1769. 1:00:45What does this mean? And if you show
  1770. 1:00:47your code even better, it will tell you
  1771. 1:00:49exactly what went wrong and how to solve
  1772. 1:00:52it. And over time, you'll get a much
  1773. 1:00:53better feel for quickly spotting errors
  1774. 1:00:56and what went wrong. And your IDE will
  1775. 1:00:58also help with that. And in this case,
  1776. 1:01:00we could have easily prevented the error
  1777. 1:01:02because our IDE already signals that we
  1778. 1:01:04need to close the string. And now
  1779. 1:01:06throughout this course, if you follow
  1780. 1:01:07along, you're going to make a lot of
  1781. 1:01:09errors. And that's the goal, right?
  1782. 1:01:11Because with that, you'll become more
  1783. 1:01:12and more used to it. That's also why I
  1784. 1:01:14keep hammering on make sure to write
  1785. 1:01:17everything out and not just simply hit
  1786. 1:01:19copy paste on all of the examples in
  1787. 1:01:21there because then out of the box they
  1788. 1:01:22will be good but you need to train
  1789. 1:01:24yourself in order to spot the
  1790. 1:01:26differences to spot the spaces to spot
  1791. 1:01:28the quotes. So make sure to type it out
  1792. 1:01:30on the keyboard make those errors
  1793. 1:01:32correct them and continue. All right now
  1794. 1:01:34it's time to get into one of the most
  1795. 1:01:36fundamental concepts in all of
  1796. 1:01:38programming not just the Python
  1797. 1:01:39programming language but in general and
  1798. 1:01:41that's variables. And variables allow
  1799. 1:01:43you to store and name your data. So
  1800. 1:01:46coming over to the hello.py file over
  1801. 1:01:49here. Let's say you're building a
  1802. 1:01:50program where you want to take in some
  1803. 1:01:52user information. So you want a name and
  1804. 1:01:55let's say we set that to Alice. This is
  1805. 1:01:58Python's way of setting a variable
  1806. 1:02:01called name and we set that equal to
  1807. 1:02:03Alice which in this case is a string. We
  1808. 1:02:07can now run this program and if we now
  1809. 1:02:10come over here and we make a reference
  1810. 1:02:12to name under the hood Python now
  1811. 1:02:14understands that name is equal to Alice
  1812. 1:02:18and similar I can for example set H to
  1813. 1:02:21let's say 25. So now if I go in here and
  1814. 1:02:24I just run H which I do here with the
  1815. 1:02:26interactive session which I can do by
  1816. 1:02:28putting it on another line hitting shift
  1817. 1:02:30enter but I can also do it by taking the
  1818. 1:02:32cursor and just selecting this part. So
  1819. 1:02:35again I'm using this with the arrow keys
  1820. 1:02:37and then I'm holding in shift. I select
  1821. 1:02:39this and I do shift enter to see under
  1822. 1:02:41the hood what the variable is that is
  1823. 1:02:44assigned over here. So we can set age to
  1824. 1:02:4625 and we can also overwrite things
  1825. 1:02:49that's why they are called variables. So
  1826. 1:02:51if I for example now say name equals and
  1827. 1:02:54now I for example say Dave and I run
  1828. 1:02:57this shift enter we can now check and
  1829. 1:02:59now Python understands that name is
  1830. 1:03:01equal to Dave. So this is how we can
  1831. 1:03:04pass data around and we can do that with
  1832. 1:03:06all kinds of data. We can do that with
  1833. 1:03:08strings which you see over here. We can
  1834. 1:03:10do that with numbers and we can even do
  1835. 1:03:12it with uh true or false values. So we
  1836. 1:03:15can for example set is student and then
  1837. 1:03:17we set that equal to true which is also
  1838. 1:03:20something we can do in Python. So the
  1839. 1:03:22things to keep in mind here about the
  1840. 1:03:23syntax about working with variables is
  1841. 1:03:25that on the left you have the variable
  1842. 1:03:27name. Then you use the equal sign which
  1843. 1:03:30means you store the value on the right
  1844. 1:03:32in the variable on the left. We store
  1845. 1:03:35Alice on the variable name and Alice is
  1846. 1:03:39the value that we're storing. Now there
  1847. 1:03:41are also some rules that you should keep
  1848. 1:03:42in mind when working with variables. So
  1849. 1:03:45here you see all kinds of variable and
  1850. 1:03:47variable names that are allowed. So we
  1851. 1:03:49can use an underscore, we can use a
  1852. 1:03:50capital letter, we can use a number in
  1853. 1:03:52here, we can even use an underscore over
  1854. 1:03:54here. But there are also some things
  1855. 1:03:55that are not allowed. So for example, a
  1856. 1:03:57variable name can start with a number.
  1857. 1:03:59It cannot use a hyphen or it cannot use
  1858. 1:04:01a space. And you can also not use
  1859. 1:04:03certain Python keywords. And we can
  1860. 1:04:05validate that by coming over here,
  1861. 1:04:07getting rid of this, and then say to age
  1862. 1:04:10is 30. When I run this, you'll get a
  1863. 1:04:13syntax error. So we get an invalid decim
  1864. 1:04:16decimal literal. This is not possible.
  1865. 1:04:19We can also do new age is 30. This will
  1866. 1:04:24also not work. So here is an example.
  1867. 1:04:26Things that are allowed, things that are
  1868. 1:04:28not allowed. And to make that even
  1869. 1:04:30simpler for you, in the Python naming
  1870. 1:04:32conventions, we use lowercase letters
  1871. 1:04:34with underscores between words. This is
  1872. 1:04:37also called snake case. So when we for
  1873. 1:04:39example want to spell out a first name
  1874. 1:04:41is Alice or a user age you can see that
  1875. 1:04:44instead of doing a space or a hyphen we
  1876. 1:04:46use an underscore. So if I do first
  1877. 1:04:48underscore name and then I set that to
  1878. 1:04:51Alice I can run this and it will be no
  1879. 1:04:54problem. We can just store this similar
  1880. 1:04:56to user age equals 25. That's all fine.
  1881. 1:05:01So the important thing to keep in mind
  1882. 1:05:02here is that there is a difference
  1883. 1:05:04between the strict rules of Python. So
  1884. 1:05:06when it will actually throw an error
  1885. 1:05:08versus the style guides because within
  1886. 1:05:11Python it's totally fine to use capital
  1887. 1:05:13letters here in the middle of a variable
  1888. 1:05:14which is called camel case. I can do
  1889. 1:05:17that right now. So first name with
  1890. 1:05:19capital N equals Alice. I can run that
  1891. 1:05:23and it will not throw an error. But this
  1892. 1:05:26is just a style thing. This is not
  1893. 1:05:28something we do in Python. So to make
  1894. 1:05:30that simple when we talk about variables
  1895. 1:05:32lowerase and when you need to create a
  1896. 1:05:34space use an underscore. And now, as we
  1897. 1:05:36go through all of these examples, I want
  1898. 1:05:38you to know that in the handbook,
  1899. 1:05:40there's almost always a little bit more
  1900. 1:05:41information that we don't cover in the
  1901. 1:05:43video. So, common mistakes, things that
  1902. 1:05:45go wrong, more examples, but otherwise,
  1903. 1:05:47it would be a 10-hour long video. So, I
  1904. 1:05:49cover the basics in here, what you need
  1905. 1:05:51to know. But if you're still like, hm,
  1906. 1:05:52variables, I don't still quite get it.
  1907. 1:05:55Make sure to go through the handbook and
  1908. 1:05:57then ask follow-up questions to ChatBT
  1909. 1:06:00or your favorite AI assistant if you
  1910. 1:06:02still need additional help. Next, let's
  1911. 1:06:04get into comments. So, what are they and
  1912. 1:06:06how do we use them? So, if we come back
  1913. 1:06:09to our script over here, you can see
  1914. 1:06:11that in here we have the first name, we
  1915. 1:06:12have the username. This is code that we
  1916. 1:06:14execute. But Python also allows us to
  1917. 1:06:17put human readable comments in our
  1918. 1:06:20scripts that Python will simply ignore.
  1919. 1:06:23It will not do anything with what we put
  1920. 1:06:25in there. We can put anything we want in
  1921. 1:06:27that case. And we can use descriptions.
  1922. 1:06:29We can explain certain bits and pieces.
  1923. 1:06:31We can add to-dos or reminders. And this
  1924. 1:06:34is a way for us as developers to not
  1925. 1:06:36only uh help our future selves, but also
  1926. 1:06:39potentially other people with which we
  1927. 1:06:42work on the same project. And the way we
  1928. 1:06:44do that within Python is by doing a
  1929. 1:06:46hashtag. So if you type a hashtag,
  1930. 1:06:49you'll see that on that whole line
  1931. 1:06:51starting with the hashtag, it will be
  1932. 1:06:53grayed out. So I can start typing in
  1933. 1:06:55here and I can say this is a comment in
  1934. 1:06:59Python. So you can see it is grayed out.
  1935. 1:07:01And if I now select all of this and I
  1936. 1:07:04run this, nothing will happen with this.
  1937. 1:07:06It won't output anything similar to what
  1938. 1:07:09we have with Alice and the user age. I
  1939. 1:07:11can for example put a print statement
  1940. 1:07:13over here to actually show you. If we do
  1941. 1:07:16the user age and add that to it as well,
  1942. 1:07:19I can execute this whole line and it
  1943. 1:07:21will print 25 because we have instructed
  1944. 1:07:24Python to print this. Similar to this,
  1945. 1:07:27we can also run this in the terminal and
  1946. 1:07:29you'll find that the output of this
  1947. 1:07:31script will just be 25. So there will be
  1948. 1:07:34no trace of this comment whatsoever. So
  1949. 1:07:37we can do that on a whole line like
  1950. 1:07:39this. But we can also do it after uh at
  1951. 1:07:42the end of a line. So if I'm here and I
  1952. 1:07:44want to write a comment saying this is
  1953. 1:07:46the first name, which in this case
  1954. 1:07:49doesn't really add a lot of value, but
  1955. 1:07:51let's say you wanted to give a little
  1956. 1:07:52bit more clarification. This also
  1957. 1:07:54totally works. We can also do multiple
  1958. 1:07:58lines by coming over here saying this is
  1959. 1:08:00another comment. This all works. No
  1960. 1:08:03problem. Now, if you want to write
  1961. 1:08:05comments over multiple lines, there's
  1962. 1:08:07actually one other way that you can do
  1963. 1:08:09this and that is by using triple quotes.
  1964. 1:08:11So, another way to write a comment is
  1965. 1:08:13doing it like this. You'll see three
  1966. 1:08:15opening quotes and then I can go over
  1967. 1:08:17here and I do three closing quotes. and
  1968. 1:08:20anything that I write in between here.
  1969. 1:08:22For example, this is a multi-line quote
  1970. 1:08:26that can go on and on and on. And in
  1971. 1:08:29this case, you don't have to start every
  1972. 1:08:31line with a hashtag. And this helps for
  1973. 1:08:34readability. You'll also find that this
  1974. 1:08:36is green instead of the grade out
  1975. 1:08:39version in here. So, typically, if you
  1976. 1:08:41want to do short and snappy comments to
  1977. 1:08:43just give a little bit of instruction or
  1978. 1:08:45clarification, you use the hashtags. If
  1979. 1:08:47you want to have more explanatory
  1980. 1:08:50paragraphs to later also describe
  1981. 1:08:52functions and classes and what they do
  1982. 1:08:54and what kind of data you need to put in
  1983. 1:08:56there, then you'll use multi-line
  1984. 1:08:58comments with the triple quotes. And as
  1985. 1:09:00a rule of thumb, you want to use
  1986. 1:09:01comments to explain the why, not the
  1987. 1:09:04what. Because since Python is relatively
  1988. 1:09:07easy to read and it usually reads like
  1989. 1:09:09plain English, you for example, here's
  1990. 1:09:11here's a bad example. So let's say you
  1991. 1:09:13have you want to calculate a total and
  1992. 1:09:14you take the subtotal and you m you
  1993. 1:09:17multiply it to calculate the text and
  1994. 1:09:19then a comment here is multiply subtotal
  1995. 1:09:22by 1.6
  1996. 1:09:23like we can already tell that by reading
  1997. 1:09:25this line. But over here in the top
  1998. 1:09:27example, we for example have a tax
  1999. 1:09:29calculation. And if if people are from
  2000. 1:09:31California, I I don't think I think this
  2001. 1:09:33is off. But let's assume this was
  2002. 1:09:35correct. You explain the the calculation
  2003. 1:09:37why you're doing this. So someone
  2004. 1:09:39looking into this code might might be
  2005. 1:09:41like, okay, what's this number? Oh, it's
  2006. 1:09:42to calculate the sales tax. So that's a
  2007. 1:09:45good reason why instead of explaining
  2008. 1:09:47what. Okay. And up next, we're going to
  2009. 1:09:50talk about data types. So these are the
  2010. 1:09:52different kinds of information that we
  2011. 1:09:55can store in Python and when we were
  2012. 1:09:58experimenting with the variables right I
  2013. 1:10:00already brief briefly mentioned like
  2014. 1:10:02look it can be a string which is text it
  2015. 1:10:04can be a number it can be a true or
  2016. 1:10:05false so let's cover all of the options
  2017. 1:10:07that are there because that's also a
  2018. 1:10:10fundamental concept that you need to
  2019. 1:10:12understand and let's start with numbers
  2020. 1:10:15so under the hood there are actually two
  2021. 1:10:17types of numbers when you are working
  2022. 1:10:19with Python and with most programming
  2023. 1:10:21languages If you're new to programming,
  2024. 1:10:22this is always a little bit weird like
  2025. 1:10:24why why is it different? There is a
  2026. 1:10:26difference between what we call integers
  2027. 1:10:27and floats. And integers are simply
  2028. 1:10:30whole numbers without decimals. So 25.
  2029. 1:10:33And we could set h equals 25. And this
  2030. 1:10:36would be considered an integer or floats
  2031. 1:10:38which have decimal points. So 19.99
  2032. 1:10:43that's a float. Now in the real world in
  2033. 1:10:45practice, Python is so flexible that you
  2034. 1:10:48often don't really have to think about
  2035. 1:10:50this. and you can just write your
  2036. 1:10:52programs as is and Python will
  2037. 1:10:54seamlessly convert one into the other.
  2038. 1:10:56But under the hood there is a difference
  2039. 1:10:58in how they are stored in memory. Uh why
  2040. 1:11:01is this? It simply has to do with
  2041. 1:11:03efficiency about how the computer like
  2042. 1:11:05can process it. But that's all you need
  2043. 1:11:07to know for now. So what can we do with
  2044. 1:11:10numbers, right? Well, we can apply basic
  2045. 1:11:12math operation. It works similar to how
  2046. 1:11:15you would use a calculator. So let's run
  2047. 1:11:18through all of the examples and show you
  2048. 1:11:21how that works. So if we come in here
  2049. 1:11:23and we can literally like use this as a
  2050. 1:11:26calculator. So we can do 5 + 5 and we
  2051. 1:11:29can run this shift enter. You'll see
  2052. 1:11:30this 10. We can do a minus it will be
  2053. 1:11:33zero. We can do multiplication with an
  2054. 1:11:35asterisk. We can do a division.
  2055. 1:11:39Everything works like this. And we can
  2056. 1:11:41also store that into variables. Right?
  2057. 1:11:43So let's say we have our total and we
  2058. 1:11:45want to calculate. we have 10 and we do
  2059. 1:11:48it minus 7 and we come in here we store
  2060. 1:11:50that. So now we do we perform the
  2061. 1:11:53calculation and we store it in the
  2062. 1:11:55total. I come in here and I run that we
  2063. 1:11:58can see three. Now again as I go through
  2064. 1:12:00this just remember because we're using
  2065. 1:12:02the interactive session instead of
  2066. 1:12:04having to write out print all the time
  2067. 1:12:06and print what the total is I can come
  2068. 1:12:08in here and just select total and run
  2069. 1:12:10it. And we can also do powers. So power
  2070. 1:12:13equals we could do 10 and then we use
  2071. 1:12:14double asterisk. let's say to the power
  2072. 1:12:16of two and then this should be 100. So
  2073. 1:12:20give it a couple of tries. Make sure to
  2074. 1:12:22play with this and also to get used to
  2075. 1:12:24typing to selecting the pieces that you
  2076. 1:12:28want to see and just get comfortable
  2077. 1:12:29with this interactive window over here
  2078. 1:12:32knowing at all times that this is quite
  2079. 1:12:34a unique way of working with Python. And
  2080. 1:12:36if I run this script like this, you'll
  2081. 1:12:38see nothing is happening. There's no
  2082. 1:12:40output because there are no print
  2083. 1:12:42statements. So if I were to print the
  2084. 1:12:44power in here, I would need to like
  2085. 1:12:48explicitly write that out, say print,
  2086. 1:12:50and then run it in the terminal session
  2087. 1:12:52like a lot of other examples you'll find
  2088. 1:12:54online do. Then you see the 100 over
  2089. 1:12:56here. But with the interactive window,
  2090. 1:12:58we can just start it up. Come here to
  2091. 1:13:00the total, say, I want just this. I want
  2092. 1:13:03just this. And I want to see the power.
  2093. 1:13:05And here in the beginning, I know that
  2094. 1:13:06I'm repeating myself with this, but you
  2095. 1:13:08need to get those reps in in the
  2096. 1:13:09beginning. you need to see like how I go
  2097. 1:13:11through the code and select things and I
  2098. 1:13:13am so used to this for me it's seamless
  2099. 1:13:15I'm using the arrow keys I'm using shift
  2100. 1:13:17but I'm I totally understand that when
  2101. 1:13:19you go through this you might be like oh
  2102. 1:13:21what how is he doing that so fast so
  2103. 1:13:23follow along run the examples try and
  2104. 1:13:25build your own calculator see what it
  2105. 1:13:27does and as you go through all of those
  2106. 1:13:28examples you'll build the muscle memory
  2107. 1:13:30to do it just like I do all right so
  2108. 1:13:32those are numbers and the basic math
  2109. 1:13:34operations that you can do now let's
  2110. 1:13:37continue to the next data types And
  2111. 1:13:39those are strings. So strings is just a
  2112. 1:13:42fancy word of for text. Any type of text
  2113. 1:13:45we can put into a string. And in Python
  2114. 1:13:48we do that between quotes. Now Python
  2115. 1:13:50doesn't care actually if you use single
  2116. 1:13:53or double quotes. You just got to be
  2117. 1:13:55consistent with this. I always use
  2118. 1:13:57double quotes. So you can also just do
  2119. 1:13:59that. Totally fine. Just be consistent.
  2120. 1:14:02And now there are a lot of things that
  2121. 1:14:03you can do with strings. So let's run
  2122. 1:14:05through a couple of examples. So I'm
  2123. 1:14:07going to create a string here. And I'm
  2124. 1:14:09going to say my name is Dave. This is a
  2125. 1:14:13string over here. And we can even add
  2126. 1:14:15some comments just showcase everything
  2127. 1:14:18that we learned. And now I can select
  2128. 1:14:20all of this and run it. We'll open up
  2129. 1:14:22the session over here. So this is how we
  2130. 1:14:24create a string. And in here we can put
  2131. 1:14:27anything really. We can even go as far
  2132. 1:14:29as let's say let's create my long
  2133. 1:14:33string. We can also use triple quotes.
  2134. 1:14:36And remember how we could also do that
  2135. 1:14:38with comments, right? But if you do it
  2136. 1:14:40after a equal sign, we can put in a long
  2137. 1:14:43string. So you can say my name equals
  2138. 1:14:46Dave and um my last name is Eilar. So in
  2139. 1:14:53this way, let me clear up the capital
  2140. 1:14:55letters over here. We can do this string
  2141. 1:14:57and this is one line, but we can also
  2142. 1:14:59have a long string. And if we now show
  2143. 1:15:02and look what's in here, you can see
  2144. 1:15:04that we have multiple lines in here. So
  2145. 1:15:07that you can see by this uh back slashn
  2146. 1:15:10that signals that it's a new line which
  2147. 1:15:12actually means if we print that. So we
  2148. 1:15:14can print my long string it will show
  2149. 1:15:17and it will print that on a new line. So
  2150. 1:15:20those are the two ways that we can
  2151. 1:15:22specify a string and put it into a
  2152. 1:15:26variable. Now with the string as a data
  2153. 1:15:29type there are a lot of operations that
  2154. 1:15:30we can do. So remember when we had
  2155. 1:15:33numbers right integers or floats we
  2156. 1:15:35could perform math operations. So
  2157. 1:15:38strings have similar features. So one
  2158. 1:15:41thing that we can do is for example
  2159. 1:15:42first name let's set that to first name
  2160. 1:15:45equals Dave and then we say last name
  2161. 1:15:48equals Ear. What we can now do for
  2162. 1:15:51example is we can set full name equals
  2163. 1:15:54and then we do first name and then we do
  2164. 1:15:57a plus sign. So we can actually perform
  2165. 1:15:59some kind of like math operations on
  2166. 1:16:01strings and then we say we want a space
  2167. 1:16:04in between. So I do an empty string over
  2168. 1:16:06here with just a space. Then do another
  2169. 1:16:09plus sign and then I do last name and
  2170. 1:16:13write that in here. Let me make this a
  2171. 1:16:14little bit smaller for you so you can so
  2172. 1:16:16you can see the full line. You can see
  2173. 1:16:18everything. So now if I run just this
  2174. 1:16:20line you can see first name is not
  2175. 1:16:22defined. Oh yeah this is a very common
  2176. 1:16:24error because I forgot to uh run these
  2177. 1:16:27lines of code. So first I need to store
  2178. 1:16:29this in memory. So now you can see over
  2179. 1:16:31here Python understands okay first name
  2180. 1:16:33is Dave and similar to last name is
  2181. 1:16:35Eilar. And now when I run this whole
  2182. 1:16:38line you can see that this will run and
  2183. 1:16:40I can get the full name out of it. Okay.
  2184. 1:16:43So now we're performing what's called
  2185. 1:16:45string manipulation. And there are a lot
  2186. 1:16:47of actions going on here. So try to
  2187. 1:16:49follow along. Try to put everything in.
  2188. 1:16:52Try to run them line by line and then
  2189. 1:16:54look at what's in the variables. Try to
  2190. 1:16:56select them. Get a feel for working with
  2191. 1:16:59this programming language and the
  2192. 1:17:00interactive window. Now what we can also
  2193. 1:17:03do is we next to the plus sign we can
  2194. 1:17:06also for example let's say we have an
  2195. 1:17:08asterisk and we can say or let's let's
  2196. 1:17:11actually do a dash. We can do a dash and
  2197. 1:17:14we can say long dash equals and then we
  2198. 1:17:18do the dash and we do it times. Let's do
  2199. 1:17:20it times 10. We save that. So let's see
  2200. 1:17:23what we have over here. Now we have well
  2201. 1:17:25we I think we can do longer. Let's
  2202. 1:17:27actually do um 30. So now you can see we
  2203. 1:17:31have a really long dash. So now if you
  2204. 1:17:33for example wanted to create a program
  2205. 1:17:34and you want to display some
  2206. 1:17:37information. So first let's say you
  2207. 1:17:39print and then you do we do the full
  2208. 1:17:42name. So we can print the full name and
  2209. 1:17:44then afterwards we print the long dash.
  2210. 1:17:48You can see if we do it like this. There
  2211. 1:17:50we go. And now we can tailor it to kind
  2212. 1:17:53of like the length. I think it will be
  2213. 1:17:55around 12. So now you can see we have
  2214. 1:17:58our name and a dash underneath that. So
  2215. 1:18:00if you want to do some print statements
  2216. 1:18:01or logging this can be helpful. So there
  2217. 1:18:04are things that we can do with strings
  2218. 1:18:06as well. Another operation is we can
  2219. 1:18:09also check the length of a string. And
  2220. 1:18:12this is using a Python built-in function
  2221. 1:18:15similar to print. So if I type print,
  2222. 1:18:17you will see that it turns blue, right?
  2223. 1:18:19This means that this is a built-in
  2224. 1:18:21function from Python. And how do you
  2225. 1:18:23know if it's built in? In the beginning,
  2226. 1:18:24you don't know. That's why you're going
  2227. 1:18:26through this course. As as you'll find
  2228. 1:18:28me explaining variables, sometimes there
  2229. 1:18:30are just things off the shelf that we
  2230. 1:18:32can use. And so getting the length of a
  2231. 1:18:34string is also a built-in function, and
  2232. 1:18:35that's through length. So not the
  2233. 1:18:37complete length but we shorten it. And
  2234. 1:18:38then for example we can plug in the long
  2235. 1:18:41dash in here. And if we run that you'll
  2236. 1:18:44find that it says 12. So what this
  2237. 1:18:46function does is instead of just print
  2238. 1:18:49instead of just printing it it will take
  2239. 1:18:51the string and it will calculate how
  2240. 1:18:53long it is. So if I take the full name
  2241. 1:18:56and do that you'll find that my full
  2242. 1:18:59name. So that's the first name plus the
  2243. 1:19:02space in here plus the last name equals
  2244. 1:19:0513. So that's a length of 13. Whereas if
  2245. 1:19:08I plug in my first name, the length
  2246. 1:19:10should be four because my name has four
  2247. 1:19:12letters. So that's a built-in function
  2248. 1:19:15that you can use. Now there are many
  2249. 1:19:17many built-in functions and we'll cover
  2250. 1:19:20some of them and as you progress on your
  2251. 1:19:22Python journey, you'll encounter more
  2252. 1:19:23and more of these. So when you're trying
  2253. 1:19:25to solve a particular problem and you
  2254. 1:19:26ask JBT, how do I do this in Python?
  2255. 1:19:29Sometimes it will tell you look there's
  2256. 1:19:30actually already a function or later a
  2257. 1:19:32package for this that you can use. Now
  2258. 1:19:35that's all you need to know for now
  2259. 1:19:37about using strings. We can store text,
  2260. 1:19:40we can manipulate it and we can do
  2261. 1:19:42things with it to process information.
  2262. 1:19:44Now next let's get into the third data
  2263. 1:19:47type and those are booleans. So booleans
  2264. 1:19:50are simply true or false. They can just
  2265. 1:19:53be that and they are very handy in
  2266. 1:19:55programming to make decisions because
  2267. 1:19:58based on whether something is true or
  2268. 1:20:00whether something is false we can make
  2269. 1:20:02decisions and we can route our program
  2270. 1:20:04or our data either to for example to the
  2271. 1:20:07left or to the right. Now and one common
  2272. 1:20:09example of this is so we with data
  2273. 1:20:11luminina we build a lot of customer care
  2274. 1:20:13automation systems and one of the steps
  2275. 1:20:15that we have in there is we let an AI
  2276. 1:20:18decide whether an incoming ticket should
  2277. 1:20:20be escalated to a human. So there's a
  2278. 1:20:23whole processing logic behind that but
  2279. 1:20:25ultimately what the AI decides is
  2280. 1:20:27escalate is true or false and when it's
  2281. 1:20:30set to true meaning it should escalate
  2282. 1:20:33we route it to a human to refute and if
  2283. 1:20:35it's false the AI can handle it
  2284. 1:20:37themselves. So th those are booleans and
  2285. 1:20:39we literally write it out with like a
  2286. 1:20:41true or a false and we use a capital
  2287. 1:20:43letter. That's a syntax thing that you
  2288. 1:20:45need to remember. So if I come in here
  2289. 1:20:47and follow the examples. So let me clear
  2290. 1:20:50this up. We can say let's say we have a
  2291. 1:20:52user status and is uh logged in. If we
  2292. 1:20:55set that to true, you will see that it
  2293. 1:20:57will turn orange. This means this is the
  2294. 1:21:00actual boolean the boolean value within
  2295. 1:21:03Python. If I don't do the capital
  2296. 1:21:06letter, you'll find that it's it doesn't
  2297. 1:21:09turn orange and it will give the
  2298. 1:21:11squiggly lines where it says look, you
  2299. 1:21:14should not do this. It should either be
  2300. 1:21:16true or it should be false. So those are
  2301. 1:21:19boolean values. So right now I can say
  2302. 1:21:22is the user logged in? This is false.
  2303. 1:21:24Now booleans often come from creating
  2304. 1:21:27comparisons. So we can do a direct
  2305. 1:21:30assignment which is what we just did,
  2306. 1:21:32right? So we can say is true and we can
  2307. 1:21:35literally just set that to true. So that
  2308. 1:21:37is a direct assignment. But we can also
  2309. 1:21:40perform conditional logic to decide
  2310. 1:21:42whether something is true or false. So
  2311. 1:21:44if you look in the example over here you
  2312. 1:21:46can do a comparison. So let's go through
  2313. 1:21:49this and let's say someone is 18. So we
  2314. 1:21:52have age is 18 and then we create a
  2315. 1:21:54variable called can vote and then we do
  2316. 1:21:56a comparison where we say look we take h
  2317. 1:22:00and we check whether it's greater than
  2318. 1:22:02or equal to 18 and we store that can
  2319. 1:22:07vote is true because we have set age to
  2320. 1:22:10true. So this is another like very cool
  2321. 1:22:13way you can where you can play with the
  2322. 1:22:14interactive session by just selecting
  2323. 1:22:16this over here. So again I'm using the
  2324. 1:22:17arrows arrows. I'm holding shift and
  2325. 1:22:20then I select just this piece over here.
  2326. 1:22:22And now I can check this. This is now
  2327. 1:22:24true. But if I for example set this to
  2328. 1:22:2816. So age over here age now is 16. And
  2329. 1:22:33I do a comparison whether it's greater
  2330. 1:22:35or equal to 18. You'll find it is now
  2331. 1:22:38false. And now if I run the entire line
  2332. 1:22:40I can now set can vote to false. So, do
  2333. 1:22:43you already get a feel for what this is
  2334. 1:22:46like and how this works? So, now the uh
  2335. 1:22:48comparison operators in here. That's
  2336. 1:22:51just one of those syntax things that you
  2337. 1:22:53need to see a couple of times in the
  2338. 1:22:56beginning. So, let's actually see what
  2339. 1:22:58we can do over here. So, you have things
  2340. 1:23:00like equal, which we do with double uh
  2341. 1:23:03equals. So, remember the assignment of a
  2342. 1:23:05variable is with one equal sign. But if
  2343. 1:23:10we do two equal signs, we actually form
  2344. 1:23:13a comparison. So if we let's let's again
  2345. 1:23:16let's set this to 18 and then let's see
  2346. 1:23:20we make another like we do is 18 is a
  2347. 1:23:23variable and then we check whether age
  2348. 1:23:26is equal to 18. So we set the age now
  2349. 1:23:29it's 18 look then we perform this it's
  2350. 1:23:32true. Now we do this not true. So these
  2351. 1:23:35are ways that we can perform really any
  2352. 1:23:38type of comparison that you want to
  2353. 1:23:40make. So coming back over here, is it
  2354. 1:23:42equal to? We can also is it not equal
  2355. 1:23:44to? So we invert it. We do that using an
  2356. 1:23:47exclamation mark. Then we have greater
  2357. 1:23:49and less than. So we could use greater
  2358. 1:23:51than 20, less than 30 or greater than or
  2359. 1:23:54equal or less or equal. So these are all
  2360. 1:23:57the types of common operators, right? If
  2361. 1:23:59you ever built some kind of like logic
  2362. 1:24:02or worked with a program or worked with
  2363. 1:24:04something like sapier or make.com or nat
  2364. 1:24:06these are very common operations and
  2365. 1:24:08this is just a way this is just a python
  2366. 1:24:11syntax to write that out. So this is
  2367. 1:24:13something you won't remember right now.
  2368. 1:24:15So this is always something you have to
  2369. 1:24:17refer to. That's also really one why I
  2370. 1:24:19wanted to create this handbook. So you
  2371. 1:24:20can bookmark this and whenever you're
  2372. 1:24:22working with variables you can come here
  2373. 1:24:24in here check it out or of course simply
  2374. 1:24:27ask AI and it will also tell you what to
  2375. 1:24:30do. Okay, so those are booleans and
  2376. 1:24:32again as with any section if you're
  2377. 1:24:34running into errors make sure you check
  2378. 1:24:36out the common mistakes. All right and
  2379. 1:24:38up next we are going to the section
  2380. 1:24:40working with data. So we already covered
  2381. 1:24:43the math, right? The arithmetic
  2382. 1:24:44operators to do simple math and to
  2383. 1:24:47perform calculations. And one thing you
  2384. 1:24:49should know about Python is that it it
  2385. 1:24:52follows the same rules really when it
  2386. 1:24:54comes to arithmetics that you would use
  2387. 1:24:57and on your math math exams in high
  2388. 1:24:59school, right? Or when you're using a
  2389. 1:25:00calculator. So for example, the
  2390. 1:25:03multiplication becomes for an addition.
  2391. 1:25:05So this will be 14 and not 20. And if
  2392. 1:25:07you use parentheses, that's how you can
  2393. 1:25:09prioritize certain operations to do them
  2394. 1:25:12before. So, similar to what it was like
  2395. 1:25:14with math in Python, it works the same
  2396. 1:25:16way. Then we have the comparison
  2397. 1:25:17operators, which I just shown you. And
  2398. 1:25:20feel free to stop here and take some
  2399. 1:25:22time to play with these. I'm quickly
  2400. 1:25:24going over this because I want to get to
  2401. 1:25:26the logical operators because we can
  2402. 1:25:29also combine boolean values and
  2403. 1:25:31conditions and we can even include the
  2404. 1:25:34words and and or. So let's have a look
  2405. 1:25:36at what that looks like. So let me
  2406. 1:25:39actually take this snippet over here and
  2407. 1:25:41we're going to play with that. So let's
  2408. 1:25:43see over here we have h equals 25 and
  2409. 1:25:46let me actually I can zoom out and I can
  2410. 1:25:48clear all of this for you and then zoom
  2411. 1:25:50in a little bit. So we have age is 25.
  2412. 1:25:53We have a license which is true. And now
  2413. 1:25:56we perform a check and we want to
  2414. 1:25:57perform a check and both must be true.
  2415. 1:26:00So to determine whether someone can
  2416. 1:26:03drive both the age needs to be like in
  2417. 1:26:05the US needs to be greater or equal than
  2418. 1:26:0816 and also has a license should be true
  2419. 1:26:11and this is also one of the cool things
  2420. 1:26:12about Python right because look at how
  2421. 1:26:15easily we can read this it's almost pure
  2422. 1:26:18English so let's go through this can
  2423. 1:26:20drive we set that equal to and then we
  2424. 1:26:23perform the first operation so age is
  2425. 1:26:25greater than or equal to 60 is that the
  2426. 1:26:28case it's 25. So let's check that. Let's
  2427. 1:26:32just run this line. That is true. Okay.
  2428. 1:26:35Now we see end over here. And we have
  2429. 1:26:38has license. So has license is set to
  2430. 1:26:41true. So what now will happen if we use
  2431. 1:26:44the end? This line over here. This will
  2432. 1:26:48output true if both of the clauses in
  2433. 1:26:52here are true, which is the case. So if
  2434. 1:26:54I now run this, you'll find that this is
  2435. 1:26:56true. And if we then print can drive it
  2436. 1:26:59will be set to true. But if we now set
  2437. 1:27:02this to false. So someone is 25. So they
  2438. 1:27:06are still over 16 true but has a license
  2439. 1:27:09is false. And now we run this and print
  2440. 1:27:13can drive is false. So you can see how
  2441. 1:27:15we can now start to build this logic
  2442. 1:27:17right. And similar we can also do or and
  2443. 1:27:20this means it's either one of the two
  2444. 1:27:23should be true. So if we do it like
  2445. 1:27:25this, they can still drive because
  2446. 1:27:27they're 16. This is maybe in like some
  2447. 1:27:29weird country or state where you can
  2448. 1:27:31either have a license or 16 and you're
  2449. 1:27:33good to go. So coming back to the
  2450. 1:27:35examples over here, you'll find that you
  2451. 1:27:38can combine these in all kinds of ways.
  2452. 1:27:40So whenever you're trying to solve a
  2453. 1:27:42problem, even if you want to stack 10
  2454. 1:27:45conditions and very complex combinations
  2455. 1:27:48of all kinds of variables that you can
  2456. 1:27:50think about using all of these operators
  2457. 1:27:53equal to, greater than, and or and using
  2458. 1:27:56these truth tables and understanding how
  2459. 1:27:59they work, you can see that you can
  2460. 1:28:01almost like create any kind of
  2461. 1:28:02decision-making logic. So go through
  2462. 1:28:04this and here can here you see
  2463. 1:28:06understanding the truth table. So that
  2464. 1:28:07this is what I was going uh for true and
  2465. 1:28:10true will be true and this is using the
  2466. 1:28:12and this is using the or and not is
  2467. 1:28:14another one. So this is how you can flip
  2468. 1:28:16it. So let me actually show you what
  2469. 1:28:18that looks like. So let's see if set has
  2470. 1:28:21a license is set to true. Let's see.
  2471. 1:28:23Let's do that. I can also now for
  2472. 1:28:25example do not has license. And now if I
  2473. 1:28:28run this this will say false because has
  2474. 1:28:31a license is true. And when when I
  2475. 1:28:32invert that it turns into false. So
  2476. 1:28:35let's do another example here. Let's do
  2477. 1:28:36drunk. Let's say drunk is equal to true.
  2478. 1:28:41So can drive now becomes age should be
  2479. 1:28:44greater than or equal than 16 and has
  2480. 1:28:50license. And here's the thing. You can
  2481. 1:28:52also do equals true. But you don't need
  2482. 1:28:55to do this. So this is like as you type
  2483. 1:28:58it out, you might want to do this. But
  2484. 1:29:00since has license is already a boolean
  2485. 1:29:02value, you don't have to make a direct
  2486. 1:29:05comparison with this. But both will
  2487. 1:29:07work. But let's for the sake of
  2488. 1:29:08simplicity leave it out. And then also
  2489. 1:29:11we do the third clause in there. We
  2490. 1:29:13literally say and not drunk. Okay. So
  2491. 1:29:17now what you can see over here, let me
  2492. 1:29:19actually zoom out a little bit so you
  2493. 1:29:21can see everything. Now if I run this
  2494. 1:29:23can drive like make sure we have
  2495. 1:29:25everything in here in memory. Now you
  2496. 1:29:28can see if we run this and then we do
  2497. 1:29:30can't drive is false because they're
  2498. 1:29:32drunk. They're 25. They have a license
  2499. 1:29:35but they're drunk and they cannot drive.
  2500. 1:29:36If we do it in false, they can't drive.
  2501. 1:29:38Now here was one more Python trick that
  2502. 1:29:40you'll often encounter. There are also
  2503. 1:29:42shortcut assignments. So when you have a
  2504. 1:29:45score, let's say score is 10. So I come
  2505. 1:29:47in here, let's clear everything out.
  2506. 1:29:49Let's say score equals 10. And you want
  2507. 1:29:53to add something to that. You could say
  2508. 1:29:55score equals score. and then we add
  2509. 1:29:58five. So now score will be 15. You can
  2510. 1:30:01also directly do score plus equals five.
  2511. 1:30:05And then we add another five to the
  2512. 1:30:07score and now it's 20. And we can do
  2513. 1:30:09this over and over and over again. So if
  2514. 1:30:11I run this a couple of times, you can
  2515. 1:30:13now see score is 90. So this is a simple
  2516. 1:30:16shortcut assignment where we don't have
  2517. 1:30:17to do this redundant like score equals
  2518. 1:30:19score + 5, but we can do it directly and
  2519. 1:30:22this works with almost all math
  2520. 1:30:25operators. All right. So, those were
  2521. 1:30:26some common operators. Now, let's get to
  2522. 1:30:29into the string manipulation. And I want
  2523. 1:30:31to show you two more things when it
  2524. 1:30:34comes to working with strings that can
  2525. 1:30:36be that are very useful, especially when
  2526. 1:30:38you're working with AI and when you're
  2527. 1:30:40working with prompts. So, we already saw
  2528. 1:30:42that you can use the plus sign, right?
  2529. 1:30:44But now I want to show you frings. So,
  2530. 1:30:47let's see what they are and why they are
  2531. 1:30:50so common in uh when you're working with
  2532. 1:30:52AI and language models. So let's say we
  2533. 1:30:53have our string and let's say we have uh
  2534. 1:30:56let's say we do hi there my name is
  2535. 1:31:01Dave. We can run this. We have the
  2536. 1:31:04string and we have their hi name there
  2537. 1:31:05my name is Dave. But let's say you have
  2538. 1:31:07a program and you don't want to hardcode
  2539. 1:31:10this name but you want to do it based on
  2540. 1:31:13the username right? So let's say name
  2541. 1:31:15equals Dave and then oh I should put
  2542. 1:31:18that in quotes right to make it a
  2543. 1:31:20string. How can we now make this in such
  2544. 1:31:22a way where we make this dynamic and we
  2545. 1:31:25replace this with the variable over
  2546. 1:31:27here? So now depending on who is
  2547. 1:31:30interacting with the system, it will
  2548. 1:31:32give them a different greeting. And this
  2549. 1:31:34is used all the times when you are
  2550. 1:31:37working with AI models and prompts, you
  2551. 1:31:38want to dynamically inject information
  2552. 1:31:40that you retrieve from another system,
  2553. 1:31:42store that in a variable and then put it
  2554. 1:31:44in a string. So the way we do that in
  2555. 1:31:47Python is through what they call
  2556. 1:31:49fstrings. And this is again this this is
  2557. 1:31:52now a syntax thing because this is just
  2558. 1:31:54something you need to remember. There's
  2559. 1:31:56not really any logic behind it, but it's
  2560. 1:31:58called fstrings. And we literally put an
  2561. 1:32:00F before it. So you have the string, you
  2562. 1:32:02have the quotes, and you just put an F
  2563. 1:32:04in here. And when we plug that F in
  2564. 1:32:06here, what we can now do is we can come
  2565. 1:32:08in here and we can use curly brackets
  2566. 1:32:11and we can now plug in any variable. So
  2567. 1:32:15you can now see that this is a string
  2568. 1:32:17and it's not giving us any errors. And
  2569. 1:32:19if I now run this and I print this, you
  2570. 1:32:21will see that if I move my oh wait, let
  2571. 1:32:24me actually move myself to the left side
  2572. 1:32:27so you can actually see something. So
  2573. 1:32:29here you can now see my name is Dave.
  2574. 1:32:31And if we change this to I don't know
  2575. 1:32:34John and we run this you'll find that
  2576. 1:32:36the string is now hi there my name is
  2577. 1:32:39John. So that's the notion of fstrings.
  2578. 1:32:42Super useful. And let's see if I for
  2579. 1:32:45example get rid of this you can see
  2580. 1:32:47right now if I run this and print it you
  2581. 1:32:50can see that it literally like hardcodes
  2582. 1:32:52the curly brackets in here. It it will
  2583. 1:32:54be orange. So it will Python will
  2584. 1:32:56indicate that it recognizes that you
  2585. 1:32:58want to do something there but it will
  2586. 1:33:00literally just print it out exactly as
  2587. 1:33:02is. So that's why you need to put the f
  2588. 1:33:04there and then it works. Now then
  2589. 1:33:06another thing that I want you to know
  2590. 1:33:08about strings is that in Python you have
  2591. 1:33:11a lot of what they call string methods.
  2592. 1:33:14So these are methods functions that you
  2593. 1:33:17can apply to a string and it will
  2594. 1:33:20perform an action. And the way you do
  2595. 1:33:22this is so here's an example. So you
  2596. 1:33:24have text, you have the string in here
  2597. 1:33:26and instead of putting it before it, so
  2598. 1:33:29print and then using the the brackets,
  2599. 1:33:31you directly take the string variable,
  2600. 1:33:33you do a dot and then you apply the
  2601. 1:33:36string method by typing out the method
  2602. 1:33:38and then using the brackets in here. So
  2603. 1:33:40let's follow uh let's follow along with
  2604. 1:33:42this to get a feel for what that is. So
  2605. 1:33:45let's say let's come over here. We have
  2606. 1:33:47Dave and we can do name. We do dot lower
  2607. 1:33:51and then we do the parenthesis. And now
  2608. 1:33:54you can see this is my name in lowerase.
  2609. 1:33:56But I can also do my name in uppercase.
  2610. 1:34:00Let's see in uppercase. And I can even
  2611. 1:34:03do let's say if we have a sentence. So
  2612. 1:34:05you could for example do sentence equals
  2613. 1:34:09hi my name is Dave. You can even do a
  2614. 1:34:14title. So you can do sentence.title
  2615. 1:34:17and then it will apply title case if I
  2616. 1:34:19store it in memory. And there we go. So
  2617. 1:34:22you can see it will capitalize all of
  2618. 1:34:24the first letters. So these are called
  2619. 1:34:26string methods. And I'm going to show
  2620. 1:34:28you one more example over here. I'm not
  2621. 1:34:30going to walk through everything but you
  2622. 1:34:32can even see if you have this message
  2623. 1:34:34over here. So I love the Python
  2624. 1:34:35programming language. We can also for
  2625. 1:34:38example uh create some boolean logic
  2626. 1:34:40around this where we can say starts with
  2627. 1:34:43ends with and that gives us true or
  2628. 1:34:45false values. We can find certain
  2629. 1:34:48phrases within a sentence. We can count
  2630. 1:34:50the occurrence or number of times Python
  2631. 1:34:53is occurring in this message and we can
  2632. 1:34:55even replace certain parts. So here if
  2633. 1:34:58we have the message and we replace
  2634. 1:34:59Python with JavaScript it will now print
  2635. 1:35:03I love JavaScript programming with
  2636. 1:35:05JavaScript. now and I totally understand
  2637. 1:35:06that that is a lot of information right
  2638. 1:35:08and you definitely don't need to
  2639. 1:35:10remember all of that like even I often
  2640. 1:35:13have to look up these things like oh
  2641. 1:35:14what was it again like there's something
  2642. 1:35:16in Python with starts with and ends with
  2643. 1:35:18these are such niche use cases that when
  2644. 1:35:22you need them all you need to know is
  2645. 1:35:24that Python has a lot of functionality
  2646. 1:35:26out of the box to solve common problems
  2647. 1:35:28so whenever you're dealing with
  2648. 1:35:30something there is a high chance that
  2649. 1:35:32you don't need to come up with the
  2650. 1:35:33entire logic yourself or create a really
  2651. 1:35:36complex function, you can first just ask
  2652. 1:35:38chatbt and say, "Look, I'm trying to
  2653. 1:35:40solve this problem. I need to I have
  2654. 1:35:42this sentence and I need to understand
  2655. 1:35:43if it if it starts with this and then I
  2656. 1:35:45want to replace a certain part and JGPT
  2657. 1:35:47will literally give you the most
  2658. 1:35:49effective way to do it through a
  2659. 1:35:50combination of all of these methods that
  2660. 1:35:53I just shared." So the goal really is to
  2661. 1:35:55get you familiar with what you can do
  2662. 1:35:57with data. What are string methods? What
  2663. 1:35:59is the notation? seeing them, walking
  2664. 1:36:01through them, and just getting a feel
  2665. 1:36:03for how this programming language works
  2666. 1:36:05is really the goal at this point, not to
  2667. 1:36:07fully understand and remember
  2668. 1:36:09everything. That's important to keep in
  2669. 1:36:10mind. All right. And now we get into the
  2670. 1:36:12section control flow. So, how can we
  2671. 1:36:15actually make decisions within our
  2672. 1:36:17program, right? We've already we already
  2673. 1:36:19saw that we can use true and false and
  2674. 1:36:21we can do calculations. But now whenever
  2675. 1:36:23we're building programs, we need to do
  2676. 1:36:26something like look if at an ATM a
  2677. 1:36:28password is correct then we allow
  2678. 1:36:30access. If not we give an error. If a
  2679. 1:36:33user clicks on a button only then we
  2680. 1:36:36perform an action. In a game if the
  2681. 1:36:38health is equal to zero it's game over.
  2682. 1:36:41Otherwise we can continue. And within
  2683. 1:36:43programming we do this through what you
  2684. 1:36:46call if statements. So let's run through
  2685. 1:36:48some examples. So let's say we have a
  2686. 1:36:51temperature and we set that equal to 25.
  2687. 1:36:55Now what we can do is we can build a
  2688. 1:36:57system that based on the temperature
  2689. 1:37:00does either a certain action when it's
  2690. 1:37:02above a threshold or something else when
  2691. 1:37:04it's below a threshold. So we can simply
  2692. 1:37:06start by saying look if the temperature
  2693. 1:37:09is greater than 25 we now use a colon
  2694. 1:37:15and we get to the next line. This is
  2695. 1:37:17something new. We haven't done this. So
  2696. 1:37:19we introduce the if statement which is
  2697. 1:37:21an operator that we can use. An if
  2698. 1:37:23statement always just starts with the
  2699. 1:37:25if. Then we have the conditional logic
  2700. 1:37:27over here and then when we end that
  2701. 1:37:29logic we do a colon, we do a enter and
  2702. 1:37:32then we get to the next line and here we
  2703. 1:37:34use an indentation. This is very
  2704. 1:37:36specific to Python. So it goes to the
  2705. 1:37:39next line and what's doing uh what it's
  2706. 1:37:41doing behind the scenes. You can see in
  2707. 1:37:43the highlight over here it's adding four
  2708. 1:37:45spaces. Now our code editor is doing
  2709. 1:37:48this automatically for us because it
  2710. 1:37:50understands the Python programming
  2711. 1:37:51language and it understands what it
  2712. 1:37:53does. So just so you know that's what's
  2713. 1:37:55going on behind the scenes. And now what
  2714. 1:37:57we can do is we can for example write a
  2715. 1:37:59print statement over here where we say
  2716. 1:38:01it's hot. If we run this nothing will
  2717. 1:38:05happen. And that is because the
  2718. 1:38:06temperature is equal to 25. If we set it
  2719. 1:38:09to 26 and we run this it will say it's
  2720. 1:38:13hot. Remember right similar to the
  2721. 1:38:15example I gave about the customer care.
  2722. 1:38:17Do we need to escalate it to a human?
  2723. 1:38:19Yes or no. This is it's a similar type
  2724. 1:38:21of logic. So let's set it back to 25.
  2725. 1:38:24Nothing will happen. Now let's create
  2726. 1:38:26another case. So what we can now do is
  2727. 1:38:29we can now go back. So we exit out of
  2728. 1:38:31this if statement and we continue with
  2729. 1:38:33an else statement. And now here we don't
  2730. 1:38:36have to specify any logic because this
  2731. 1:38:38will simply execute in all other cases.
  2732. 1:38:42And then we say print it's nice weather.
  2733. 1:38:46Now if I run this it will say it's nice
  2734. 1:38:49weather because if we follow the order
  2735. 1:38:51of operations which in Python will be
  2736. 1:38:54from top to bottom and from left to
  2737. 1:38:57right it will first check if the
  2738. 1:38:59temperature is greater uh if the
  2739. 1:39:01temperature is greater than 25 it will
  2740. 1:39:02print it. This is not the case. Okay.
  2741. 1:39:04Now we go into the else condition. This
  2742. 1:39:07will always run. If this is not true
  2743. 1:39:09this will run. That is how it is
  2744. 1:39:12currently set up. It's it's a boolean
  2745. 1:39:14boolean decision-making logic. And now
  2746. 1:39:15the syntax here with if and then a colon
  2747. 1:39:18and an else and then nothing there and
  2748. 1:39:19another colon is just one of those
  2749. 1:39:21things. You just have to see it and do
  2750. 1:39:23it a couple of times before it clicks.
  2751. 1:39:25But let's say you want to add more
  2752. 1:39:26conditions to the mix. So actually what
  2753. 1:39:29we want to do is say look if the
  2754. 1:39:32temperature is greater than 25 we say
  2755. 1:39:34it's uh it's hot. But we can also say if
  2756. 1:39:38the temperature is greater than 30, we
  2757. 1:39:42say it's very hot. And now what we do in
  2758. 1:39:48here, if we if we set it up like this,
  2759. 1:39:50we have an if statement and then another
  2760. 1:39:52if statement. And let's see, let's
  2761. 1:39:55actually put this at 24. What will
  2762. 1:39:58happen right now? You'll find that
  2763. 1:40:00currently it will say it's nice weather.
  2764. 1:40:03But then if we put this to 31 and we run
  2765. 1:40:07this, you'll find that it's both running
  2766. 1:40:09is very hot and it's hot. But we in this
  2767. 1:40:12case we don't want that because we want
  2768. 1:40:14it to be either one of the decision-m
  2769. 1:40:17points. So for that Python has something
  2770. 1:40:19else and that's called an L if. So here
  2771. 1:40:22we can chain things together. So it will
  2772. 1:40:24first check if the temperature is
  2773. 1:40:27greater than 30 and if that is the case
  2774. 1:40:29it will print is very hot and then it
  2775. 1:40:32knows that it can end the loop. So it
  2776. 1:40:34will not check for this. So what this
  2777. 1:40:36looks like is now it will say it's very
  2778. 1:40:38hot even though this condition is also
  2779. 1:40:41true. It will not get to that because of
  2780. 1:40:44how we structured it. So another example
  2781. 1:40:46over here is uh here another chain and
  2782. 1:40:49you can also use multiple alifs. you can
  2783. 1:40:51actually chain them together. So let's
  2784. 1:40:53say we have a score and if we say if
  2785. 1:40:56it's uh greater or equal to 90 we say a
  2786. 1:40:58excellent here we we get a B here we get
  2787. 1:41:01a C here it needs improvement. So let me
  2788. 1:41:04actually copy paste this to see what
  2789. 1:41:06this looks like. So now with 85 you get
  2790. 1:41:09a B and if you have a 90 you get
  2791. 1:41:12excellent. So remember the order of
  2792. 1:41:14operations right from top to bottom from
  2793. 1:41:16left to right and if we use an if l if
  2794. 1:41:18chain the script will stop once one of
  2795. 1:41:21the conditions is true and if it gets
  2796. 1:41:23through everything and there is none of
  2797. 1:41:25these conditions is true it will always
  2798. 1:41:28execute the else statement. This is
  2799. 1:41:29something you have to get used to but
  2800. 1:41:31this is really the bread and butter of
  2801. 1:41:34building programs. You take in the data
  2802. 1:41:37whatever type of data type it is whe
  2803. 1:41:39whether it's a number a boolean or a
  2804. 1:41:42number you combine that into some kind
  2805. 1:41:44of like variables and you apply some
  2806. 1:41:46operations and then you want to do stuff
  2807. 1:41:48with it. If it's this we do that if we
  2808. 1:41:50get to here then we execute this
  2809. 1:41:52function. If the escalation is true we
  2810. 1:41:55we make sure we get a real human in the
  2811. 1:41:57loop. Really the fundamental building
  2812. 1:42:00blocks of how you build systems and how
  2813. 1:42:02you put something together in a
  2814. 1:42:04programming language. Now the nice thing
  2815. 1:42:06is that everything we've learned up
  2816. 1:42:07until this point can also be re
  2817. 1:42:10reapplied and combined. Right? So here
  2818. 1:42:12when you're using if else statements we
  2819. 1:42:14can also use the and or and not
  2820. 1:42:17operators to determine the boolean
  2821. 1:42:19logic. So similar to how we were first
  2822. 1:42:22looking at age and license and we're
  2823. 1:42:24just printing what it was. We can also
  2824. 1:42:27create if else statements around this
  2825. 1:42:29and combine them in those two. So just
  2826. 1:42:32to showcase that to you, you can come in
  2827. 1:42:34here and here this will print you can
  2828. 1:42:37drive and if we put put it to 12. So
  2829. 1:42:40this is a 12y old we cannot drive. If we
  2830. 1:42:43want to let the program know that this
  2831. 1:42:45is not possible we can print this and we
  2832. 1:42:48will say you cannot drive. Now we run
  2833. 1:42:51this and it will go and we can put any
  2834. 1:42:53type of l if statements in between. And
  2835. 1:42:56now with if else statements we can even
  2836. 1:42:58do nested conditions. So we can for
  2837. 1:43:00example say if has ticket and then we go
  2838. 1:43:03to the next line but we also say if age
  2839. 1:43:07greater or equal to 18 we print enjoy
  2840. 1:43:12the movie and then we do an else
  2841. 1:43:14statement in here so they have a ticket
  2842. 1:43:16but they're not 18. we print needs
  2843. 1:43:19supervision
  2844. 1:43:21and then we can come in here all the way
  2845. 1:43:23to the end and then add another print
  2846. 1:43:25statement and say please buy a ticket.
  2847. 1:43:30So now you can see someone's 15 has a
  2848. 1:43:32ticket they need supervision. Whenever
  2849. 1:43:35they're 18 they can enjoy the movie.
  2850. 1:43:37When they don't have a ticket they need
  2851. 1:43:39to buy a ticket. Now the next concept
  2852. 1:43:42that we will cover in the control flow
  2853. 1:43:44section is the notion of loops where we
  2854. 1:43:47can repeat code multiple times. So this
  2855. 1:43:49is often something that you need to do
  2856. 1:43:51when you're building programs. And for
  2857. 1:43:53example, let's say you want to do
  2858. 1:43:54something like this. You want to perform
  2859. 1:43:55an operation five times. Instead of
  2860. 1:43:58writing this out in your program, which
  2861. 1:44:00is which is really for verbose, we can
  2862. 1:44:02create a loop around this which is much
  2863. 1:44:04cleaner and much shorter. The most
  2864. 1:44:06common way to like do this is using a
  2865. 1:44:09for loop. So let's give an example of
  2866. 1:44:12this. And again there is a specific
  2867. 1:44:14syntax that we need to understand in
  2868. 1:44:16here. So let's clear this up. When we do
  2869. 1:44:19a four, we start with four. That's why
  2870. 1:44:22it's called a for loop. And we select a
  2871. 1:44:26counter in here. And this is one of
  2872. 1:44:28those things in the beginning it's a
  2873. 1:44:29little bit tricky because this can
  2874. 1:44:30pretty much be anything. But let's take
  2875. 1:44:32i for now. But we can also put x. And we
  2876. 1:44:34can also put whatever in here. But a
  2877. 1:44:37common way if you want to create a
  2878. 1:44:38counter is I because it's really short.
  2879. 1:44:40And then we say for i in and then in
  2880. 1:44:43this case we can give it a range. And
  2881. 1:44:45let's say we give it five. We can then
  2882. 1:44:47do something like print and then we do
  2883. 1:44:49i. So in this case if I run this you
  2884. 1:44:52will see that we'll print 0 to four in
  2885. 1:44:54this case. Here is there's a lot going
  2886. 1:44:56on in here because right now like up
  2887. 1:44:58until this point you probably were like
  2888. 1:44:59okay Dave I can follow all of this but
  2889. 1:45:01this this is not plain English. This is
  2890. 1:45:03weird. Why does it start with zero?
  2891. 1:45:05First of all, one thing to keep in mind
  2892. 1:45:07is that Python is a uh zero index-based
  2893. 1:45:11programming language. Meaning that
  2894. 1:45:13Python starts to count from zero. This
  2895. 1:45:16is something that we will also encounter
  2896. 1:45:18later when we're working with lists and
  2897. 1:45:20indexes. If you want to get the first
  2898. 1:45:22element, we say we want element zero
  2899. 1:45:24instead of element one. That's why you
  2900. 1:45:27see zero over here. And what we are
  2901. 1:45:30essentially doing here is we're creating
  2902. 1:45:33an iteration where we say look for i in
  2903. 1:45:37range five and range five is a range
  2904. 1:45:40where we say look we start with zero and
  2905. 1:45:42then we go to one to two to three to
  2906. 1:45:44four and then we stop. It's syntax. It's
  2907. 1:45:46a notation. It's something you have to
  2908. 1:45:48get used to. And then we perform an
  2909. 1:45:50operation. And in this case we use i. So
  2910. 1:45:52we use the counter uh variable here as
  2911. 1:45:55well. But we can also for example print
  2912. 1:45:58hello world and then if we run this it
  2913. 1:46:00will just simply five times print hello
  2914. 1:46:03world. But the i refers to the counter
  2915. 1:46:05in here. But let's get back to the docs
  2916. 1:46:07over here and see what's going on over
  2917. 1:46:09here. So again python starts counting at
  2918. 1:46:12zero not at one. It's called zero
  2919. 1:46:13indexing. And you can also count from
  2920. 1:46:15different starting points. So just this
  2921. 1:46:17is just a way of repeating things over
  2922. 1:46:19and over again. We can do it through
  2923. 1:46:21numbers by giving a range let's say 1 to
  2924. 1:46:24six. uh we can even count with steps of
  2925. 1:46:27two all things that are possible. So let
  2926. 1:46:30me actually run this over here to give
  2927. 1:46:32you an example for for uh what that
  2928. 1:46:34means. So before we had five, right? So
  2929. 1:46:38we said range five and then we print
  2930. 1:46:41everything. But we can also say look we
  2931. 1:46:43want to go from one to six and then
  2932. 1:46:46you'll find that it will print 1 to five
  2933. 1:46:48because it will stop before six. That's
  2934. 1:46:50just the way it works. And that's one
  2935. 1:46:52thing like right now you're probably
  2936. 1:46:54wondering like oh it's a little bit
  2937. 1:46:55tricky so you start at zero and you put
  2938. 1:46:57in six but you actually go to five even
  2939. 1:47:00I to this date whenever I do four loops
  2940. 1:47:02um you're always tinkering with this so
  2941. 1:47:04what you end up doing is you're
  2942. 1:47:06experimenting with this and you oh wait
  2943. 1:47:08no I actually want to get to to six so I
  2944. 1:47:10plug in seven then you correct it and
  2945. 1:47:13that's the iterative process right
  2946. 1:47:15that's also what I love about using the
  2947. 1:47:17interactive session it's so fast you can
  2948. 1:47:19select bits and pieces and continue. And
  2949. 1:47:22then here you have, you can see we add
  2950. 1:47:24another variable to it. So we say we
  2951. 1:47:26want to go from zero. We want to start
  2952. 1:47:29at zero. We want to go to 10, but we
  2953. 1:47:31want to do it in steps of two. And then
  2954. 1:47:33what you'll find is that it will go from
  2955. 1:47:350 to 2 to 4 to 6 to 8. So that's
  2956. 1:47:39something we can also do with the range
  2957. 1:47:41function. And there are more components
  2958. 1:47:43to it. But that's just enough for now to
  2959. 1:47:46understand. Look, if we want to do
  2960. 1:47:47things over and over and over again, we
  2961. 1:47:50don't want to do this. That's the
  2962. 1:47:53takeaway for this section. And that's
  2963. 1:47:55all for now. All right. And that brings
  2964. 1:47:57us to data structures. So how we can
  2965. 1:48:00store multiple values together. So up
  2966. 1:48:03until this point, we have stored one
  2967. 1:48:05value per variable, right? So we were
  2968. 1:48:07talking about the numbers, we were
  2969. 1:48:09talking about the strings and the
  2970. 1:48:10boolean values. But what if you need to
  2971. 1:48:12store multiple values? So you want to
  2972. 1:48:14create a collection and put them
  2973. 1:48:15together. That's where data structures
  2974. 1:48:18come in. So these are like containers
  2975. 1:48:20and they come in the form of lists like
  2976. 1:48:23a shopping list ordered items. So I want
  2977. 1:48:25this, this, this, and I also want
  2978. 1:48:27bananas in there and I also want apples
  2979. 1:48:29or a dictionary. These have key value
  2980. 1:48:32pairs. So it could be like a phone book.
  2981. 1:48:34So you have a name and there is a number
  2982. 1:48:36associated to it. So they come in pairs
  2983. 1:48:38and then you have what is called tupils.
  2984. 1:48:40These are fixed. So you create them once
  2985. 1:48:42and you can't really mess with them. So
  2986. 1:48:44for example like coordinates and then
  2987. 1:48:46you have sets. These are a bag of unique
  2988. 1:48:48items. So you can take a whole lot of
  2989. 1:48:51information and you just get rid of all
  2990. 1:48:53the duplicates. So you only have the
  2991. 1:48:54unique values in there. Those are the
  2992. 1:48:56common data structures that you'll use
  2993. 1:48:58within the Python programming language.
  2994. 1:49:00So let's start with lists which is
  2995. 1:49:02actually a really common one. You'll use
  2996. 1:49:04this all the time. So, we're going to
  2997. 1:49:07start with the syntax and that is as
  2998. 1:49:11follows. So, we're going to clear this
  2999. 1:49:12up and we're going to say my list
  3000. 1:49:15equals. So, spell that out correctly. My
  3001. 1:49:18list equals and now here comes the
  3002. 1:49:19syntax. We use brackets, square
  3003. 1:49:22brackets, not the curly brackets. That's
  3004. 1:49:24for the dictionaries we'll use later.
  3005. 1:49:26We'll use square brackets. Now, this is
  3006. 1:49:29the container in which we can start to
  3007. 1:49:31put stuff. And Python is really
  3008. 1:49:34flexible. So you can literally view this
  3009. 1:49:37as some kind of bag or container and we
  3010. 1:49:39can dump all types of stuff in it. So
  3011. 1:49:42remember we had Alice, right? We can
  3012. 1:49:44dump Alice in here. Alice is a string,
  3013. 1:49:46but we can also plug in 25. Um we can
  3014. 1:49:50also say look we have uh h equals 25.
  3015. 1:49:53And now next to 25 we also actually plug
  3016. 1:49:56in the h which is now a variable. But we
  3017. 1:49:59can also plug in actually true. And you
  3018. 1:50:02know what? We also uh had the has
  3019. 1:50:05license uh which in this case is false
  3020. 1:50:09and now we plug that in and that's all
  3021. 1:50:12totally fine if we store it in memory
  3022. 1:50:15and then run it. So let me clear this up
  3023. 1:50:17to get rid of the errors. So now we have
  3024. 1:50:19a list all types of different data
  3025. 1:50:21formats and data types that are in
  3026. 1:50:23there. That's the beauty of Python is
  3027. 1:50:25really flexible uh and it doesn't really
  3028. 1:50:27care about that. Now whenever we have a
  3029. 1:50:29list we often want to do something with
  3030. 1:50:32that. So now we have this list and now
  3031. 1:50:34we can index this list. So let's say
  3032. 1:50:37you're working on a problem you have
  3033. 1:50:38this container and you want to take
  3034. 1:50:40Alice out of that list or whatever the
  3035. 1:50:43that element is. Lists are ordered
  3036. 1:50:46meaning that how you store it in this
  3037. 1:50:49way will like Python will remember and
  3038. 1:50:53through this we can access certain
  3039. 1:50:56indexes of this list to grab information
  3040. 1:50:59out of it and we do that in a similar
  3041. 1:51:01way using the square brackets but now
  3042. 1:51:04directly on the list variable itself. So
  3043. 1:51:07we can now do the square brackets and
  3044. 1:51:09now we're going to index things. So a
  3045. 1:51:12couple of minutes ago I explained how
  3046. 1:51:14Python is a um zero B uses a zerobased
  3047. 1:51:17index. So it starts at zero. So that
  3048. 1:51:20means if we want to grab Alice out of
  3049. 1:51:22here we do a zero and that will give us
  3050. 1:51:25Alice. So we could for example say name
  3051. 1:51:28is equal to my list and then we take the
  3052. 1:51:30first element. Now that is Alice. Now we
  3053. 1:51:33can set H equals my list and then we
  3054. 1:51:37take the second element but we index it
  3055. 1:51:39with one. And now we get 25 and so on.
  3056. 1:51:43We can go on and on and on. And also
  3057. 1:51:45what what you can also do is you can
  3058. 1:51:47also say look what if we want the last
  3059. 1:51:49we want the last item but like what is
  3060. 1:51:51it? Is it like three four five? Python
  3061. 1:51:53has a way uh to do this. So this is
  3062. 1:51:55actually like has license. So we can say
  3063. 1:51:57let's say the license equals oh look and
  3064. 1:52:00here actually this is interesting. we
  3065. 1:52:02get a blue uh highlight over here
  3066. 1:52:05meaning that there could be a problem
  3067. 1:52:07where this is an internal uh variable
  3068. 1:52:10that Python is using. Now in this case
  3069. 1:52:11we should be fine. Uh but let's actually
  3070. 1:52:14like override it with has license. So
  3071. 1:52:16sometimes you have that for example when
  3072. 1:52:17you write print that's that's something
  3073. 1:52:20that we can use inside Python internally
  3074. 1:52:22and that's often not how you want to
  3075. 1:52:23name your variables. So that's just a
  3076. 1:52:25quick side note. So we can now say my
  3077. 1:52:27list and I was explaining that how we
  3078. 1:52:29can get the last element. We can do a
  3079. 1:52:31minus one. So we can also refers the
  3080. 1:52:34index. So you can now see we get to has
  3081. 1:52:36license. We can also do minus2 and that
  3082. 1:52:39will give us the true which should be
  3083. 1:52:42true. And then we can even get minus
  3084. 1:52:43three. So there are multiple ways like
  3085. 1:52:46forward or backward to work with the
  3086. 1:52:49list and to get elements out of it. Now
  3087. 1:52:52next to grabbing single items that we
  3088. 1:52:54just saw, we can also take slices. So we
  3089. 1:52:57can also specify a range using the
  3090. 1:52:59colon. Now next to storing information
  3091. 1:53:02in a list and then grabbing something
  3092. 1:53:03from it. We can also over overwrite data
  3093. 1:53:07in a list we can add to it. We can grab
  3094. 1:53:09from it. We can remove things. So let's
  3095. 1:53:11walk through some common operators in
  3096. 1:53:13here. So let's say we have the list and
  3097. 1:53:15we say my list and now we say look we
  3098. 1:53:18have my list and we take the first
  3099. 1:53:21element in there. We say Alice and we
  3100. 1:53:22say look now this is Dave. Now if we
  3101. 1:53:25look at our list you can see Alice has
  3102. 1:53:27now been updated with Dave. We can also
  3103. 1:53:30use a list method. Uh in this case is
  3104. 1:53:33append and we can just add something to
  3105. 1:53:36it. So let's actually add Alice back to
  3106. 1:53:39the list. And what this will do is it
  3107. 1:53:42will append it. Let's see show you over
  3108. 1:53:44here. So you can see it has now added
  3109. 1:53:46Alice to the end of the list. So append
  3110. 1:53:50is just taking a list as is and then
  3111. 1:53:51stacking that to the end. And we can
  3112. 1:53:54also remove stuff. So if we come in here
  3113. 1:53:56and let's say hey we have my list and we
  3114. 1:53:59now do remove and again we want to
  3115. 1:54:01remove Alice from the list. So Alice is
  3116. 1:54:03having a hard time with list this list.
  3117. 1:54:05We're not sure if we want her on or off
  3118. 1:54:07or whether it's Dave Alice is gone
  3119. 1:54:09again. So all operations that we can
  3120. 1:54:12follow. Often in Python there are also
  3121. 1:54:14multiple ways to accomplish the same
  3122. 1:54:17goal. Uh with append uh there is also an
  3123. 1:54:20insert. So instead of just saying look
  3124. 1:54:22we want this at the end we can also
  3125. 1:54:24insert it into a specific index. So
  3126. 1:54:27coming here again let's see so Alice is
  3127. 1:54:30from the list again and then we can say
  3128. 1:54:32look we want to insert and then we say
  3129. 1:54:34look we want it on index one and we
  3130. 1:54:37bring Alice back in there and let's run
  3131. 1:54:40this. So you can see Alice is back in
  3132. 1:54:42there. Lots of different ways to think
  3133. 1:54:44about look what do we what do I want to
  3134. 1:54:46accomplish? What do I want to do? How do
  3135. 1:54:48I want to store the data? And then
  3136. 1:54:50Python likely has something for that for
  3137. 1:54:53you to accomplish that goal. And similar
  3138. 1:54:55to strings, lists also have methods to
  3139. 1:54:58do even more with it. So we can check
  3140. 1:55:00how long a list is. We can count, we can
  3141. 1:55:04index, we can sort, we can reverse. All
  3142. 1:55:07stuff that you may need to do at some
  3143. 1:55:09point where you run into an issue and
  3144. 1:55:11then you'll find, oh, look, Python can
  3145. 1:55:12actually reverse this list for me. Easy.
  3146. 1:55:15But again, these are more these are not
  3147. 1:55:17so common, I would say, in the real
  3148. 1:55:19world, especially when you're working on
  3149. 1:55:21AI cases. Every now and then they pop
  3150. 1:55:23up, but for now, it's totally fine. Just
  3151. 1:55:26high level be aware of them. Know that
  3152. 1:55:28you can do stuff with lists, but it's
  3153. 1:55:30much more important to understand the
  3154. 1:55:32fundamentals, right? What is the list?
  3155. 1:55:34We can store data into it and we use
  3156. 1:55:36brackets to do that. That's important.
  3157. 1:55:39And we index them. That's the most
  3158. 1:55:41important thing for now. So, let's get
  3159. 1:55:42into dictionaries. So remember, right,
  3160. 1:55:45these are key value pairs. So within a
  3161. 1:55:48list, we simply have a grocery list,
  3162. 1:55:51whatever. Alice doesn't have to be
  3163. 1:55:53related to 25. They're just in the same
  3164. 1:55:56list, but could be entirely different
  3165. 1:55:59concepts. A dictionary changes that. A
  3166. 1:56:02dictionary uses key value pairs. And we
  3167. 1:56:04do that using the curly brackets. So
  3168. 1:56:07here we can start to store information
  3169. 1:56:09in a way where I can say look we have a
  3170. 1:56:12person and now I'm going to open up the
  3171. 1:56:16uh I'm going to create the curly
  3172. 1:56:17brackets in here. I'm going to do do an
  3173. 1:56:19enter and I'm going to say hey let's say
  3174. 1:56:20a person has a name and there comes
  3175. 1:56:23Alice again and I should put that in
  3176. 1:56:25quotes over here. So this is the key. So
  3177. 1:56:26the name is Alice and Alice has an age
  3178. 1:56:29and now that is a number. So let's say
  3179. 1:56:33Alice is 25 and we separate all of the
  3180. 1:56:37new elements in the dictionary similar
  3181. 1:56:39to how we did that in the list with a
  3182. 1:56:41comma. So whenever we go to the next
  3183. 1:56:43line we do a comma and then we can say
  3184. 1:56:45look Alice also has um a city and we set
  3185. 1:56:49that equal to New York. So Alice is 25
  3186. 1:56:52lives in New York. Now this becomes a
  3187. 1:56:56dictionary and what we can do with
  3188. 1:56:58dictionary is we can look up certain
  3189. 1:57:01elements in there. So if we have this
  3190. 1:57:03and we look at the entire dictionary we
  3191. 1:57:06get everything. But now if we want to
  3192. 1:57:08for example grab the we want to know how
  3193. 1:57:11old Alice is in this case what we do is
  3194. 1:57:14instead of using indexing with numbers
  3195. 1:57:17we use the keys to look up the value. So
  3196. 1:57:20we do that also with square brackets.
  3197. 1:57:23Again this is a syntax thing. So we
  3198. 1:57:25define the dictionary with curly
  3199. 1:57:27brackets but when we want to retrieve
  3200. 1:57:29information from it we use the square
  3201. 1:57:32brackets. Something we need to remember.
  3202. 1:57:34And now I can plug in the key. So I can
  3203. 1:57:36say h. And now that will pull the
  3204. 1:57:39information from the dictionary. It will
  3205. 1:57:41perform a lookup and we'll say look we
  3206. 1:57:43got 25. If we do the name we'll get
  3207. 1:57:46Alice. If we do the city we'll get New
  3208. 1:57:48York and so on. And similar to lists, we
  3209. 1:57:51can also update or overwrite information
  3210. 1:57:54in the dictionary. So we can also say
  3211. 1:57:56look person uh name we can just
  3212. 1:57:58overwrite that and say Dave. So now all
  3213. 1:58:01of a sudden you can see over here the
  3214. 1:58:03output now this dictionary contains
  3215. 1:58:05Dave. And we can also add stuff to the
  3216. 1:58:07dictionary which is actually quite
  3217. 1:58:09straightforward. Uh we can just specify
  3218. 1:58:12another key. So something that's not in
  3219. 1:58:14there. So we can for example say we do
  3220. 1:58:16license equals uh true. And now if we
  3221. 1:58:20run this you'll find that the name is
  3222. 1:58:22still Dave. You can see age25 city. And
  3223. 1:58:26now we have added the license to that as
  3224. 1:58:28well. And if we want to get rid of that
  3225. 1:58:30what we can do is we can simply do a
  3226. 1:58:32delete. So we do delete person license.
  3227. 1:58:35And now if we check that you will now
  3228. 1:58:37find that license is not in here
  3229. 1:58:40anymore. So those are the same type of
  3230. 1:58:42operations that you can do with a list
  3231. 1:58:45and within a dictionary. And when to use
  3232. 1:58:48which one is something you have to get a
  3233. 1:58:50feel for when you're are when you're
  3234. 1:58:53working with Python, when you're
  3235. 1:58:54programming in general, there are often
  3236. 1:58:56infinite ways to solve the same problem.
  3237. 1:58:58So you could very well solve problems by
  3238. 1:59:01just using list and storing everything
  3239. 1:59:03in there. But sometimes it's much easier
  3240. 1:59:05to have key value pairs where if you
  3241. 1:59:08want to look up something, you don't
  3242. 1:59:09have to figure out look what was the
  3243. 1:59:11index of this list and then need to
  3244. 1:59:13figure out where was it. You simply
  3245. 1:59:15know, oh, I stored it at the H uh I
  3246. 1:59:18sorted at the H key. So if I want to
  3247. 1:59:19know the H, we just need to plug in
  3248. 1:59:21that. This is all something you'll get a
  3249. 1:59:23feel for as you get more experienced and
  3250. 1:59:25more exposure to working with the Python
  3251. 1:59:27programming language. All right. And
  3252. 1:59:29lastly, dictionary also have methods. So
  3253. 1:59:32we can use the keys, we can get the
  3254. 1:59:34values, we can can get the items. So all
  3255. 1:59:36different ways of accessing the
  3256. 1:59:38information that's available within the
  3257. 1:59:41dictionary. This is a nice exercise to
  3258. 1:59:43try for yourself and see how they work.
  3259. 1:59:45Okay, then let's get into tupils and
  3260. 1:59:48then finally in sets. So these are data
  3261. 1:59:51structures that actually in the wild you
  3262. 1:59:55don't really use a lot, but it's good to
  3263. 1:59:57know how they work just so when you
  3264. 1:59:59encounter them. So a pupil is immutable.
  3265. 2:00:02So remember right with the list and the
  3266. 2:00:05dictionary I saw look we can create it
  3267. 2:00:07and then look we can just override the
  3268. 2:00:09name we can remove Alice all of that.
  3269. 2:00:11Tupils are immutable. So the the idea of
  3270. 2:00:13a tupil is you want to create it and the
  3271. 2:00:16program should never touch that. So for
  3272. 2:00:18example when you have a coordinate or an
  3273. 2:00:20RGB color and just when you want to
  3274. 2:00:23adjust it you just write create a new
  3275. 2:00:25one because the coordinate is not going
  3276. 2:00:27to change and tupils are specified with
  3277. 2:00:30parenthesis. So remember we had lists
  3278. 2:00:32square brackets we had dictionaries
  3279. 2:00:35curly brackets now we have tupils
  3280. 2:00:37parenthesis okay so tupils go in either
  3281. 2:00:41in pairs or you can add more to it. So
  3282. 2:00:44we can have a point and uh we could have
  3283. 2:00:46three and five and we have colors. So
  3284. 2:00:48let's actually plug this in and get a
  3285. 2:00:51feel for what this is like. So we have
  3286. 2:00:53an empty pupil. There's nothing in
  3287. 2:00:54there. We have a point which is three
  3288. 2:00:57and five and then we have the colors in
  3289. 2:00:58here. So what I can now do is let's say
  3290. 2:01:00colors and I want to get the first
  3291. 2:01:03element in there. So this works similar
  3292. 2:01:05to how we're working with the list,
  3293. 2:01:06right? It's very similar uh but it's
  3294. 2:01:09just in a way where look if we now say
  3295. 2:01:11look this is now blue. this will get an
  3296. 2:01:14error because if this were a list, this
  3297. 2:01:17would be totally acceptable. But now
  3298. 2:01:19tupil object does not support item
  3299. 2:01:22assignment. That's what the error says
  3300. 2:01:24because that's one of the properties of
  3301. 2:01:26why you want to use a tupil. So other
  3302. 2:01:28than that, it's very similar to a list
  3303. 2:01:30and we can do all the same things,
  3304. 2:01:31right? We can do get items, we can use
  3305. 2:01:33zero, we can do minus one, we can do
  3306. 2:01:35slicing. That's all you need to know for
  3307. 2:01:37now. So let's get into sets. final data
  3308. 2:01:40structure of really the Python basics,
  3309. 2:01:43all the really most fundamental Lego
  3310. 2:01:45blocks. And a set is a way to create
  3311. 2:01:47unique values to make sure that whenever
  3312. 2:01:50we're working with a collection, there
  3313. 2:01:51are no duplicates in there. There are
  3314. 2:01:53two ways to create sets. We can use the
  3315. 2:01:55set notation over here. Or we can use
  3316. 2:01:58curly brackets, but then not assigning
  3317. 2:02:00the key value pairs because otherwise it
  3318. 2:02:02would be a dictionary. So let's quickly
  3319. 2:02:04go through this because you just need to
  3320. 2:02:05see it at this point rather than like
  3321. 2:02:07fully understanding everything that's
  3322. 2:02:09going on. So we can create an empty set.
  3323. 2:02:11So there's nothing in here and then we
  3324. 2:02:13could later add things to it. But we can
  3325. 2:02:15also set it with values. Both ways work.
  3326. 2:02:17So here let's say we have a set of
  3327. 2:02:19numbers 1 2 3 4 5. So these are the
  3328. 2:02:21numbers. So this is now a set even
  3329. 2:02:24though we use curly braces because we
  3330. 2:02:27don't do the assignment with uh the
  3331. 2:02:30colon and using uh strings in there.
  3332. 2:02:32It's a set. Now we can also do it like
  3333. 2:02:35this. So again in a similar way we use
  3334. 2:02:37set parenthesis and then we plug the
  3335. 2:02:40list in there. That also works. Now we
  3336. 2:02:43can use it to dduplicate items because
  3337. 2:02:46if you don't do that like if you don't
  3338. 2:02:49have or don't intend to do that like you
  3339. 2:02:51could just as well use a list. There's
  3340. 2:02:53no uh there's no point for that. So
  3341. 2:02:55let's say we have the scores over here.
  3342. 2:02:57So notice how 90 appears in here two
  3343. 2:03:00times. So first this is a list. See
  3344. 2:03:03we're using square brackets. So if I
  3345. 2:03:05store this in memory and let me actually
  3346. 2:03:08switch this over here so you can see it.
  3347. 2:03:09If I store this in memory and print it,
  3348. 2:03:11you can see uh this is the list. But now
  3349. 2:03:14we can create unique scores by using the
  3350. 2:03:17set notation and we plug that in here
  3351. 2:03:20and you can see oh it's actually like it
  3352. 2:03:22was 90 and 85. It's also twice in there.
  3353. 2:03:25I didn't even notice that. So now you
  3354. 2:03:26can see it get it gets rid of the
  3355. 2:03:28duplicate values and now we can store
  3356. 2:03:30that and now our unique scores become
  3357. 2:03:32just that and we can do that exactly the
  3358. 2:03:35same over here. Apple, banana, orange.
  3359. 2:03:37These are the fruits but now if we add
  3360. 2:03:39banana one more time it works in exactly
  3361. 2:03:43the same way. Oh, I missed a quote over
  3362. 2:03:45here. So now fruits is still apple,
  3363. 2:03:48banana, orange even though banana is in
  3364. 2:03:51there two times. So that's really what
  3365. 2:03:53you should know about sets and the basic
  3366. 2:03:56operations. We can remove, we can
  3367. 2:03:58discard, we can check things, but it's
  3368. 2:04:00to dduplicate collections. All right,
  3369. 2:04:03and that brings you to the end of the
  3370. 2:04:05Python basics section. So we covered
  3371. 2:04:08almost all of the very fundamental
  3372. 2:04:10building blocks that you need to
  3373. 2:04:11understand about the Python programming
  3374. 2:04:13language. Data types, data structures,
  3375. 2:04:16operators, how you can combine them. And
  3376. 2:04:18you should now get a feel for what it's
  3377. 2:04:21like to write simple Python functions,
  3378. 2:04:23right? You should be getting comfortable
  3379. 2:04:25with either executing code through the
  3380. 2:04:27terminal terminal or see why the Jupyter
  3381. 2:04:30interactor session is so nice to work
  3382. 2:04:33with and how you can quickly explore
  3383. 2:04:35what the data is, check if you made any
  3384. 2:04:37errors and course correct. So with this
  3385. 2:04:39fundamental understanding out of the way
  3386. 2:04:41right now, the next section, building
  3387. 2:04:44programs, is all about how we can
  3388. 2:04:46actually use all of these building
  3389. 2:04:48blocks and create longer scripts instead
  3390. 2:04:50of just isolated lines that we've been
  3391. 2:04:53doing and how to piece things together.
  3392. 2:04:55So it starts to look more and more and
  3393. 2:04:57more like we're actually building
  3394. 2:04:58something and automating something.
  3395. 2:05:00We're getting there. You're crushing it.
  3396. 2:05:02And right now, I still understand this
  3397. 2:05:04is new. These concepts are very
  3398. 2:05:06abstract. They're isolated. You don't
  3399. 2:05:08have to remember all of this. This is
  3400. 2:05:10just the first exposure and it will get
  3401. 2:05:12better over time. And now this would be
  3402. 2:05:14another great time to take a quick
  3403. 2:05:15break. Maybe grab another fresh cup of
  3404. 2:05:17coffee or your favorite beverage and
  3405. 2:05:19then we'll get into the building
  3406. 2:05:20programs section. All right, so let's
  3407. 2:05:23dive into building programs. I also took
  3408. 2:05:26a fresh cup of coffee here. And in
  3409. 2:05:29building programs, we are going to cover
  3410. 2:05:31here on the left side. We can see we're
  3411. 2:05:33going to get into functions, external
  3412. 2:05:35tools, practical tips to use, how you
  3413. 2:05:37use Python in the real world, error
  3414. 2:05:40handling, and then we get into classes.
  3415. 2:05:43So, this is really where you'll get to
  3416. 2:05:45see Python come to life in action, and
  3417. 2:05:48we can actually start to do stuff with
  3418. 2:05:50the language. So, let's dive into
  3419. 2:05:52functions, which are used to create
  3420. 2:05:55reusable blocks of code, so we don't
  3421. 2:05:57have to repeat ourselves. You can think
  3422. 2:06:00of a function like a recipe. you can
  3423. 2:06:01follow multiple times. a machine that
  3424. 2:06:03takes input and produces output or a
  3425. 2:06:05named shortcut for for example complex
  3426. 2:06:07operations and before we already saw
  3427. 2:06:10that we could use loops right so when we
  3428. 2:06:12did the five times print hello world
  3429. 2:06:14that's a little bit redundant and we
  3430. 2:06:16don't want to do that so we created the
  3431. 2:06:17loop to do that but let's say we have
  3432. 2:06:20more complex logic so it's not just a
  3433. 2:06:22oneline print statement but there are
  3434. 2:06:24actually calculations there steps
  3435. 2:06:26printing steps maybe we need to get some
  3436. 2:06:28information manipulate some information
  3437. 2:06:30and every time something happens within
  3438. 2:06:32in our system, we need to do that.
  3439. 2:06:34That's where functions come into place
  3440. 2:06:36where we can define it once and then
  3441. 2:06:38later within our code, we can simply
  3442. 2:06:40call that function and we can now use
  3443. 2:06:43that functionality. So we don't have to
  3444. 2:06:45write the same thing over and over
  3445. 2:06:47again. And you've actually already been
  3446. 2:06:49using some of Python's built-in
  3447. 2:06:51function. So for example the print
  3448. 2:06:52statement that we use all the time or
  3449. 2:06:55the length that we use to um count the
  3450. 2:06:58items or the length of an array we have
  3451. 2:07:01also used that already. So those are
  3452. 2:07:03Python built-in functions and within
  3453. 2:07:06functions we are right now we're going
  3454. 2:07:08to cover three main things. We're going
  3455. 2:07:09to I'm going to teach you how you can
  3456. 2:07:11define functions. Then we're going to
  3457. 2:07:13talk about parameters. So these are
  3458. 2:07:15things you put in the functions to
  3459. 2:07:16control the inputs and the outputs and
  3460. 2:07:18then returning the values. So this is
  3461. 2:07:20what the output of the function will be.
  3462. 2:07:22All right. So let's start with defining
  3463. 2:07:25functions. And for this I'm going to
  3464. 2:07:27come over here to Visual Studio Code and
  3465. 2:07:30we're going to start with a new fresh
  3466. 2:07:33clean slate here in hello.py. So as with
  3467. 2:07:36anything with any new concept we're
  3468. 2:07:38going to start with some syntax, right?
  3469. 2:07:40Because first there are some rules that
  3470. 2:07:41we need to understand before we can
  3471. 2:07:43actually get into the functionality. Now
  3472. 2:07:45every function in Python starts with
  3473. 2:07:47defaf from definition meaning we're
  3474. 2:07:50going to define a function then followed
  3475. 2:07:52by a space and then we're going to write
  3476. 2:07:55the name of the function. This can be
  3477. 2:07:57literally anything. You can put anything
  3478. 2:07:59here. Now as a rule of thumb you want
  3479. 2:08:01the function to be descriptive of what
  3480. 2:08:04it does. So let's start with a simple
  3481. 2:08:06greeting function to create a print
  3482. 2:08:09statement. And what you then want to do
  3483. 2:08:12after the name of the function, you need
  3484. 2:08:15parenthesis opening and closing
  3485. 2:08:17parenthesis and then a colon. Again,
  3486. 2:08:19this is all syntax. You need to see it
  3487. 2:08:21once and then you can quickly refer to
  3488. 2:08:23it. For now, this is all we need. And
  3489. 2:08:25then we can hit enter. And now we get
  3490. 2:08:27into the function. So we have now
  3491. 2:08:29specified our function over here. And
  3492. 2:08:31here in here with the tabs or four
  3493. 2:08:34spaces, we can actually put stuff in
  3494. 2:08:37here. So we can for example write a
  3495. 2:08:39print statement and say hello. All
  3496. 2:08:41right. And now let's have a look at what
  3497. 2:08:42happens when we run this. So you can see
  3498. 2:08:45right here we we load the function into
  3499. 2:08:47memory but there's no output. We don't
  3500. 2:08:49see anything here. And the same would be
  3501. 2:08:51true if we run it in the terminal. You
  3502. 2:08:54can see it just tries to run the script
  3503. 2:08:56but there's no output. It just mentioned
  3504. 2:08:58that it runs the file. So that is the
  3505. 2:09:01case because when you define a function
  3506. 2:09:03it is simply a placeholder for that
  3507. 2:09:05logic. But when you want to actually use
  3508. 2:09:08a function, we need to specifically tell
  3509. 2:09:11Python to do that. So what we can do is
  3510. 2:09:13we can come over to a new line over here
  3511. 2:09:15and type in greet and then we do opening
  3512. 2:09:18and closing parenthesis. And now this is
  3513. 2:09:20actually where we would call the
  3514. 2:09:21function. So now if I one more time open
  3515. 2:09:23this up. Now if I do greet you can see
  3516. 2:09:26that it executes the function and that
  3517. 2:09:29it outputs the print statement over
  3518. 2:09:31here. Similar if I do a copy paste over
  3519. 2:09:33here uh and I can do hello again and I
  3520. 2:09:37store this into memory and then do
  3521. 2:09:39greet. You can see now we've changed our
  3522. 2:09:41function and then now when we call the
  3523. 2:09:43function now it prints this. So that was
  3524. 2:09:45your first function. So the important
  3525. 2:09:47thing to remember is the syntax. We
  3526. 2:09:49start with defaf function name opening
  3527. 2:09:51and closing parenthesis and then we do
  3528. 2:09:53the colon. Then you can add your code
  3529. 2:09:54here. Make sure it's indented. And then
  3530. 2:09:57if you don't want to return something,
  3531. 2:09:59you don't have to put in this pass over
  3532. 2:10:01here. But you can also do it for
  3533. 2:10:02clarity. So normally functions will
  3534. 2:10:05often return something. And this pass
  3535. 2:10:07putting this pass over here is simply a
  3536. 2:10:09kind of like a readable way for humans
  3537. 2:10:11to say look this function doesn't return
  3538. 2:10:13anything. I in the next sections I'll
  3539. 2:10:15show you how we can return stuff. But
  3540. 2:10:17you can see it doesn't change anything.
  3541. 2:10:19So you can also just get rid of this and
  3542. 2:10:21it will be exactly the same. but Python
  3543. 2:10:24accepts it. So those are the key parts
  3544. 2:10:27and then some tips on naming functions.
  3545. 2:10:29So like I've said, you want functions,
  3546. 2:10:32you want functions to be descriptive of
  3547. 2:10:33what they're doing, right? And there's
  3548. 2:10:35also there al there are also some style
  3549. 2:10:37rules to this similar to how we talked
  3550. 2:10:40about there are style rules to
  3551. 2:10:42variables, right? We use a similar setup
  3552. 2:10:44over here. So we use lowercase letters
  3553. 2:10:46and whenever there's a space, we use an
  3554. 2:10:48underscore. So if we want to calculate
  3555. 2:10:51some kind of total, we do calculate
  3556. 2:10:53underscore total. We want to send an
  3557. 2:10:55email, send underscore email, no capital
  3558. 2:10:58letters. So we don't want to do uh we
  3559. 2:11:01don't want to use capital letters in
  3560. 2:11:02here. Those are reserved for classes
  3561. 2:11:04which we will cover later. But remember
  3562. 2:11:07these are styling styling guidelines. So
  3563. 2:11:10it will work perfectly fine. You won't
  3564. 2:11:12get an error. But other developers will
  3565. 2:11:14look at you and they will see that
  3566. 2:11:16you're a beginner and we don't want
  3567. 2:11:18that, right? So then calling the
  3568. 2:11:19functions this is what I already showed
  3569. 2:11:21you right. So let let me actually copy
  3570. 2:11:23paste this example over here to see we
  3571. 2:11:25can also call uh functions multiple
  3572. 2:11:27times. So that's the nice thing about a
  3573. 2:11:29function. So here we have say goodbye we
  3574. 2:11:31can do it once and now if we do want to
  3575. 2:11:33do it one more time in our script we can
  3576. 2:11:35simply just refer and just call the
  3577. 2:11:38function instead of having to do it over
  3578. 2:11:40and over again. And now what this means
  3579. 2:11:42whenever you run your entire script so
  3580. 2:11:44everything runs you can see that all of
  3581. 2:11:46the logic here is executed. by three
  3582. 2:11:48times. And beyond just simple print
  3583. 2:11:51statements, we can really do anything
  3584. 2:11:53with in a function. So we can also come
  3585. 2:11:55back to some of the logic we already
  3586. 2:11:57tested before and we can input if else
  3587. 2:11:59statements. And the most important thing
  3588. 2:12:01here to keep in mind is the indentation
  3589. 2:12:04and how you structure how you structure
  3590. 2:12:06these functions, right? So let me walk
  3591. 2:12:08you through it. So when we create the
  3592. 2:12:09function, we do defaf and we do the
  3593. 2:12:11check weather. And you can also see over
  3594. 2:12:13here like how your ID how the code
  3595. 2:12:15editor is helping with this. So now this
  3596. 2:12:17this is how we specify the function. Now
  3597. 2:12:19we do an indent. Now if we want to check
  3598. 2:12:22what if we want to uh include an if
  3599. 2:12:24statement we do if and then let's say uh
  3600. 2:12:27temp
  3601. 2:12:29greater than 25. We for example print
  3602. 2:12:33and we say it's hot. And now you can see
  3603. 2:12:37these squiggly lines under here under
  3604. 2:12:39temperature. And that is because right
  3605. 2:12:40now Python doesn't know what temperature
  3606. 2:12:43is. And that's because we haven't
  3607. 2:12:44specified it yet. So you want to store
  3608. 2:12:47that over here and say look temperature
  3609. 2:12:49is 16. If temperature is greater than 25
  3610. 2:12:52print it's hot. Then we go in here and
  3611. 2:12:55then I do a shift tab to go back to this
  3612. 2:12:57line. I do an else. I do another enter.
  3613. 2:13:00Our IDE will cover the indentation and
  3614. 2:13:03otherwise print it's nice weather. So
  3615. 2:13:07this is why it's also good to like I've
  3616. 2:13:09said beyond just copy and pasting the
  3617. 2:13:11examples over here really writing it out
  3618. 2:13:14because if you just do copy paste and
  3619. 2:13:16you run it everything will run but it's
  3620. 2:13:18those nitty-gritty things where like
  3621. 2:13:20look how how does this work? Should I
  3622. 2:13:22have it like this or have do I have it
  3623. 2:13:24on this line? And you can immediately
  3624. 2:13:26tell that your IDE will tell you like
  3625. 2:13:28something's off. And this is how you
  3626. 2:13:30build the like the the muscle memory and
  3627. 2:13:32the the uh the skill really to look at
  3628. 2:13:35Python code and think about okay look
  3629. 2:13:37this is a function we have if else
  3630. 2:13:39statements this is how it should be
  3631. 2:13:40structured. So now if we do this
  3632. 2:13:43remember if we run this what happens
  3633. 2:13:45nothing correctly because we haven't
  3634. 2:13:47called the function yet. So now I go to
  3635. 2:13:50the other line over here. I go all the
  3636. 2:13:53way to the back all the way really to
  3637. 2:13:55the beginning. So no indentation and I'm
  3638. 2:13:57going to do the check weather. I hit
  3639. 2:13:58enter to autocomplete. So that's also
  3640. 2:14:00something you'll notice, right? So I do
  3641. 2:14:02check and now my IDE already says look
  3642. 2:14:05check weather is a function that I have
  3643. 2:14:07over here. So now I can just press enter
  3644. 2:14:09and it will autocomplete that. So that's
  3645. 2:14:12also one of those things where you need
  3646. 2:14:14to you need to get your hands on the
  3647. 2:14:16keyboard. You need to be able to type
  3648. 2:14:18and then you'll find all kinds of
  3649. 2:14:20interesting things that your IDE will
  3650. 2:14:21show you. So you'll find that as I go
  3651. 2:14:23through all of these examples, I'll also
  3652. 2:14:26explain more and more of these things
  3653. 2:14:28behind the scenes. So now we have to
  3654. 2:14:29check weather over here. We can put it
  3655. 2:14:31into memory. Check the weather. So it's
  3656. 2:14:33nice weather. I can come over here.
  3657. 2:14:35Let's say let's make it 30. Store this.
  3658. 2:14:38Check weather. It's hot. Okay, that's
  3659. 2:14:40our function to check the weather. All
  3660. 2:14:42right. Okay. So let's come back over
  3661. 2:14:44here. You can check out some common
  3662. 2:14:46mistakes. If uh things don't go wrong,
  3663. 2:14:48things is like you forget the uh
  3664. 2:14:50parenthesis. That's a that's a big one.
  3665. 2:14:52You forget the colon at the end. So do
  3666. 2:14:54greet no colon. All beginner mistakes
  3667. 2:14:57that you'll uh run into or the bad
  3668. 2:14:59indentation. So it's not formatted
  3669. 2:15:01correctly. All right. So let's now let's
  3670. 2:15:03continue on this and let's talk about
  3671. 2:15:04parameters. So parameters work with
  3672. 2:15:08functions to make them dynamic. Right?
  3673. 2:15:10So if I come back to this example. So
  3674. 2:15:12right now like this is hardcoded and
  3675. 2:15:15hardcoded means whenever this script
  3676. 2:15:17runs it will always be this. I can do
  3677. 2:15:20this all the time. I can do check
  3678. 2:15:22weather, check weather, check weather.
  3679. 2:15:23It will always be hot and this will
  3680. 2:15:24never change. That's because there are
  3681. 2:15:26no parameters that we can
  3682. 2:15:29programmatically or dynamically change.
  3683. 2:15:31So that's where parameters come in. You
  3684. 2:15:33can now see that we can also add
  3685. 2:15:35parameters in here and parameters go in
  3686. 2:15:38between the parenthesis. So over here
  3687. 2:15:40you can see we have the greet function
  3688. 2:15:42but then we plug in the name over here.
  3689. 2:15:44Now we can use that variable name in the
  3690. 2:15:47function itself. And then when we call
  3691. 2:15:49the function we can plug in that
  3692. 2:15:52parameter and it will use that it will
  3693. 2:15:55use that data within the function. Okay.
  3694. 2:15:56So let's have a look at how this works.
  3695. 2:15:59Again we have our simple function over
  3696. 2:16:00here. So let's do another one. So we do
  3697. 2:16:02greet. So dev greet this is all the same
  3698. 2:16:05and then we do the parenthesis. And now
  3699. 2:16:07what we do is we do name and then we do
  3700. 2:16:10a colon. So now this function takes name
  3701. 2:16:13as a parameter. And what we can now do
  3702. 2:16:14is we do print and we create a string.
  3703. 2:16:17we say hello and then remember if we
  3704. 2:16:21wanted to to use variables within
  3705. 2:16:23strings, do you remember what it was? It
  3706. 2:16:25was called using an f string. So we put
  3707. 2:16:28a little f before the string and then we
  3708. 2:16:31could use the curly brackets in here to
  3709. 2:16:34plug in a parameter. So now when we have
  3710. 2:16:36this function and we go to greet, what
  3711. 2:16:40we can do is we can now say name equals
  3712. 2:16:44and let's say we can put in Dave. So we
  3713. 2:16:46save this and we do greet and you'll
  3714. 2:16:48find that it says hello Dave but we can
  3715. 2:16:50also do this one more time and we can do
  3716. 2:16:53hello Alice. So this is a way for us
  3717. 2:16:56this is a really this is a key concept
  3718. 2:16:58about working with function because this
  3719. 2:16:59is something you'll do all the time
  3720. 2:17:00where when you're building programs you
  3721. 2:17:02think about look what logic do I want to
  3722. 2:17:04implement what data what information is
  3723. 2:17:06is coming at me and how do I want to use
  3724. 2:17:09that information within my function so
  3725. 2:17:11now we've made a dynamic script that we
  3726. 2:17:13can change and one thing to uh remember
  3727. 2:17:17here is that for Python it doesn't
  3728. 2:17:20matter in this case if I specifically
  3729. 2:17:23say name equals Dave or I just do greet
  3730. 2:17:26Dave because how this works is you can
  3731. 2:17:28also have multiple parameters and it
  3732. 2:17:31will just follow the order of
  3733. 2:17:32operations. So let me show you what I
  3734. 2:17:34mean with that. So I can also for
  3735. 2:17:35example let's let's do let's do last
  3736. 2:17:37name first name last name and then we
  3737. 2:17:39say look we have a first name in here
  3738. 2:17:42and then I just do let's see I do space
  3739. 2:17:45in here and then we do last name and so
  3740. 2:17:48now we have two parameters in here that
  3741. 2:17:50we can insert. And now what you'll find
  3742. 2:17:53is if I do this and if I run this
  3743. 2:17:55function we'll get an error because it
  3744. 2:17:57says look greed. Let me actually move me
  3745. 2:18:00to the side. So you can see now greed is
  3746. 2:18:02missing one required positional argument
  3747. 2:18:04last name. So Python now understands
  3748. 2:18:06look in this function you actually need
  3749. 2:18:08two parameters and you only gave one. So
  3750. 2:18:11if we now plug in my last name over here
  3751. 2:18:15you can see that right now this is all
  3752. 2:18:18uh correct and now we can see hello Dave
  3753. 2:18:20ablar. So now it's all good and you'll
  3754. 2:18:23see that you actually don't have to
  3755. 2:18:25specify first name last name because
  3756. 2:18:27Python understands look this is the
  3757. 2:18:28order of operation. First we do the
  3758. 2:18:30first name and then we do the last name.
  3759. 2:18:32So if I swap this around and do it like
  3760. 2:18:35this and I agreed it will be reverse. It
  3761. 2:18:38will it will take my last name and we'll
  3762. 2:18:40plug it in the first name. So I what I
  3763. 2:18:42always uh like to do I always like to be
  3764. 2:18:45explicit with this and really say look
  3765. 2:18:48first name equals Dave and then I put
  3766. 2:18:50the last name in here. So you don't have
  3767. 2:18:53to do this. Python will also work
  3768. 2:18:54without but especially if you're working
  3769. 2:18:56with multiple functions right now you
  3770. 2:18:59can clearly see look this function is
  3771. 2:19:01greed and I plug in the first name and
  3772. 2:19:03the last name. So you add a little bit
  3773. 2:19:05more code to it but it helps for
  3774. 2:19:07readability. So now when I plug this in
  3775. 2:19:09and I greet it, you'll find that it
  3776. 2:19:12works correctly. And now what's also
  3777. 2:19:13interesting now we can also like if you
  3778. 2:19:16want to for whatever reason you can also
  3779. 2:19:18swap it around. So now the order doesn't
  3780. 2:19:21matter because we are explicit about it.
  3781. 2:19:23So now if I run this even though the
  3782. 2:19:26order is in reverse it still says my
  3783. 2:19:29name correctly over here because we
  3784. 2:19:31mapped them to the correct parameters
  3785. 2:19:33over here. And now functions can also
  3786. 2:19:35have default parameters. So what you can
  3787. 2:19:38do over here whenever you specify the
  3788. 2:19:40function let's say first name let's say
  3789. 2:19:43you can put an equal sign in here and
  3790. 2:19:45let's say we do John and then last name.
  3791. 2:19:48So oh this is another interesting thing
  3792. 2:19:50you can specify default values in here.
  3793. 2:19:53Now you'll see that we get red squiggly
  3794. 2:19:55lines in here and that means that here's
  3795. 2:19:57an error. So this is another syntax
  3796. 2:19:59thing. Whenever you want to specify
  3797. 2:20:02default values, meaning that right now
  3798. 2:20:05uh I for example don't have to put in a
  3799. 2:20:07first name and then it will if there's
  3800. 2:20:09no first name, it will default to John.
  3801. 2:20:11But there's an order to things. So you
  3802. 2:20:13need to uh you need to set the
  3803. 2:20:17parameters that don't have a default
  3804. 2:20:18value first and then you set the ones
  3805. 2:20:21that have default values. So now it's
  3806. 2:20:22just like it's just like swapping things
  3807. 2:20:24around in different order. The
  3808. 2:20:25functionality is still the same but this
  3809. 2:20:27is just like what Python expects. So now
  3810. 2:20:30if I store this function now let's see I
  3811. 2:20:33can uh come in here and look now I can
  3812. 2:20:36actually run this function and I only
  3813. 2:20:38need to plug in the last name and it
  3814. 2:20:40won't give me it won't give me an error
  3815. 2:20:42because now it will simply say look okay
  3816. 2:20:45first name is not there in that case I
  3817. 2:20:47always take John and let's see we can do
  3818. 2:20:51something similar for the last name and
  3819. 2:20:53now because this is now also has a
  3820. 2:20:56default value we can swap it around
  3821. 2:20:58again just for the order of things. And
  3822. 2:21:01now I don't actually have to plug
  3823. 2:21:03anything into my function and I can just
  3824. 2:21:05run it and it will run with the default
  3825. 2:21:08values of John Doe. But I can simply
  3826. 2:21:11override that and say look I want to
  3827. 2:21:13greet it with Dave and vice versa. You
  3828. 2:21:15can do it with last name, first name,
  3829. 2:21:17both. So that is a way to work with
  3830. 2:21:19parameters. You can plug them in. You
  3831. 2:21:21can give them default values. You can
  3832. 2:21:23change them to make your programs
  3833. 2:21:25dynamic. Okay. So we've already seen
  3834. 2:21:28that you can just work with multiple
  3835. 2:21:30parameters. So you can add as much
  3836. 2:21:31information as you want there. So let me
  3837. 2:21:34quickly show you this example about
  3838. 2:21:35calculator. So here you can see we have
  3839. 2:21:38a function calculate total. We take the
  3840. 2:21:40price, the tax rate and the discount.
  3841. 2:21:42And now instead of doing simple print
  3842. 2:21:44statements, we're going to apply some
  3843. 2:21:46math. Right? So we we first calculate
  3844. 2:21:49the tax by u multiplying the price with
  3845. 2:21:52a tax rate. Then we have a final price.
  3846. 2:21:54So we're storing v variables inside this
  3847. 2:21:57function over here and then we print the
  3848. 2:22:00final price using an fstring and then
  3849. 2:22:02you can see over here order matters. So
  3850. 2:22:05let's see because right now we are not
  3851. 2:22:08specifying the uh names right we already
  3852. 2:22:11saw this then order matters if we are
  3853. 2:22:13specific about this that's why I always
  3854. 2:22:16recommend to do that you cannot make
  3855. 2:22:18that mistake so you'll always find that
  3856. 2:22:21it's very clear that the discount is
  3857. 2:22:24this this is the tax rate and this is
  3858. 2:22:25the price so that's why I always
  3859. 2:22:28recommend using these keyword arguments
  3860. 2:22:30that you can see over here right you
  3861. 2:22:32specify the function and then when you
  3862. 2:22:34use them just make it explicit. Say the
  3863. 2:22:36city is this instead of just like
  3864. 2:22:37relying on the order uh of operations.
  3865. 2:22:41Now, one more other thing that I want to
  3866. 2:22:42show you here when it comes to functions
  3867. 2:22:45is the notion of global versus local
  3868. 2:22:50variables within Python. This is a
  3869. 2:22:52common mistake and this can be really
  3870. 2:22:54frustrating in the beginning. But
  3871. 2:22:56whenever so by now you know you when you
  3872. 2:22:59uh run a Python file, it goes from top
  3873. 2:23:01to bottom, from left to right. But there
  3874. 2:23:03is also a notion as to when we are
  3875. 2:23:06inside a function or in a class for
  3876. 2:23:08Python that information now becomes
  3877. 2:23:10locally and I'll show you in a bit what
  3878. 2:23:12that means but it essentially means that
  3879. 2:23:14you can use that information within the
  3880. 2:23:15function and within the function Python
  3881. 2:23:17understands what it is but outside of
  3882. 2:23:19the function we cannot use it. Let me
  3883. 2:23:22show you an example. So let's take the
  3884. 2:23:23calculate the calculate total over here.
  3885. 2:23:26So we have this function and over here
  3886. 2:23:29let's even make it simpler by setting by
  3887. 2:23:32hard coding the price over here. So or
  3888. 2:23:34let's say we we just take the price and
  3889. 2:23:37we get rid of the tax and the discount.
  3890. 2:23:40So we set the tax rate we hardcode it.
  3891. 2:23:43So we set that to
  3892. 2:23:458 and then we set the discount to 10.
  3893. 2:23:49And actually let's make it even more
  3894. 2:23:51explicit. So we put the tax rate here.
  3895. 2:23:54So we plug that and then we can put the
  3896. 2:23:57text right here and then we say the
  3897. 2:24:00discount is 10 and then we put that
  3898. 2:24:03here. So now we can see and you can also
  3899. 2:24:06see how I can play with this. I can add
  3900. 2:24:08a comment here. So we can for example so
  3901. 2:24:10these are the default values and then
  3902. 2:24:12over here we are going to do the
  3903. 2:24:15calculation. So and then we do print
  3904. 2:24:19final answer final price. Okay. So now
  3905. 2:24:22we have made the function simpler in a
  3906. 2:24:25way where it only takes the price as an
  3907. 2:24:27input and we can calculate this and you
  3908. 2:24:29can see this show up over here. So now
  3909. 2:24:32what happens if we for example are in
  3910. 2:24:35another part of our script later down
  3911. 2:24:37the line and we want to continue. So we
  3912. 2:24:39first made one calculation and now we
  3913. 2:24:41want to maybe add something to it and we
  3914. 2:24:43want to use the discount one more time.
  3915. 2:24:45So if we for example now say look okay I
  3916. 2:24:48want to use that discount again because
  3917. 2:24:50we we set it to 10 right uh discount is
  3918. 2:24:5310 over here you see if I just type in
  3919. 2:24:54discount in here it will give us the
  3920. 2:24:56yellow squiggly line saying discount is
  3921. 2:24:59not defined so when I run this it will
  3922. 2:25:01get an error even though this right now
  3923. 2:25:05is all stored in memory it's in the same
  3924. 2:25:06file discount is not available so you
  3925. 2:25:09can see I'll actually move that discount
  3926. 2:25:11is not available and that is because
  3927. 2:25:14this is the difference between local and
  3928. 2:25:16global variables. Whatever is inside a
  3929. 2:25:19function is considered locally in Python
  3930. 2:25:22and then outside the function we cannot
  3931. 2:25:24use that. So there is an order to
  3932. 2:25:26things. So if I for example now set over
  3933. 2:25:29here at the top I set discount is let's
  3934. 2:25:32say 20. I run this you'll find that we
  3935. 2:25:37set the discount to 20. Now we'll get
  3936. 2:25:40inside the function and it will perform
  3937. 2:25:43the calculation. you you'll still see
  3938. 2:25:45that the total is the same. So we get
  3939. 2:25:47the same answer. We get the 98 and
  3940. 2:25:49that's because inside this function,
  3941. 2:25:51Python prioritizes the variable that you
  3942. 2:25:54have over here. So even though first we
  3943. 2:25:55say discount is is 10 because we go from
  3944. 2:25:59top to bottom and from left to right, it
  3945. 2:26:01will overwrite the 10 over here. Then it
  3946. 2:26:04will perform here the calculation using
  3947. 2:26:06all of the information in here. But then
  3948. 2:26:08later when outside the function we refer
  3949. 2:26:10to the discount, it is still 20. And
  3950. 2:26:12this is really just one of those
  3951. 2:26:13examples that you need to run into this
  3952. 2:26:15a couple of times in the real world and
  3953. 2:26:17think about like, oh look, I thought
  3954. 2:26:19discount was 10, right? Why is it 20
  3955. 2:26:21right now? And then why is it 20 right
  3956. 2:26:23now? And they see, oh wait, it's a
  3957. 2:26:25global variable over here and here is
  3958. 2:26:27the local variable. Now, um I've shown
  3959. 2:26:29you that if you don't have a global
  3960. 2:26:34variable and you just have local
  3961. 2:26:36variables in the function and you try to
  3962. 2:26:38access it, it won't work. But here's the
  3963. 2:26:42thing, it works the other way around. So
  3964. 2:26:44within functions, we can use global
  3965. 2:26:47variables. So if I specify the discount
  3966. 2:26:49outside of the function, we can use that
  3967. 2:26:52discount in here and Python will know,
  3968. 2:26:54look, we have a global variable. So
  3969. 2:26:56that's one level higher, it overrides it
  3970. 2:26:58and we can use that inside a function.
  3971. 2:27:00Now, this is not common, but it can uh
  3972. 2:27:04it works. And why I said it's not common
  3973. 2:27:07because typically you want to be very
  3974. 2:27:09specific about this. and then still add
  3975. 2:27:11the discount as a parameter because
  3976. 2:27:14otherwise information can get lost
  3977. 2:27:16meaning that if I specify the discount
  3978. 2:27:18over here and then let's see I have the
  3979. 2:27:20function and now we calculate the total
  3980. 2:27:22price you can see that the output is
  3981. 2:27:24still the same so this discount is
  3982. 2:27:27referring to what's specified over here
  3983. 2:27:29but now when you're working on real
  3984. 2:27:30projects you often have multiple files
  3985. 2:27:32multiple functions and now someone's
  3986. 2:27:34working on this and you see this
  3987. 2:27:36function over here and someone decides
  3988. 2:27:37to get rid of this now this function
  3989. 2:27:40doesn't work anymore because now uh
  3990. 2:27:42let's see if I get rid of this. Now it
  3991. 2:27:44says look there's no discount over here.
  3992. 2:27:46So adding that and making that specific
  3993. 2:27:48in this function is best practice in
  3994. 2:27:51that case so that you always know look
  3995. 2:27:53whenever you need to calculate the total
  3996. 2:27:55we also need to plug in that discount
  3997. 2:27:59specifically over here and it doesn't
  3998. 2:28:00matter where we get it from but this is
  3999. 2:28:02the place and that's how you don't
  4000. 2:28:04forget it that it needs to be in there.
  4001. 2:28:06So that was a little bit of playing with
  4002. 2:28:08global local variables. You get some
  4003. 2:28:10exposure to what it's like to work with
  4004. 2:28:12the function to input the parameters and
  4005. 2:28:15then how to call the function. And
  4006. 2:28:17really it's about practice here. You
  4007. 2:28:18need to see multiple examples. So later
  4008. 2:28:21on when we're going to the practical
  4009. 2:28:22Python in this session, we're going to
  4010. 2:28:24actually do some stuff because I'm fully
  4011. 2:28:26aware and this is some of the things
  4012. 2:28:28that like really bothered me when I was
  4013. 2:28:30learning Python in the beginning. You
  4014. 2:28:32always see these like cookie cutter
  4015. 2:28:33examples. So like look I can yes I can
  4016. 2:28:36print someone's name but what what is
  4017. 2:28:38actually the point of that right? So
  4018. 2:28:41bear with me we need those fundamental
  4019. 2:28:43building blocks. So then here I'm
  4020. 2:28:44literally going to show you like how you
  4021. 2:28:46can take a CSV file import it do
  4022. 2:28:48calculations and then write it back to a
  4023. 2:28:49file and that's really where things will
  4024. 2:28:51start to click and we're going to reuse
  4025. 2:28:53these building blocks again but we need
  4026. 2:28:55to be step by step. Okay so then the
  4027. 2:28:57final section in here of functions is
  4028. 2:28:59returning values. So up until this point
  4029. 2:29:03we created functions that just do
  4030. 2:29:05something and then either just print
  4031. 2:29:07something or do nothing. Functions can
  4032. 2:29:09also return something and we do that
  4033. 2:29:12with the return syntax over here. So
  4034. 2:29:15let's dive into some examples. Okay. So
  4035. 2:29:18let's say we have the simple function
  4036. 2:29:20and we do a print and we take a and b as
  4037. 2:29:25parameters and we just in this case we
  4038. 2:29:28just print a and b. So this is now what
  4039. 2:29:32we saw before very simple function we
  4040. 2:29:34don't return anything. So now if we do
  4041. 2:29:36add print and we call this and we plug
  4042. 2:29:39in a= 5 and let's say b= 10. Okay, wait.
  4043. 2:29:46We can for example do let's actually do
  4044. 2:29:48plus. Okay, there we go. So now you can
  4045. 2:29:50see we run this function and it just
  4046. 2:29:52does a print statement but it just shows
  4047. 2:29:55up in the terminal but now we cannot
  4048. 2:29:57access that 15. It's like it's gone
  4049. 2:29:59right now. It just it was a one-time
  4050. 2:30:01print but now we there's nothing. Let's
  4051. 2:30:04say we want to add something else to it.
  4052. 2:30:06There's no way to to reference that 15
  4053. 2:30:09or a variable where that is stored in.
  4054. 2:30:11So that where that's where return comes
  4055. 2:30:13in. So when we want to perform an
  4056. 2:30:15operation and we also want to like store
  4057. 2:30:18that and do something with it. So then
  4058. 2:30:20what do you do? You add a return. So we
  4059. 2:30:23do a return. We do add and we do a
  4060. 2:30:26return. So we do this. We do the same
  4061. 2:30:29stuff. So we do a and b. We plug that in
  4062. 2:30:32and let's see colon. And now what we can
  4063. 2:30:36do is instead of a print we do a return
  4064. 2:30:39and then we say a and then we do plus b.
  4065. 2:30:42If we now run this and we say add return
  4066. 2:30:46and we call that function. The thing is
  4067. 2:30:48in the terminal if I run this over here
  4068. 2:30:51let's see oh sorry I should plug in the
  4069. 2:30:54variables over here let's see we will
  4070. 2:30:57also see 15 but there is a difference
  4071. 2:31:00and that is when we do the at print so
  4072. 2:31:02we just print it it will like printing
  4073. 2:31:04is just show showing it but we cannot do
  4074. 2:31:06anything with that later whereas
  4075. 2:31:08returning it it is actually returning it
  4076. 2:31:11and we can capture and we can store that
  4077. 2:31:12information and the way we do that is
  4078. 2:31:14simply by saying look we have our
  4079. 2:31:16function and it outputs something and we
  4080. 2:31:19store that into a variable. So now what
  4081. 2:31:22we can do now if we run this now you'll
  4082. 2:31:25see we'll we'll just run this line and
  4083. 2:31:27you won't see the 15 show up here
  4084. 2:31:30because it's stored in result and now
  4085. 2:31:32result is something that we can use and
  4086. 2:31:35we can do whatever with that. So now we
  4087. 2:31:36can do + 50, we can do + 20 and that
  4088. 2:31:39information is stored. And here it's
  4089. 2:31:42also important to let's see to give a a
  4090. 2:31:45quick distinction between the
  4091. 2:31:47interactive session that we use all the
  4092. 2:31:49time and running it in the terminal uh
  4093. 2:31:51when programs run in the background for
  4094. 2:31:53example because because when I for
  4095. 2:31:54example comment this out, I select
  4096. 2:31:56something and I do command forward slash
  4097. 2:31:58or on Windows uh control slash you can
  4098. 2:32:00comment out entire blocks very easy.
  4099. 2:32:03This helps if you want to run your
  4100. 2:32:04program without running this. For
  4101. 2:32:06example, if I now run it in the
  4102. 2:32:08terminal, let's see. So, we do run in
  4103. 2:32:10dedicated terminal. You can see this
  4104. 2:32:12show up. Now, you can see that it will
  4105. 2:32:14it will print the 15 out over here. So,
  4106. 2:32:16you'll see that if we close this out and
  4107. 2:32:19now this and I encourage encourage you
  4108. 2:32:21to follow along with this and also like
  4109. 2:32:23play with like commenting these blocks
  4110. 2:32:25out and then moving quickly between
  4111. 2:32:27them. Now, if we run this, you'll see
  4112. 2:32:30that we run it, there's no 15. So this
  4113. 2:32:33is a difference between the interactive
  4114. 2:32:35session and the terminal if you do it in
  4115. 2:32:37the interactive session. Even though
  4116. 2:32:39it's not like printing it, we can still
  4117. 2:32:42see the the output. But that's just
  4118. 2:32:44something that you have to keep in mind.
  4119. 2:32:45But there's there is under the hood
  4120. 2:32:47there's a difference because this 15 is
  4121. 2:32:49something that we that we can use and
  4122. 2:32:52this is print statement that that just
  4123. 2:32:54shows up because let me show you if I
  4124. 2:32:56now do so we have the result you saw we
  4125. 2:32:58can store that right we have that 15 but
  4126. 2:33:00if we do that over here so we say if the
  4127. 2:33:03add print so we do print results equals
  4128. 2:33:06we can save the output we will see the
  4129. 2:33:0815 but now when we do print result it's
  4130. 2:33:11empty there's nothing here so little
  4131. 2:33:14tiny difference but something in
  4132. 2:33:15beginning that you need to get used to.
  4133. 2:33:17Okay. And so with that we can perform
  4134. 2:33:20all kinds of calculations. So let's take
  4135. 2:33:22the following example over here. Let's
  4136. 2:33:24copy paste it. So here we have a
  4137. 2:33:25function to calculate the area. So it
  4138. 2:33:27takes as an argument the width and the
  4139. 2:33:30height and then we calculate the area by
  4140. 2:33:33multiplying it and then we return the
  4141. 2:33:34area. So we can also store in between
  4142. 2:33:38variables. We can expand on them do
  4143. 2:33:40calculations and then return the
  4144. 2:33:42variable. So we don't specifically have
  4145. 2:33:44to do the return statement here. Whereas
  4146. 2:33:47this would also work. It would be
  4147. 2:33:49exactly the same. But this is a little
  4148. 2:33:51bit easier to also help you as a
  4149. 2:33:54programmer think through your program,
  4150. 2:33:56right? What's the goal? First, we want
  4151. 2:33:57to calculate the area. How do we do
  4152. 2:33:59that? Width time height. Okay. And the
  4153. 2:34:01area is the stuff that we want to
  4154. 2:34:03return. So if I run this and I calculate
  4155. 2:34:06the area, we can print the room size and
  4156. 2:34:09it's 120 square ft. And we can simply
  4157. 2:34:14for example come in here and let's say
  4158. 2:34:15you know we want to er uh we want to add
  4159. 2:34:17a margin of error. So we want to say
  4160. 2:34:19look area is area and then we do it
  4161. 2:34:23times 1
  4162. 2:34:25let's see let's add a 5% margin and then
  4163. 2:34:28you'll find that it's bigger and these
  4164. 2:34:31returned values we can use them later.
  4165. 2:34:33So if I take this example over here. So
  4166. 2:34:36let's say we have a very simple function
  4167. 2:34:38to double a number. We can have a result
  4168. 2:34:40which is now uh 10 because we input five
  4169. 2:34:43and the function doubles it number times
  4170. 2:34:45two. We get that result and then we can
  4171. 2:34:47use it in another expression. So let's
  4172. 2:34:50say we have the total we do double five
  4173. 2:34:53double3 and then we get 16. So you can
  4174. 2:34:56see how we can now start to combine
  4175. 2:34:58things right. We take this function and
  4176. 2:35:00we use it just in an expression. So
  4177. 2:35:03instead of just first storing the
  4178. 2:35:04results we look double five that will
  4179. 2:35:08output 10 and double three will output
  4180. 2:35:11six and we can simply combine that right
  4181. 2:35:14like this will be 10 we store it in
  4182. 2:35:16total and now we have total and we can
  4183. 2:35:19print this over here and we can also use
  4184. 2:35:21it in a condition. So we can say look if
  4185. 2:35:23double 7 is bigger than 10 we say it's a
  4186. 2:35:27big number. So the like this is this
  4187. 2:35:30this can get a little bit tricky to to
  4188. 2:35:32work with but that's why I why I love
  4189. 2:35:34the interactive session because you can
  4190. 2:35:36literally look at okay what does double
  4191. 2:35:387 do by selecting this using the uh
  4192. 2:35:40arrow command uh arrow on your keyboard
  4193. 2:35:43and shift and I can look this is 14 so
  4194. 2:35:46now I do if double 7 which is 14 is
  4195. 2:35:50greater than 10 it's a big number so now
  4196. 2:35:52if I run this it will say big number but
  4197. 2:35:54if I say let's say we do three and I run
  4198. 2:35:57this it will not do anything. And within
  4199. 2:35:59functions, we can also return multiple
  4200. 2:36:01values similar to how we could also
  4201. 2:36:03input multiple parameters, right? So,
  4202. 2:36:06let's do a let's do a just a simple
  4203. 2:36:09function just as an example. Uh we
  4204. 2:36:12define it and then say look, we have a
  4205. 2:36:14we have our numbers. Let's say we have
  4206. 2:36:17our numbers which is a list. We do 1 2 3
  4207. 2:36:214 5. You should actually do some spaces
  4208. 2:36:24in here for clarity. So we have the
  4209. 2:36:27numbers in here and then what we want to
  4210. 2:36:28return or let's say first we do we do
  4211. 2:36:31the first number and that is going to be
  4212. 2:36:34our we have our numbers and then
  4213. 2:36:36remember this is a list right and we can
  4214. 2:36:38index that by using the uh square
  4215. 2:36:40brackets and then we do index zero this
  4216. 2:36:42refers to the one so this is the first
  4217. 2:36:44number and then let's say we do the last
  4218. 2:36:48number and that is going to be uh let's
  4219. 2:36:51see we take that same thing numbers and
  4220. 2:36:54then we do minus one and then what we
  4221. 2:36:56can do is we can return first number and
  4222. 2:36:59then we do a comma. So this is syntax
  4223. 2:37:01again. So it's not end or n. We do a
  4224. 2:37:04comma to say look we want to return the
  4225. 2:37:06first number and we want to return the
  4226. 2:37:08last number. And then what we can do is
  4227. 2:37:11we can for example let's say if we have
  4228. 2:37:13this here in memory we can call our
  4229. 2:37:16simple uh function with doesn't take any
  4230. 2:37:19input parameters right now. And then if
  4231. 2:37:22we want to store that we could for
  4232. 2:37:23example say first number and then comma
  4233. 2:37:26again last number and we can capture
  4234. 2:37:29that. So now if we run this you'll find
  4235. 2:37:32that we have first number one last
  4236. 2:37:34number is five. And the thing to keep in
  4237. 2:37:36mind here is that the variables over
  4238. 2:37:38here do not have to be the same as what
  4239. 2:37:41we put over here. So we could for
  4240. 2:37:43example just as well do f and l and it
  4241. 2:37:45would also work. So now we have if we we
  4242. 2:37:48do it via print statement we could print
  4243. 2:37:49our f which is one or we could just look
  4244. 2:37:51at f over here is one and in a similar
  4245. 2:37:54fashion our l is five. So that's how you
  4246. 2:37:58return multiple values from a function.
  4247. 2:38:01And that also wraps up the section here
  4248. 2:38:04on functions where the most important
  4249. 2:38:06thing to keep in mind here is that when
  4250. 2:38:08you're using functions, if you use a
  4251. 2:38:10print statement, it just displays it.
  4252. 2:38:12When you want to return something, which
  4253. 2:38:14is what you often want to do in the real
  4254. 2:38:16world, use the return. And in the
  4255. 2:38:19beginning, you'll make a lot of mistakes
  4256. 2:38:21with the syntax. You have to do it a
  4257. 2:38:23couple of times before it really clicks.
  4258. 2:38:25def function name colon indentation it
  4259. 2:38:28will get more and more familiar. Okay,
  4260. 2:38:30so with that let's dive into the next
  4261. 2:38:33section se section called external
  4262. 2:38:35tools. So here we are going to get into
  4263. 2:38:39one of Python's core tracks where we can
  4264. 2:38:42actually use a lot of like out ofthe-box
  4265. 2:38:45tools that other people have created for
  4266. 2:38:47us to make our life as a programmer much
  4267. 2:38:51more fun and way easier. So, we already
  4268. 2:38:54talked about packages, right? The pip
  4269. 2:38:56install things. In the beginning, I
  4270. 2:38:57showed you the request library. So, now
  4271. 2:38:59we're going to dive a little bit deeper
  4272. 2:39:01into that and show you a little bit more
  4273. 2:39:03examples. So, why Python is so awesome
  4274. 2:39:06and why I also like back in university.
  4275. 2:39:09So, this is 10 years ago when I when it
  4276. 2:39:11really start to click for me working
  4277. 2:39:13with Python was beyond all of the boring
  4278. 2:39:16stuff that they showed in the lectures
  4279. 2:39:18like what I show you right now. I know
  4280. 2:39:19this is boring, right? Writing a
  4281. 2:39:21function, like doing a print statement.
  4282. 2:39:22Yeah, but but Dave, what can we do with
  4283. 2:39:24it? This is where it gets cool because
  4284. 2:39:26now with simple packages that we can
  4285. 2:39:28import, we can scrape an entire website.
  4286. 2:39:30We can perform data analysis. We can
  4287. 2:39:32import AI and machine learning models.
  4288. 2:39:34We can use external APIs and we can
  4289. 2:39:36automate stuff on our computer. And
  4290. 2:39:38building something like that from
  4291. 2:39:40scratch as a beginner would be
  4292. 2:39:43impossible. But I'm going to show you
  4293. 2:39:44how you can import those packages, work
  4294. 2:39:46with them, and it's going to be super
  4295. 2:39:48fun. So let's first quickly cover some
  4296. 2:39:50terminology and then we'll get into the
  4297. 2:39:52examples. But in Python there is a big
  4298. 2:39:55difference between built-in packages.
  4299. 2:39:57These already come with Python. So you
  4300. 2:40:00can use them right now without an
  4301. 2:40:01installation and external libraries. You
  4302. 2:40:04need to install those for example
  4303. 2:40:05through pip first. That's a distinction.
  4304. 2:40:07Not everything comes uh out of the box.
  4305. 2:40:10Now here's some terminology that you
  4306. 2:40:12should be aware of. So this will get you
  4307. 2:40:14get more familiar with this over time
  4308. 2:40:16but you sometimes hear me refer to like
  4309. 2:40:18now I'm talking about packages and
  4310. 2:40:20before we were uh creating functions
  4311. 2:40:22right later we'll get into classes and
  4312. 2:40:24you also have what's called modules. So
  4313. 2:40:27here's a quick overview in Python as
  4314. 2:40:29Python programmers among each other when
  4315. 2:40:31we say module we mean a single Python
  4316. 2:40:34file. So our hello.py Pi over here. You
  4317. 2:40:38could consider this a module. And right
  4318. 2:40:41now we like this is all we know, right?
  4319. 2:40:43We have only have worked with a single
  4320. 2:40:45Python file. But when we go beyond that,
  4321. 2:40:47what you actually do in the real world
  4322. 2:40:49is you create all kinds of files that
  4323. 2:40:51work with each other and that talk with
  4324. 2:40:53each other. All of these files you can
  4325. 2:40:54call those modules, right? So then a
  4326. 2:40:56package is a folder containing multiple
  4327. 2:40:58modules. So we'll we'll cover this
  4328. 2:41:01later. When we install a package, you'll
  4329. 2:41:03find that we can use various bits and
  4330. 2:41:05pieces from it. And then within the uh
  4331. 2:41:08packages and within the modules, we can
  4332. 2:41:10then import the functions. And that is
  4333. 2:41:12really where we get to the core
  4334. 2:41:13functionality of what we can do with it.
  4335. 2:41:15Right? So think of it like this. There's
  4336. 2:41:17kind of like a mental model. A module is
  4337. 2:41:19like a toolbox or tools in there. A
  4338. 2:41:21package is like a garage with multiple
  4339. 2:41:23toolboxes. So there's lots of stuff in
  4340. 2:41:25here. Then a function is a specific tool
  4341. 2:41:28from the toolbox like a hammer or a
  4342. 2:41:30screwdriver. You you really need it to
  4343. 2:41:31solve a particular problem. And then a
  4344. 2:41:33class is like a blueprint for building
  4345. 2:41:35tools. I think this is a really good
  4346. 2:41:37mental model to keep in mind right now.
  4347. 2:41:39Okay. So let's look at an example of
  4348. 2:41:41imports. And when you are importing uh
  4349. 2:41:45packages or modules you'll start at the
  4350. 2:41:48very top of the of the script. So we do
  4351. 2:41:50that at the top. That is just how we do
  4352. 2:41:52that in Python. And we also need it
  4353. 2:41:54before we can use it really. So if I
  4354. 2:41:57come in here and I show you I show you
  4355. 2:41:59first show you this step by step. There
  4356. 2:42:00are comments in here. uh we don't need
  4357. 2:42:02those but this is just to explain how it
  4358. 2:42:04works. We can do an import statement. So
  4359. 2:42:07this is the syntax import and then for
  4360. 2:42:09example we do math. So this is a builtin
  4361. 2:42:12module that is available within Python.
  4362. 2:42:15We don't have to install it. I can
  4363. 2:42:17simply run this and it will say look
  4364. 2:42:19import math and it will say okay this is
  4365. 2:42:21fine we can now use this. So I can for
  4366. 2:42:24example now use this module and I can
  4367. 2:42:26use a function from this module by
  4368. 2:42:28taking math dot and then for example
  4369. 2:42:31taking the square root which is sqrt
  4370. 2:42:34short for square root and I can plug in
  4371. 2:42:3616 and I can run that and now the output
  4372. 2:42:39is four. So now instead of having to
  4373. 2:42:41come up with like how do I calculate the
  4374. 2:42:42square root and how do I need to create
  4375. 2:42:44a custom function for that I just use
  4376. 2:42:46math and then I just use the square root
  4377. 2:42:49function. So that's how that works and
  4378. 2:42:51again like I've said you don't need
  4379. 2:42:53this. So you it could be as simple as
  4380. 2:42:55just import math and then here we do the
  4381. 2:42:58square root and now we we can store it
  4382. 2:43:00right that's how we can work with it.
  4383. 2:43:02But there is another way that's the
  4384. 2:43:04pattern over here. We can also import
  4385. 2:43:06specific items from a module. And here's
  4386. 2:43:10the syntax instead of just starting with
  4387. 2:43:12the import. So import math, we do from
  4388. 2:43:16math, import, and then the specific
  4389. 2:43:19functions that we want to use. So it's
  4390. 2:43:22very readable. It reads just like plain
  4391. 2:43:24English. That's why it's really nice.
  4392. 2:43:25And we can now instead of having to do
  4393. 2:43:28math dots square root, you'll see the
  4394. 2:43:32squiggly lines because Python will say,
  4395. 2:43:34look, I don't know what math is because
  4396. 2:43:36we didn't import math. We did from math.
  4397. 2:43:39So we looked into the toolbox and we
  4398. 2:43:42just took the square root and the pi. We
  4399. 2:43:44just took the hammer and the wrench, not
  4400. 2:43:46the entire toolbox. So pi python doesn't
  4401. 2:43:48know what the toolbox is right now, but
  4402. 2:43:50we do know what square root is. And we
  4403. 2:43:53can plug in 16 and it works in a similar
  4404. 2:43:55way. So this is an introduction to how
  4405. 2:43:57you work with imports. And almost every
  4406. 2:44:00Python file that you will create will
  4407. 2:44:03start with some types of imports. So
  4408. 2:44:05this is really important to get used to.
  4409. 2:44:08So, Python has some very useful built-in
  4410. 2:44:11modules. So, for example, take the
  4411. 2:44:13random library and I'm just going to
  4412. 2:44:15show you these examples over here. So,
  4413. 2:44:18we can import the random module. So,
  4414. 2:44:20we'll do the entire thing. Import random
  4415. 2:44:22and we can use module functions. So, in
  4416. 2:44:25here we can say look, we can do random
  4417. 2:44:27and then rand int from random integer is
  4418. 2:44:30a function that's available in here and
  4419. 2:44:33it takes as arguments a starting a
  4420. 2:44:36starting point and an end point. So it
  4421. 2:44:37gives a range and then we say look we
  4422. 2:44:39want a random number uh between 1 and 10
  4423. 2:44:41and now it gives us nine but we can run
  4424. 2:44:44this over and over and over again and
  4425. 2:44:46you'll see that every time we run this
  4426. 2:44:48it will be different. So that's how we
  4427. 2:44:50can rate random numbers but we can also
  4428. 2:44:52do a random choice. So whenever we can
  4429. 2:44:55also have a list and we can say random.
  4430. 2:44:57Choice and then in here if we run this
  4431. 2:44:59let's see um apple banana orange and
  4432. 2:45:02then we get what do we get? All right.
  4433. 2:45:06So, if you want to start an online uh
  4434. 2:45:09gambling app or casino, you can do that
  4435. 2:45:12with Python. You just plug in a bunch of
  4436. 2:45:14random integers and random choices and
  4437. 2:45:16you can now let people bet on whether
  4438. 2:45:18it's going to be an apple, banana, or an
  4439. 2:45:20orange. Well, there there's your next uh
  4440. 2:45:23project idea that you can start with.
  4441. 2:45:25Okay, so now coming back to other
  4442. 2:45:28built-in modules. There are plenty and
  4443. 2:45:30here are some useful ones. So for
  4444. 2:45:32example we have the datetime uh module
  4445. 2:45:34the library where we can work with all
  4446. 2:45:36kinds of dates. So we can get the date
  4447. 2:45:38right now we can get the time we can
  4448. 2:45:40calculate what the time will be or the
  4449. 2:45:42date will be in a week from now. Uh we
  4450. 2:45:44can interact with the operating system.
  4451. 2:45:46We can work with JSON data and these are
  4452. 2:45:49all libraries like I want to I just want
  4453. 2:45:51to show it to you right now. But there
  4454. 2:45:53is really a lot to these. So the best
  4455. 2:45:56way to like really learn about this. So
  4456. 2:45:58look, so now we have import daytime, we
  4457. 2:46:00have today, and then we can see today uh
  4458. 2:46:02today's date. But knowing
  4459. 2:46:05what how to use this. So daytime uh
  4460. 2:46:08knowing that you need to do date today,
  4461. 2:46:10that's all stuff where for example you
  4462. 2:46:12go to chat GPT how what can I do with
  4463. 2:46:16the daytime lip in Python? this is
  4464. 2:46:20really the way to go because even for me
  4465. 2:46:22like under or remembering the very
  4466. 2:46:24specifics of oh the daytime library how
  4467. 2:46:27do I specifically get the time right now
  4468. 2:46:29in a specific format I don't know that
  4469. 2:46:32and I don't have to remember that
  4470. 2:46:33because AI is there for me so now you
  4471. 2:46:36can see look we can get the current date
  4472. 2:46:37and time you can also just get the date
  4473. 2:46:39and time you can also get specific dates
  4474. 2:46:42or time so there's so much stuff that
  4475. 2:46:44you can do with it and all kinds of
  4476. 2:46:46formatting but that's the beauty of AI
  4477. 2:46:47right now you just need to be aware of
  4478. 2:46:49oh look whenever I want to do something
  4479. 2:46:52in Python with dates we have the daytime
  4480. 2:46:55library and if you forget even that you
  4481. 2:46:57can just ask chat GBT like what's that
  4482. 2:46:59library again that you can do stuff with
  4483. 2:47:01dates with in Python it be look it's the
  4484. 2:47:03daytime library and that's how you do it
  4485. 2:47:05so with this you can like figure out all
  4486. 2:47:07kinds of uh calculations uh everything
  4487. 2:47:10that you want to do with a date is
  4488. 2:47:12possible in here okay and then we have
  4489. 2:47:14working with the operating system so
  4490. 2:47:17Python can also like do literally do
  4491. 2:47:19anything on on your computer. It can can
  4492. 2:47:22create files. It can browse files. It
  4493. 2:47:23can create folders. It can read files.
  4494. 2:47:26We can do all of that stuff. And we'll
  4495. 2:47:27we'll see some examples later down the
  4496. 2:47:29line. So I can come in here. So that's
  4497. 2:47:31the OS from the operating system. So we
  4498. 2:47:34import it and we can say look what's the
  4499. 2:47:36current uh working directory. So we can
  4500. 2:47:37print it. You can say look uh we're
  4501. 2:47:39currently in here in my Dropbox in my
  4502. 2:47:41Python projects. So this is where we're
  4503. 2:47:43currently at. So it understands that.
  4504. 2:47:45And we have one to work with JSON data
  4505. 2:47:47which we'll cover later. is very common
  4506. 2:47:49when you're working with AI. So there's
  4507. 2:47:50a lot of stuff in the Python uh
  4508. 2:47:52programming language already that we can
  4509. 2:47:54use. All right, then quick uh summary on
  4510. 2:47:58importing methods. So we can import the
  4511. 2:48:00entire module, right? We've seen that we
  4512. 2:48:02can import specific functions by doing
  4513. 2:48:04from module import and then the function
  4514. 2:48:07name. We can also import with an alias.
  4515. 2:48:10So let's say you have the pandas library
  4516. 2:48:12which we will uh use in the in the next
  4517. 2:48:14lessons. you'll find that we're going to
  4518. 2:48:16do import pandas as then we import it as
  4519. 2:48:19pd. So whenever we want to use pandas,
  4520. 2:48:21we don't just have to write it out. We
  4521. 2:48:23do pd. And in Python, this is also like
  4522. 2:48:25one of those um styling things where for
  4523. 2:48:28some libraries, there's just like we all
  4524. 2:48:30as developers have agreed agreed like if
  4525. 2:48:33you use pandas, you import it as pandas
  4526. 2:48:35spd. That's just the way we do it. Do
  4527. 2:48:37you have to do it like that? No. Uh but
  4528. 2:48:40that's using an alias. So that's also
  4529. 2:48:42one more thing that there is. You can
  4530. 2:48:43also import everything from a module. So
  4531. 2:48:45by using the asterisk, you don't want to
  4532. 2:48:48do that. Okay. So then let's get into
  4533. 2:48:50installing packages. And we've already
  4534. 2:48:53uh seen a sneak preview of this. So now
  4535. 2:48:55we need to get back to the terminal
  4536. 2:48:57again. Remember what that was, right? So
  4537. 2:48:59quick refresher. Let's see. We're in
  4538. 2:49:01here. Let's open up the side window
  4539. 2:49:03again to uh quickly get zoom out a
  4540. 2:49:06little bit. Look where are we? We are in
  4541. 2:49:08our Python forai folder and we have this
  4542. 2:49:11virtual environment, right? And uh if we
  4543. 2:49:14want to open up the terminal, you go
  4544. 2:49:15over here, you do new terminal. And
  4545. 2:49:18there we are. And now remember, right,
  4546. 2:49:20we can use the pip install. So now we
  4547. 2:49:21can do pip install. We already installed
  4548. 2:49:24the request library. So you can do that
  4549. 2:49:25one more time. It will probably say look
  4550. 2:49:27this is already satisfied. And we can
  4551. 2:49:28for example also let's do a pip install.
  4552. 2:49:31Do pandas. Let's do the pandas library.
  4553. 2:49:33Well, because we'll use that uh later
  4554. 2:49:35on. So this will take some time. We'll
  4555. 2:49:36go through everything. So this is how we
  4556. 2:49:39install packages in there. And once
  4557. 2:49:41that's done, what we can now do, I can
  4558. 2:49:44now do an import. So let's do uh import
  4559. 2:49:47pandas. And remember pandas, you import
  4560. 2:49:49that as an alias, right? Um so we do
  4561. 2:49:52import pandas pd. And now let's see if
  4562. 2:49:55this works. And there we go. We can now
  4563. 2:49:57import the pandas library. But if I try
  4564. 2:49:59to import a library that's not installed
  4565. 2:50:01yet. So for example, let's do from let's
  4566. 2:50:04say from pientic import uh base. Let's
  4567. 2:50:08do base model. So if I do it like this
  4568. 2:50:11you can see uh there's no module named
  4569. 2:50:13paidentic. So this is a very common
  4570. 2:50:15issue in the beginning even when you
  4571. 2:50:17install pandas for example and you want
  4572. 2:50:19to try and import it if you get module
  4573. 2:50:21not found errors it's not installed or
  4574. 2:50:24it's not installed in the correct
  4575. 2:50:25environment. So you may open up a
  4576. 2:50:28terminal that where your virtual
  4577. 2:50:30environment is not activated. So you
  4578. 2:50:32don't see the fan over here. That's one
  4579. 2:50:34of the most common beginner mistakes and
  4580. 2:50:36it can be super frustrating because then
  4581. 2:50:38you're following along and you're typing
  4582. 2:50:40everything but then you just need to
  4583. 2:50:41select the right Python interpreter and
  4584. 2:50:44then make sure when you open up the
  4585. 2:50:46terminal when you have the right
  4586. 2:50:48environment selected that the virtual
  4587. 2:50:50environment is activated. So that's one
  4588. 2:50:52of the most common mistakes that you'll
  4589. 2:50:54run into. Now when it comes to packages
  4590. 2:50:56we can also install specific versions.
  4591. 2:50:58So if we for example look up this
  4592. 2:51:00request library and do we do request pip
  4593. 2:51:02and we go to the Python package index
  4594. 2:51:05you can find the whole history of the
  4595. 2:51:07request library and you can see that
  4596. 2:51:09currently the latest version uh is this
  4597. 2:51:11one over here like usually you can go to
  4598. 2:51:14the uh to the GitHub page as well. Yeah,
  4599. 2:51:17here's the source. So you can literally
  4600. 2:51:19see like all this is is just a
  4601. 2:51:22collection of Python files that other
  4602. 2:51:23people already created and you can see
  4603. 2:51:25all of the info here. You can see the
  4604. 2:51:26examples. Uh so here you can also say
  4605. 2:51:28look this is now the latest version but
  4606. 2:51:31if I want to install a specific version
  4607. 2:51:34or I want to lock a certain function
  4608. 2:51:36because like sometimes things change and
  4609. 2:51:37you have an older project where you need
  4610. 2:51:39a specific version otherwise you get
  4611. 2:51:41errors you can do it like this you do
  4612. 2:51:43pip install and you do two equals so
  4613. 2:51:46that's uh it's not one it's two and then
  4614. 2:51:48if I come in here let's see we open up
  4615. 2:51:50another terminal so the request library
  4616. 2:51:53is already installed but I can override
  4617. 2:51:55this by running this command and now it
  4618. 2:51:59will downgrade it. So you will find over
  4619. 2:52:01here it successfully uninstalled the the
  4620. 2:52:04the version that we had. So it was the
  4621. 2:52:05latest version and it successfully
  4622. 2:52:07installed an older version in this case.
  4623. 2:52:11So that's also something that you can
  4624. 2:52:12do. You can also install multiple
  4625. 2:52:14packages. So on one line you can do for
  4626. 2:52:16example you can install pandas, numpy,
  4627. 2:52:18mattplot lip all in once. And let's see
  4628. 2:52:22let's come over here. It will totally
  4629. 2:52:24work. So we'll run this. As you can see
  4630. 2:52:27over here, this is all finishing going
  4631. 2:52:29after each other. So that's how you can
  4632. 2:52:30install multiple packages. But when
  4633. 2:52:33you're working with Python, there's one
  4634. 2:52:34more key concept that you'll find in
  4635. 2:52:36almost every tutorial that you'll follow
  4636. 2:52:38and it's also essential when you are
  4637. 2:52:40working together with other people on a
  4638. 2:52:42project. And that is the notion of a
  4639. 2:52:43requirements.txt
  4640. 2:52:45file. So this is a file that we can
  4641. 2:52:47store inside our project where that
  4642. 2:52:50looks something like this where there is
  4643. 2:52:51a specification of all the packages that
  4644. 2:52:53we use and also the versions and then
  4645. 2:52:56instead of new members manually adding
  4646. 2:52:59everything we can run a simple a single
  4647. 2:53:01command that will install everything
  4648. 2:53:04from that text file and that text file
  4649. 2:53:07is going to be the requirements.txt
  4650. 2:53:09file. So we can in a similar fashion we
  4651. 2:53:12don't also have to create this manually.
  4652. 2:53:14we can simply work on our project and
  4653. 2:53:15then whenever we want to freeze all of
  4654. 2:53:18the requirements, we can hit a pip pip
  4655. 2:53:20freeze and then uh push it to
  4656. 2:53:21requirements.txt.
  4657. 2:53:23So let's see what that looks like in
  4658. 2:53:25action. So first uh I'm I want you to
  4659. 2:53:28create one from scratch. So what we can
  4660. 2:53:29do is we can simply copy
  4661. 2:53:30requirements.txt.
  4662. 2:53:32We come in here and let's see I am going
  4663. 2:53:35to create a new file requirements.txt.
  4664. 2:53:38So this is just a text file. We can put
  4665. 2:53:40anything in here. And now what we can do
  4666. 2:53:41is for example we can come in here. We
  4667. 2:53:44can copy this specific section over
  4668. 2:53:47here. Come back to our project. And now
  4669. 2:53:50we have a requirements.txt file. And now
  4670. 2:53:53what we can do is we can use the
  4671. 2:53:54following following command. So it's pip
  4672. 2:53:56install-r requirements.txt.
  4673. 2:53:59So let's copy this. Come back to our
  4674. 2:54:01project. So make sure you have your
  4675. 2:54:02virtual environment selected. We can
  4676. 2:54:04open up a new terminal and let's see
  4677. 2:54:07that will open. It will load the
  4678. 2:54:08environment. And now if I do this pip
  4679. 2:54:10install our requirement.txt,
  4680. 2:54:13we run this, it will install everything
  4681. 2:54:15that's in here. And now we have
  4682. 2:54:17successfully uh added all of that to our
  4683. 2:54:19environment. Now if I close out of this
  4684. 2:54:22and now I can show you how the pip
  4685. 2:54:24freeze works. So let's say we completely
  4686. 2:54:25get rid of this and we don't keep track
  4687. 2:54:27of that, but we were just working on our
  4688. 2:54:29project. We do pip install this, pip
  4689. 2:54:30install that, and now we want to put
  4690. 2:54:33that into a requirements.txt file. We
  4691. 2:54:36can come over here and we can do pip pip
  4692. 2:54:38freeze and we can use the arrow sign to
  4693. 2:54:40put it in requirements.txt.
  4694. 2:54:43So we can copy this. Come over here. We
  4695. 2:54:46do pip freeze requirements.xt. And what
  4696. 2:54:49you'll find right now is now it's
  4697. 2:54:50creating the txt file in here and you
  4698. 2:54:52find all of the exact same verses in
  4699. 2:54:55there. Now what's also one nice thing
  4700. 2:54:57about working with Visual Studio Code.
  4701. 2:54:59If you are in here for example and let's
  4702. 2:55:02say we get rid of our virtual
  4703. 2:55:03environment. So let's say this is a
  4704. 2:55:06fresh new project that someone else was
  4705. 2:55:08working on and they shared it with you.
  4706. 2:55:09So there are requirements in here. What
  4707. 2:55:11we can now do we can follow the same
  4708. 2:55:13process where we do look we want to
  4709. 2:55:14create a virtual environment. We say we
  4710. 2:55:16use fence and now we can say we want to
  4711. 2:55:19use this python installation. We use the
  4712. 2:55:20latest one. And now because there is a
  4713. 2:55:22requirement.txt file in our folder it is
  4714. 2:55:25asking us like look do you want to
  4715. 2:55:27install any dependencies. So we can say
  4716. 2:55:29yes and we do okay. And now it's
  4717. 2:55:31creating the environment and also
  4718. 2:55:32installing the dependencies in one shot.
  4719. 2:55:35So this is something like I said very
  4720. 2:55:37common whenever you are working on an
  4721. 2:55:40external project. Someone is sharing
  4722. 2:55:41code via git and github that we will
  4723. 2:55:43show uh I will introduce to you later if
  4724. 2:55:45you're new to that. This will always be
  4725. 2:55:47a starting point because they'll likely
  4726. 2:55:49be using packages and you want to make
  4727. 2:55:51sure you get all the same versions so
  4728. 2:55:53you you will exactly know that the code
  4729. 2:55:55will work. All right. So that's a quick
  4730. 2:55:57introduction to how you can install
  4731. 2:55:59external packages and then also how you
  4732. 2:56:01can import them right now. How do you
  4733. 2:56:03find packages? Well, right now the best
  4734. 2:56:05place to do that really is chatgbt.
  4735. 2:56:07There are lots of list and websites. But
  4736. 2:56:09right now if you want to solve a problem
  4737. 2:56:10with Python, you should really ask like
  4738. 2:56:12how can I do this in Python and are
  4739. 2:56:14there any packages that can help me with
  4740. 2:56:15that? And GBT will literally give you a
  4741. 2:56:17list of all the packages that are useful
  4742. 2:56:19for that, how to install them, how to
  4743. 2:56:20work with them and we'll point you to
  4744. 2:56:22the documentation. Okay. Common
  4745. 2:56:24mistakes, import errors. make sure that
  4746. 2:56:26is installed correctly. Naming conflicts
  4747. 2:56:29can also be an issue. So this is also
  4748. 2:56:32one of the things you should be aware
  4749. 2:56:33of. If you for example import uh daytime
  4750. 2:56:36and then you create a variable now the
  4751. 2:56:39daytime then the import is then gone.
  4752. 2:56:41You override it. Remember right so when
  4753. 2:56:43we for example were talking about the
  4754. 2:56:44discount set discount to 10 and then you
  4755. 2:56:46if you override that it's 20. Similar is
  4756. 2:56:49with import. It's just a variable name.
  4757. 2:56:51It's just a placeholder for uh Python.
  4758. 2:56:53So that's something you should be aware
  4759. 2:56:55of. Okay, so we've covered external
  4760. 2:56:59tools introduction importing packages
  4761. 2:57:01both builtin um and external. Now let's
  4762. 2:57:05cover working with APIs. So this is one
  4763. 2:57:08of the it's a really common thing when
  4764. 2:57:10you are uh working on AI projects and
  4765. 2:57:13that's why I want to explain it already
  4766. 2:57:15here. it it may already be a little bit
  4767. 2:57:17more advanced, but this is just such a
  4768. 2:57:20core skill that you need to understand
  4769. 2:57:21because when you are building AI systems
  4770. 2:57:24and agents, what you are essentially
  4771. 2:57:26doing is you're taking information from
  4772. 2:57:28some type of input from some type of
  4773. 2:57:30system and you want to do something with
  4774. 2:57:31that, right? You want to pull data from
  4775. 2:57:33a CRM. You want to get order information
  4776. 2:57:35from Shopify or Wukcommerse or you want
  4777. 2:57:37to send a message through Slack or an
  4778. 2:57:39email service or use the models from
  4779. 2:57:41OpenAI or Entropic. That's all done
  4780. 2:57:44through using APIs. So, let's look at
  4781. 2:57:47this. And for this, we're going to use
  4782. 2:57:49the requests library which we've already
  4783. 2:57:52installed. And I'm going to show you how
  4784. 2:57:54to work with a free and open-source API.
  4785. 2:57:57This is a weather API. So, let's go
  4786. 2:58:00through this uh step by step. And you
  4787. 2:58:02can for this you can actually copy paste
  4788. 2:58:03it because I don't want you to fully
  4789. 2:58:05like type this over and then we are
  4790. 2:58:07going to work with this. So, let's see.
  4791. 2:58:08Don't save this. Uh let's go. We can
  4792. 2:58:11close this out again. Okay, there we go.
  4793. 2:58:14Back into things. So from the top, we
  4794. 2:58:17import the request library. The quest
  4795. 2:58:19request library is a Python library that
  4796. 2:58:22we can use to interact with APIs. Now
  4797. 2:58:25the uh URL that we have over here is
  4798. 2:58:28just something that you need to look up
  4799. 2:58:30in this case. So every API that you use
  4800. 2:58:33will have instructions. You can look
  4801. 2:58:35into the documentation says look here's
  4802. 2:58:36the URL and here are parameters that you
  4803. 2:58:39can plug in there in order to interact
  4804. 2:58:41with this uh API. So you can see this is
  4805. 2:58:44api.openo.com
  4806. 2:58:46or v1 forecast and then what we need to
  4807. 2:58:48plug in is a latitude and a longitude.
  4808. 2:58:51So that's how we can get the weather
  4809. 2:58:53information from a location. Here we we
  4810. 2:58:57know that the latitude and longitude of
  4811. 2:58:59Paris like we just set that to this.
  4812. 2:59:01This is not something you have to
  4813. 2:59:02remember but this is just as an example.
  4814. 2:59:04this AI gave this to me. So, we're
  4815. 2:59:06assuming this is correct. And then we
  4816. 2:59:08have the URL. And look what you can see
  4817. 2:59:10right now. Now, we have built up the URL
  4818. 2:59:13over here. And you can see that because
  4819. 2:59:15we were using frings, you can now see
  4820. 2:59:17that the latitude and the longitude are
  4821. 2:59:20plugged in. Right? So, now we're
  4822. 2:59:22bringing more and more of what we've
  4823. 2:59:24learned together. So, this is an F
  4824. 2:59:25string. Now, we can use the request
  4825. 2:59:27library. So we do request and then we do
  4826. 2:59:31get using the URL over here to make an
  4827. 2:59:34API call. So let's run that. And you can
  4828. 2:59:37see we have a green check mark. Let's
  4829. 2:59:39have a look at what's in here. We get a
  4830. 2:59:42response that says 200. And in the world
  4831. 2:59:44of APIs that means 200 is okay. 200 is
  4832. 2:59:48good. And for now you don't have to
  4833. 2:59:50understand why. We're just going through
  4834. 2:59:52this exercise. Uh so just follow along
  4835. 2:59:54with me. And what we can now do is the
  4836. 2:59:56response that we got back, we want to
  4837. 2:59:59look at the data that's underneath that.
  4838. 3:00:01And for that within the request library,
  4839. 3:00:03we can call thejson function to have a
  4840. 3:00:07look at the data. So now we do that. And
  4841. 3:00:09then if we print the data or look at the
  4842. 3:00:12data over here, you can see that this is
  4843. 3:00:14the information that we got back from
  4844. 3:00:16the API. So you can see the input
  4845. 3:00:18parameters let long. And then over here,
  4846. 3:00:21let's see. You can see like the current
  4847. 3:00:24time over here. So this is the time in
  4848. 3:00:27uh UTC right now in the UTC time zone.
  4849. 3:00:30And you can see that let's see over
  4850. 3:00:32here. Make sure we can see everything.
  4851. 3:00:34We have the temperature and then the
  4852. 3:00:36interval. And we can see it's uh 13.1°
  4853. 3:00:41C. The interval here is seconds. So this
  4854. 3:00:44is really this is really cool, right? So
  4855. 3:00:45now we were able with just a few lines
  4856. 3:00:49of Python to extract and capture the
  4857. 3:00:52information from what's the weather
  4858. 3:00:53right now, right now in Paris. Okay, so
  4859. 3:00:56now you can hopefully see that this is
  4860. 3:00:58actually starting to get a little bit
  4861. 3:00:59useful, right? We can actually do stuff
  4862. 3:01:01and let's actually have a look at let's
  4863. 3:01:03do this one more time and let's look at
  4864. 3:01:05this data object over here that we're
  4865. 3:01:08getting back. So if we look at this and
  4866. 3:01:11if we look at the type of this data that
  4867. 3:01:15we have over here, we can see that this
  4868. 3:01:16is a Python dictionary. And this means
  4869. 3:01:20that what we can do right now based on
  4870. 3:01:22everything that we learned about using a
  4871. 3:01:24dictionary, we can also access specific
  4872. 3:01:27keys and then the values in there using
  4873. 3:01:30the keys. So if in our program right now
  4874. 3:01:32for example, we just wanted to get the
  4875. 3:01:34temperature. What we could do is we
  4876. 3:01:35could either look at the data over here
  4877. 3:01:37and we say look we have at the top level
  4878. 3:01:39over here you so you need to be aware of
  4879. 3:01:41the small indents over here which are
  4880. 3:01:42nested dictionaries. You can see that
  4881. 3:01:45here we have under current we have a a
  4882. 3:01:48nested dictionary and in here is the
  4883. 3:01:50temperature. So we can view that like
  4884. 3:01:53this. So first of all we can have a look
  4885. 3:01:54at all of the keys. So we can indeed see
  4886. 3:01:56look there is a current. So you can see
  4887. 3:01:59it all the way. Let me move this around
  4888. 3:02:00so you can see a current. That is the
  4889. 3:02:03last key that is in here. So let's have
  4890. 3:02:06a look at what that looks like if we now
  4891. 3:02:08take the dictionary and remember
  4892. 3:02:10indexing for a dictionary is using the
  4893. 3:02:12square brackets and then we plug in the
  4894. 3:02:14key. So now if I let's clear this up for
  4895. 3:02:17you to show it. Now you can say look
  4896. 3:02:19from this data it's it's it's a
  4897. 3:02:22dictionary. There's a lot of information
  4898. 3:02:23in there but now I just want the current
  4899. 3:02:25and the current key has the following
  4900. 3:02:27information here. So we have the time,
  4901. 3:02:29we have the interval and we have the
  4902. 3:02:30temperature. So then what we can do is
  4903. 3:02:33we can continue to do that because this
  4904. 3:02:37if I look at this, this is still a
  4905. 3:02:39dictionary. You can have dictionaries
  4906. 3:02:41inside dictionaries. So now we can just
  4907. 3:02:43continue the pattern and we can simply
  4908. 3:02:46do another lookup with another key. And
  4909. 3:02:49now you can see that we have the actual
  4910. 3:02:52temperature. So this is now something
  4911. 3:02:53that we could actually store. So we can
  4912. 3:02:55store the temperature and now we have
  4913. 3:02:57captured this in such a way where we can
  4914. 3:02:59program programmatically use the
  4915. 3:03:01temperature and I know that we're moving
  4916. 3:03:03quick here. We're make we're making big
  4917. 3:03:05steps because right now instead of like
  4918. 3:03:07just focusing on new concepts we're also
  4919. 3:03:10bringing in previous concepts that we
  4920. 3:03:12already covered, right? And now it's
  4921. 3:03:13like oh wait wait wait yes dictionaries
  4922. 3:03:15and then oh what was the syntax again?
  4923. 3:03:17How do we do that? Uh but that's the
  4924. 3:03:19learning process. We make it more and
  4925. 3:03:21more complex over time. So here you can
  4926. 3:03:23see one more time in the docs uh and at
  4927. 3:03:25any time if you feel like oh this is a
  4928. 3:03:26little bit too much go back to the docs
  4929. 3:03:28there's more info there you can see the
  4930. 3:03:29nested structure that's uh that's in
  4931. 3:03:32there. Okay so now we can also go one
  4932. 3:03:35step further and actually start to
  4933. 3:03:37create a function around this to capture
  4934. 3:03:40just what we need. So let's have a look
  4935. 3:03:42at what's going on over here. So if we
  4936. 3:03:44structure it like this, we can now
  4937. 3:03:46actually start to build a program where
  4938. 3:03:48we say look we import the request
  4939. 3:03:50library. We have a function which is
  4940. 3:03:53called get weather and we do def get
  4941. 3:03:55weather and then we plug in the
  4942. 3:03:57parameters. So we have latitude
  4943. 3:03:58longitude and then we say look the
  4944. 3:04:00response is and then we do exactly the
  4945. 3:04:03same that we already did, right? So this
  4946. 3:04:04is what we did in the previous step. We
  4947. 3:04:06get the data and then we return the data
  4948. 3:04:09current and then we take the
  4949. 3:04:10temperature. So you see what we're doing
  4950. 3:04:11over here. This is where like now this
  4951. 3:04:13is where we start to actually like
  4952. 3:04:15become a programmer. This is
  4953. 3:04:17programming. We figure out some logic.
  4954. 3:04:19We know how to solve it and then we we
  4955. 3:04:21put it into a function and then we we
  4956. 3:04:24return that. And now we can say look we
  4957. 3:04:26can get the weather or the temperature
  4958. 3:04:27in Paris right now which is 13.2.
  4959. 3:04:31We can get the temperature in London
  4960. 3:04:3311.8. And we can get the temperature in
  4961. 3:04:35Tokyo which is 19.1. And now we can
  4962. 3:04:39print all of those. This is cool, right?
  4963. 3:04:41So here you can see the beauty of using
  4964. 3:04:44functions and why why they are so useful
  4965. 3:04:47and how everything comes together and
  4966. 3:04:49especially if you can if you combine it
  4967. 3:04:51with external uh services and APIs that
  4968. 3:04:54other people make available and we
  4969. 3:04:55import the request library. Now all of a
  4970. 3:04:58sudden we have we can literally build a
  4971. 3:05:00weather alarm. So you could build a
  4972. 3:05:02program around this for your like
  4973. 3:05:03hometown or city. Whenever a temperature
  4974. 3:05:06is like either below or above a certain
  4975. 3:05:08threshold you can trigger something. So
  4976. 3:05:10summary of what we've learned. You send
  4977. 3:05:12the request to the API URL with
  4978. 3:05:14parameters like the cor the coordinates
  4979. 3:05:16that we did. The API processes your
  4980. 3:05:18requests and find the data sends it back
  4981. 3:05:20to you. You receive that data in a JSON
  4982. 3:05:23format which we then load into Python in
  4983. 3:05:25a dictionary and then you extract the
  4984. 3:05:27specific parts you need. So the pattern
  4985. 3:05:29here is always the same when you are
  4986. 3:05:31working with external APIs. You connect,
  4987. 3:05:33send requests, get data back and then
  4988. 3:05:35you use the information from it in
  4989. 3:05:37whatever shape or form you need it. And
  4990. 3:05:39APIs are really how modern software
  4991. 3:05:41systems comm communicate with each
  4992. 3:05:43other. So when you're building an AI
  4993. 3:05:45system, for example, that needs to
  4994. 3:05:46integrate with a ticketing system, you
  4995. 3:05:48look up that ticketing systems uh API
  4996. 3:05:51documentation, you need to probably get
  4997. 3:05:52an API key and then you can write Python
  4998. 3:05:55functions around that to capture
  4999. 3:05:56customer information or order
  5000. 3:05:58information or all of the apps that you
  5001. 3:06:01use on your laptop like right now.
  5002. 3:06:03Probably like 90% of them have a public
  5003. 3:06:05API that you can use. So, for example,
  5004. 3:06:07Slack or your favorite to-do app, they
  5005. 3:06:09all have APIs where you can extract the
  5006. 3:06:12key, understand the uh URL that you need
  5007. 3:06:14to connect with and the parameters that
  5008. 3:06:16you need to plug in there and then you
  5009. 3:06:17can send and receive information from it
  5010. 3:06:19into it. All right, so now next we are
  5011. 3:06:22going to we're going to the section
  5012. 3:06:23working with data and this is going to
  5013. 3:06:26be really cool. And here we're going to
  5014. 3:06:29ramp things up a little bit. In this
  5015. 3:06:31specific section, what I want you uh to
  5016. 3:06:34do is I just want you to follow along
  5017. 3:06:36and we're going to copy paste the code
  5018. 3:06:39snippets. You don't have to like type
  5019. 3:06:41all of this out because it's way too
  5020. 3:06:42much. And my goal with this section is
  5021. 3:06:45to show you what's possible with Python
  5022. 3:06:48because I always like I remember when I
  5023. 3:06:51was learning Python, the my favorite way
  5024. 3:06:53to learn was through reverse
  5025. 3:06:55engineering. So I would find the script
  5026. 3:06:57online and now with GPT it's even
  5027. 3:06:59easier. You literally tell it like,
  5028. 3:07:01"Hey, look to this." And then you see
  5029. 3:07:03the capabilities and you're like, "Whoa,
  5030. 3:07:05this is cool." And then you start to
  5031. 3:07:07connect the dots where you're like,
  5032. 3:07:08"Hey, if I can do this, I can probably
  5033. 3:07:11also do this. What would that look
  5034. 3:07:13like?" And then you start to look at the
  5035. 3:07:14code and then you start to play with the
  5036. 3:07:16the parameters and with the variables.
  5037. 3:07:18And then that's how you get a feel for
  5038. 3:07:21what you can do with this language. So
  5039. 3:07:23what we're going to do right now is
  5040. 3:07:25we're going to build on the API that we
  5041. 3:07:27just saw. We're going to load u a lot of
  5042. 3:07:29data and we're going to manipulate that
  5043. 3:07:32and we're going to visualize that. So in
  5044. 3:07:34order to follow along with this section,
  5045. 3:07:35you need uh the request library, the
  5046. 3:07:37pundas library and the mud plot lib
  5047. 3:07:39library. I already showed that in a
  5048. 3:07:42previous section where I showed you how
  5049. 3:07:43you can install multiple libraries. If
  5050. 3:07:45you did not run the command at that
  5051. 3:07:47point, you should do it now because we
  5052. 3:07:49need all of these libraries. Uh request
  5053. 3:07:51is to work with APIs, pundas is to work
  5054. 3:07:53with data and then the metplot library
  5055. 3:07:55is to create visualizations. So we can
  5056. 3:07:57create plots. First we're going to what
  5057. 3:07:59we're going to do and I what I recommend
  5058. 3:08:00is I recommend creating a new file for
  5059. 3:08:02this. So let's come in here. Let's clean
  5060. 3:08:04it up. And then I do uh command B. I do
  5061. 3:08:07new file. Let's call it do get data.py.
  5062. 3:08:11So new file. Make sure to give it a.py
  5063. 3:08:14extension. And then right now I can
  5064. 3:08:16close this one more time because this is
  5065. 3:08:17going to be a big script. And I want you
  5066. 3:08:19to I want you to save this as well so
  5067. 3:08:22you can later reference it. So, first
  5068. 3:08:24we're going to get 7 days of uh weather
  5069. 3:08:27data. So, I'm going to copy paste this
  5070. 3:08:29script. I'm going to plug it in here.
  5071. 3:08:31And I just want you to briefly go
  5072. 3:08:33through it with me to understand what's
  5073. 3:08:35going on over here. So, first at the
  5074. 3:08:37top, we start with the imports, right?
  5075. 3:08:39The request and then we do the daytime
  5076. 3:08:41library. Now you can see right now we
  5077. 3:08:43also import uh time delta which is a a
  5078. 3:08:46function in here that we can say look if
  5079. 3:08:48we have the daytime today which we can
  5080. 3:08:51get daytime now we can actually get a
  5081. 3:08:54week ago by saying time delta days is 7
  5082. 3:08:57and this programmatically understands
  5083. 3:08:59that okay look right now is today's date
  5084. 3:09:02we need to go 7 days back so let's let's
  5085. 3:09:04walk through this and I'm going to zoom
  5086. 3:09:06out a little bit so you can see
  5087. 3:09:08everything uh side by side let me see I
  5088. 3:09:10can go one over here. So I can do uh
  5089. 3:09:13daytime now which is going to give us
  5090. 3:09:16the exact timing right now like to the
  5091. 3:09:18millisecond and then we can do today and
  5092. 3:09:21then time delta 7 is a week ago. So you
  5093. 3:09:24can see a week ago is now uh visualized
  5094. 3:09:27over here. So you can see we can get uh
  5095. 3:09:30if you look at the date it goes all the
  5096. 3:09:32way back exactly one week. Okay. Now
  5097. 3:09:35we're going to format the dates for the
  5098. 3:09:38API because the API that we're working
  5099. 3:09:40with here the uh Paris AP or the get
  5100. 3:09:43weather API for Paris it expects this uh
  5101. 3:09:46format. So we need to uh specify the
  5102. 3:09:49year the month and then the date. So
  5103. 3:09:52what we can do is we can use this method
  5104. 3:09:55over here used essentially to conver
  5105. 3:09:58convert a day time into a specific
  5106. 3:10:00format. And why I said like look just
  5107. 3:10:02copy this right now because I understand
  5108. 3:10:05this is a lot. We have time delta. We
  5109. 3:10:07have this like strive time thingy. We
  5110. 3:10:09have all these uh commands over here.
  5111. 3:10:11For now we can just say look this gives
  5112. 3:10:13us the start date in exactly the way we
  5113. 3:10:16need it for the API and also the end
  5114. 3:10:18date in exactly the way we need it. So
  5115. 3:10:20now we have a date range. And now if you
  5116. 3:10:23look in here we can plug this into the
  5117. 3:10:26uh function where right now the latitude
  5118. 3:10:28and the longitude are hardcoded. So this
  5119. 3:10:30is always for Paris. We can change that
  5120. 3:10:32right now. And the the dynamic variables
  5121. 3:10:35in there are now the start date and the
  5122. 3:10:37end date. So let's run this. This is now
  5123. 3:10:40our URL. And now we can do the response.
  5124. 3:10:43We can get the data. And then we can
  5125. 3:10:46print it. And you can see right now,
  5126. 3:10:48let's see if I actually do it like this.
  5127. 3:10:51Now you can see that we have more data
  5128. 3:10:54in here where you can see the that we
  5129. 3:10:56have daily data for the past seven days.
  5130. 3:10:59And you can see the maximum and the
  5131. 3:11:00minimum for those those days. So now
  5132. 3:11:03instead of just getting like the current
  5133. 3:11:05temperature right now, we have more
  5134. 3:11:07information. So that was step number
  5135. 3:11:09one. So now let's continue. So now we're
  5136. 3:11:12going to load it into pandas. So pandas
  5137. 3:11:14is a library that you can use to
  5138. 3:11:16manipulate data. You can really think of
  5139. 3:11:18it as Excel but for uh for Python.
  5140. 3:11:22Pretty much anything that you can do in
  5141. 3:11:24Excel plus more you can also do with the
  5142. 3:11:26pandas library. And it's it's a really
  5143. 3:11:28great library. So I have a background as
  5144. 3:11:30a data scientist like for the first like
  5145. 3:11:323 years of my career like pandas is like
  5146. 3:11:35pretty much all I did. Pandas mod lip
  5147. 3:11:37and then machine learning libraries. But
  5148. 3:11:39this pandas was always the starting
  5149. 3:11:40point. So what we're going to do right
  5150. 3:11:42now is we're actually going to uh turn
  5151. 3:11:44this into a nice little script. So what
  5152. 3:11:45I'm going to do right now is I'm going
  5153. 3:11:47to paste this here. But now what I want
  5154. 3:11:49you to do is instead of take doing the
  5155. 3:11:51import here, I'm going to put that at
  5156. 3:11:53the top. That's just a style thing like
  5157. 3:11:55it works like to Python is totally fine
  5158. 3:11:58with having the imports in here. But you
  5159. 3:12:00should get used to having all the
  5160. 3:12:01imports at the top. And now what what
  5161. 3:12:04you can do over here is you can even
  5162. 3:12:05like do let's say we do a hashtag and
  5163. 3:12:08then we do kind of like a big line to
  5164. 3:12:10say look first this was the stuff with
  5165. 3:12:13the API. Now we're getting to the stuff
  5166. 3:12:16that we're doing with pandas. So when we
  5167. 3:12:19have the data that's still in memory. So
  5168. 3:12:22remember if you close this out and now
  5169. 3:12:25you come in here and you will try to do
  5170. 3:12:27this it will say data is not defined. So
  5171. 3:12:30make sure that whenever you're working
  5172. 3:12:31with the interactive session you keep it
  5173. 3:12:33open and you make sure you should think
  5174. 3:12:36about what what does Python currently
  5175. 3:12:37have in memory and if that's not the
  5176. 3:12:39case you need to rerun it. So now we
  5177. 3:12:41have the data once more and you can also
  5178. 3:12:43see how quick this is right this is
  5179. 3:12:44super nice if you close out of it now in
  5180. 3:12:471 second we have the last week week's
  5181. 3:12:50worth of data again. So now in here in
  5182. 3:12:52the data object we now it changed a
  5183. 3:12:55little bit. So before we had the current
  5184. 3:12:57key right but now that is not in there
  5185. 3:12:59because we didn't get the current data
  5186. 3:13:01we get the we get a date range. So now
  5187. 3:13:03we have the daily key. So we can get the
  5188. 3:13:05daily data which is a dictionary in here
  5189. 3:13:07which we see right now. So now we have
  5190. 3:13:09that information in here and now we're
  5191. 3:13:11going to turn that into a data frame.
  5192. 3:13:14And this is pandanda's uh way of saying
  5193. 3:13:16look if you have an excel spreadsheet
  5194. 3:13:18right you have the columns and you have
  5195. 3:13:20the rows you can create a nice little
  5196. 3:13:22table in pandas that is called a data
  5197. 3:13:24frame and again we have specific syntax
  5198. 3:13:27for how to do that we use in this case
  5199. 3:13:30pd because we imported pandas pd then we
  5200. 3:13:33use the data frame and then we need to
  5201. 3:13:35specify a specific structure in here for
  5202. 3:13:37now don't worry about how this works you
  5203. 3:13:40don't need to know that for now all you
  5204. 3:13:41need to do is run this. And now what we
  5205. 3:13:44can do if we now look into the data
  5206. 3:13:47frame, you can see that we actually have
  5207. 3:13:48a table in here that's very readable.
  5208. 3:13:51And that's one of the things that I like
  5209. 3:13:53about the panos library where if I look
  5210. 3:13:55at this, this is messy. Even though it's
  5211. 3:13:58the exact same information, right? And
  5212. 3:13:59computers love this. Computers love JSON
  5213. 3:14:02data and dictionaries because it's very
  5214. 3:14:03fast. It's very memory efficient. But
  5215. 3:14:06like I when I analyze data, this is this
  5216. 3:14:08is what I want to see because this is
  5217. 3:14:10very clear. I can exactly see just like
  5218. 3:14:12in Excel. Okay, awesome. This is
  5219. 3:14:14something that I can understand and that
  5220. 3:14:16we can now do stuff with. Now, one more
  5221. 3:14:18thing that we're going to do is we're
  5222. 3:14:20going to turn the actual date and we're
  5223. 3:14:23going to change the uh format because
  5224. 3:14:26out of the box and when you're working
  5225. 3:14:28with uh pandas, this is a very common
  5226. 3:14:29operation. the date right now it will be
  5227. 3:14:32a string because when you are uh sending
  5228. 3:14:36information back and forth via an API
  5229. 3:14:38using JSON JSON doesn't care about data
  5230. 3:14:41types it's all string based so now we
  5231. 3:14:44need to tell Python look this is
  5232. 3:14:45actually a uh this is actually a date
  5233. 3:14:48because that's going to unlock some of
  5234. 3:14:49the features that we can use for
  5235. 3:14:51plotting so it understands that uh there
  5236. 3:14:53is an order of operations and we can
  5237. 3:14:55change the scale so we run that and now
  5238. 3:14:58we have a data frame Let's see over here
  5239. 3:15:01it is exactly the same but now if we uh
  5240. 3:15:04now under the hood the date uh Python
  5241. 3:15:07understand that this is a date just
  5242. 3:15:09follow along copy executed make sure
  5243. 3:15:12that you have the data frame over here
  5244. 3:15:14like this and then we get to the next
  5245. 3:15:16step so you should see the output now
  5246. 3:15:18we're going to visualize it and this is
  5247. 3:15:20what we can do with the mattplot lip
  5248. 3:15:21library so first let's see I'm going to
  5249. 3:15:23copy all of this so you can see there's
  5250. 3:15:25a lot of information uh going on over
  5251. 3:15:27here over here let's do one more let's
  5252. 3:15:29just do a Quick break here to see look
  5253. 3:15:31now we're getting into Mattplot lip and
  5254. 3:15:33remember we put the imports at the top.
  5255. 3:15:37So now you can see yellow squiggly
  5256. 3:15:38lines. Python says look I don't know
  5257. 3:15:40what plt is. So we come over here we
  5258. 3:15:43plug it in here. And this is just one of
  5259. 3:15:45those things where mattplot lip and then
  5260. 3:15:48you need pipplot. Importing it as plt is
  5261. 3:15:51just something we do. It's just
  5262. 3:15:52something we all agreed on. I could do
  5263. 3:15:55anything here and it would work but plt
  5264. 3:15:58is the way we do it. So make sure you
  5265. 3:15:59import that as well. So now we import
  5266. 3:16:01the met plot lip library and now Python
  5267. 3:16:04understands look I can now use that PLT
  5268. 3:16:08and this again is a library has a whole
  5269. 3:16:10specific set of syntax and instructions
  5270. 3:16:12where we where we can create figures. So
  5271. 3:16:14we have a figure, we can plot it, we can
  5272. 3:16:16do the X label, we can do the Y label,
  5273. 3:16:18we can create a title, we can create a
  5274. 3:16:19legend. There are almost infinite
  5275. 3:16:22possibilities with this library as well.
  5276. 3:16:24But let's let's show what we can do over
  5277. 3:16:27here. There we go. Now we have created a
  5278. 3:16:30figure. So now you can see on the x-axis
  5279. 3:16:33over here you can see the dates of last
  5280. 3:16:35week. We see the minimum temperature and
  5281. 3:16:36the maximum temperature. And we have a
  5282. 3:16:38title Paris weather past 7 days
  5283. 3:16:41temperature here on uh on the y-axis.
  5284. 3:16:44This is now already a report that you
  5285. 3:16:47can create. And like I've said in the
  5286. 3:16:49beginning of my career working as a data
  5287. 3:16:51scientist and data analyst like this was
  5288. 3:16:53core part of my work and not necessarily
  5289. 3:16:56getting weather from weather data from
  5290. 3:16:58Paris but using company information and
  5291. 3:17:00more specifically IoT data from sensors
  5292. 3:17:03to analyze trends and to create reports.
  5293. 3:17:06And actually right now to this day like
  5294. 3:17:08still one client that I'm working with
  5295. 3:17:10I've I have a task in my inbox right now
  5296. 3:17:12where I need to create a report like
  5297. 3:17:14this and we have a whole Python uh
  5298. 3:17:17codebase that gets the data from from
  5299. 3:17:19the IoT sensors from the database and we
  5300. 3:17:21have it set up in such such a way where
  5301. 3:17:23the researchers get exactly the type of
  5302. 3:17:25plots that they're looking for. So now
  5303. 3:17:27we are quickly making moves and already
  5304. 3:17:29actually getting close to skills that
  5305. 3:17:32you can actually pli apply in the real
  5306. 3:17:34world and that you can even get paid
  5307. 3:17:36for. That's why I wanted to take a quick
  5308. 3:17:38leap here without you worrying about
  5309. 3:17:41okay look what's everything that's going
  5310. 3:17:43on over here but just show you some of
  5311. 3:17:45the possibilities and have a look over
  5312. 3:17:47here you also have the save fic in here.
  5313. 3:17:49Now if I open this up you can see it's
  5314. 3:17:51even saved as a PNG. So that's already
  5315. 3:17:54in here. So I can now create an email
  5316. 3:17:55say hey look client here's the weather
  5317. 3:17:58from in Paris from the past seven days
  5318. 3:18:00and I can email that. Python can also do
  5319. 3:18:02that. Now let's see there's one more
  5320. 3:18:04thing. Now we're also going to save it
  5321. 3:18:06to a CSV file. Create some separation.
  5322. 3:18:10Now we're going to use the OS library.
  5323. 3:18:12Put it at the top. Import it. Make sure
  5324. 3:18:14to import it. Let's see. Let's close
  5325. 3:18:16this. What we can do right now is we can
  5326. 3:18:20use the OS library to say look we want
  5327. 3:18:22to so we want to store we want to export
  5328. 3:18:24our data as a CSV file so we can for
  5329. 3:18:27example both send the image and also the
  5330. 3:18:29data set and now with the OS library we
  5331. 3:18:32say look if this path doesn't exist so
  5332. 3:18:34data we make the directory so look at
  5333. 3:18:36this in this folder there's no uh data
  5334. 3:18:39folder if I run this we now have a data
  5335. 3:18:42folder pretty cool right pretty cool and
  5336. 3:18:45now we can save it and this is all
  5337. 3:18:47possible because of pandas. It makes it
  5338. 3:18:49super easy similar to how Excel you can
  5339. 3:18:51just like export to CSV. We can take our
  5340. 3:18:54data frame which is the one over here
  5341. 3:18:56and we can say to CSV. So that's a
  5342. 3:18:59method that's available on there and
  5343. 3:19:01then we can provide a path data and then
  5344. 3:19:03we say we call it Paris uh weather CSV
  5345. 3:19:07and then we do that. And now you can see
  5346. 3:19:09a confirmation over here because we have
  5347. 3:19:10a print statement which says we have the
  5348. 3:19:12data saved to Paris weather.csv. So now
  5349. 3:19:15let's see let's close out of this. Let's
  5350. 3:19:17actually have a look inside the data
  5351. 3:19:19folder. Wow, look we have a weather.csv.
  5352. 3:19:22We can even reveal that in the finder
  5353. 3:19:24and you can actually see that now we
  5354. 3:19:25have a file over here that we can share
  5355. 3:19:28and that we can work with even in other
  5356. 3:19:30tools. So this is pretty cool, right? So
  5357. 3:19:33here you can see the complete example.
  5358. 3:19:35And like I said, we're making big steps
  5359. 3:19:38right here. We're going from isolated
  5360. 3:19:40building blocks to literally bringing
  5361. 3:19:41everything together. We connected to a
  5362. 3:19:43real API. We worked with dates and
  5363. 3:19:46times. We processed data with pandas. We
  5364. 3:19:48created the visualizations. We handled
  5365. 3:19:50files and folders. And we saved the
  5366. 3:19:52results. These are literally the skills
  5367. 3:19:54of like a junior data analyst. These are
  5368. 3:19:56the skills that you need to understand.
  5369. 3:19:58And now, as an exercise, here's what I
  5370. 3:20:00want you to do. I want you to try and
  5371. 3:20:02modify the code to get the weather for
  5372. 3:20:04your city. So you can come in here and
  5373. 3:20:06find uh where wherever you live and then
  5374. 3:20:09update everything in here from like the
  5375. 3:20:11latitude, longitude to also uh the
  5376. 3:20:14titles over here so it doesn't say
  5377. 3:20:16weather in Paris and then you can even
  5378. 3:20:19uh change the file name over here. So go
  5379. 3:20:22through the entire thing, play with it
  5380. 3:20:23and see if you can create the weather
  5381. 3:20:24chart and the export for the weather in
  5382. 3:20:27your city. Okay, and now it's time to
  5383. 3:20:29dive into the next section which is
  5384. 3:20:30called practical python. So here, beyond
  5385. 3:20:34just showing you isolated code snippets,
  5386. 3:20:36I'm going to actually teach you what
  5387. 3:20:38it's like to work with Python in the
  5388. 3:20:41real world. So we're going to build real
  5389. 3:20:43programs with a proper structure. And
  5390. 3:20:46you got a sneak peek of that in the
  5391. 3:20:48previous section already. But here, what
  5392. 3:20:50we're going to do is we're we're going
  5393. 3:20:51to set up a project. We're going to
  5394. 3:20:53understand Python paths and how they
  5395. 3:20:55work with each other. We're going to
  5396. 3:20:56work with even more data, and we're
  5397. 3:20:58going to organize our code. So, we're
  5398. 3:21:00going to split our code into reusable
  5399. 3:21:01functions and also across files. This is
  5400. 3:21:05really, really important and a lot of
  5401. 3:21:07beginner courses and tutorials skip that
  5402. 3:21:09and it took me years to like fully
  5403. 3:21:11figure this out and to really be
  5404. 3:21:13confident with this. So, let's first get
  5405. 3:21:16into the project structure. Super
  5406. 3:21:19important talking about organizing your
  5407. 3:21:21workspace. So, currently we are in this
  5408. 3:21:24folder, right? We already created some
  5409. 3:21:26some folders in here. We have the
  5410. 3:21:27hello.py, PI we have the weather chart
  5411. 3:21:29which I'm going to get rid of right now
  5412. 3:21:31and we have the get data that we created
  5413. 3:21:33but now let's actually start to create
  5414. 3:21:36some structure in here and see how all
  5415. 3:21:37of that works together. So what I want
  5416. 3:21:39you to do is I want you to create a uh a
  5417. 3:21:42new folder and we're going to call this
  5418. 3:21:44sales analysis. So let's come in here
  5419. 3:21:48and let's see we are going to create
  5420. 3:21:50sorry not a new file we do a new folder
  5421. 3:21:52and we do sales analysis. So this this
  5422. 3:21:55can be another like project inside this.
  5423. 3:21:57So sales analysis in here. Okay. And
  5424. 3:22:00then what you want to do is inside the
  5425. 3:22:03sales analysis create these subfolders.
  5426. 3:22:05So you do data and you do output. So in
  5427. 3:22:08here we do new folder. We have data and
  5428. 3:22:10we do another folder. We do output.
  5429. 3:22:13Okay. All right. So it should should
  5430. 3:22:15look like this. Now what we're going to
  5431. 3:22:18do is we're going to create a data file
  5432. 3:22:20that we are going to work with. So you
  5433. 3:22:22can simply copy paste this this uh over
  5434. 3:22:25here and then inside the data folder
  5435. 3:22:28we're going to over here we're going to
  5436. 3:22:30do new file and I'm going to do sales
  5437. 3:22:32and I'm going to specify the uh uh the
  5438. 3:22:35file extension CSV. So this will signal
  5439. 3:22:38look this is a CSV file and then I'm
  5440. 3:22:40going to paste this in here and I am
  5441. 3:22:42going to save it. Now you can see over
  5442. 3:22:44here that do you want to install uh
  5443. 3:22:46rainbow CSV? This is actually something
  5444. 3:22:48that I recommend. So let's see over
  5445. 3:22:50here. Yes, I trust this. I'm going to
  5446. 3:22:52install rainbow CSV. If you if you don't
  5447. 3:22:55get the popup, you can also just go to
  5448. 3:22:57the extensions over here, right?
  5449. 3:22:59Remember these are the building blocks
  5450. 3:23:01and then you search for rainbow CSV and
  5451. 3:23:05then you click on it and then you click
  5452. 3:23:06install because look what this will now
  5453. 3:23:08do is it will show us uh different
  5454. 3:23:10coloring. So you can see the columns
  5455. 3:23:12easily coming back. So now we have a CSV
  5456. 3:23:15file in here and then let's see over
  5457. 3:23:18here. Now let's understand paths and how
  5458. 3:23:22they work. So when we are for example in
  5459. 3:23:24the sales analysis folder. So let's say
  5460. 3:23:26this is a project you're you're working
  5461. 3:23:28on in here and you want to reference the
  5462. 3:23:31sales the sales.csv the file that we
  5463. 3:23:33just created. We actually need to refer
  5464. 3:23:35to it to say look we need data. We need
  5465. 3:23:38to go into data folder and then we want
  5466. 3:23:39sales. CSV. So it's all like with
  5467. 3:23:43respect to where things are live on your
  5468. 3:23:45file system. So let's give an example of
  5469. 3:23:48that to make that more clear. In the
  5470. 3:23:49sales uh analysis folder, we're going to
  5471. 3:23:51create a file analyzer.py and we're
  5472. 3:23:54going to copy paste and we're going to
  5473. 3:23:55plug this in. So this is a way for us to
  5474. 3:23:58get a feel for it. So in sales analysis,
  5475. 3:24:00we do analyzer.py
  5476. 3:24:03and we plug this in. So now when we are
  5477. 3:24:06in this file, when we for example want
  5478. 3:24:08to access the data or the outputs, we
  5479. 3:24:10need to work with specific parts. So
  5480. 3:24:12let's give an example of what that looks
  5481. 3:24:13like. Let's say we import OS which is
  5482. 3:24:15the library we can use to get
  5483. 3:24:17information about our operating system
  5484. 3:24:19and we then print the current working
  5485. 3:24:22directory which is the OS to get current
  5486. 3:24:24working directory and we print that we
  5487. 3:24:26can see all the way over here that we
  5488. 3:24:28are currently in the sales analysis
  5489. 3:24:30folder and now we can check let me
  5490. 3:24:32actually zoom out a little bit now we
  5491. 3:24:34can check whether Python can access our
  5492. 3:24:36uh sales.csv CSV file. So we do an if
  5493. 3:24:38statement and we say look if the OS path
  5494. 3:24:41the path over here exists we print we
  5495. 3:24:44found the data. Else we say we did not
  5496. 3:24:46find the data. So let's run this and we
  5497. 3:24:48can see look it found the data and that
  5498. 3:24:50is because from analyzer.py if we want
  5499. 3:24:53to get to here we need to say first go
  5500. 3:24:55into data then access sales.csv. If I
  5501. 3:24:59get rid of this so for example of the
  5502. 3:25:00data just just give me sales.csv CSV and
  5503. 3:25:03I run this, you'll find that we'll run
  5504. 3:25:06into an error. Cannot find it because
  5505. 3:25:08this file is looking then into the sales
  5506. 3:25:10analysis folder for a file called
  5507. 3:25:12sales.csv and that doesn't exist. So
  5508. 3:25:15that is how you can start to organize
  5509. 3:25:17your projects and create structure. And
  5510. 3:25:19a best practice here is keep data
  5511. 3:25:21separate. So don't mix code and data
  5512. 3:25:23files. Create separate folders like data
  5513. 3:25:25and outputs. Use clear names. Data for
  5514. 3:25:28input files, outputs for results,
  5515. 3:25:30figures for images. Use simple
  5516. 3:25:32structures. Keep your main script at
  5517. 3:25:34like the top level and go deeper. Also,
  5518. 3:25:36don't go to really like other folders
  5519. 3:25:38somewhere else on your computer. Keep it
  5520. 3:25:41focused and isolated. And then always uh
  5521. 3:25:43keep on testing as you go. Right? So,
  5522. 3:25:45both using the interactive session which
  5523. 3:25:47is great for running line by line, but
  5524. 3:25:50then also make sure that when you run
  5525. 3:25:52the entire file all at once, you can
  5526. 3:25:54also access it. And this is one of the
  5527. 3:25:56things where in the beginning uh
  5528. 3:25:58remember I reconfigured when we were
  5529. 3:26:00installing uh Visual Studio Code we
  5530. 3:26:02configured the Python execution. So if
  5531. 3:26:04you run into any errors here you need to
  5532. 3:26:07come back to the settings. So one more
  5533. 3:26:09time for Visual Studio Code settings.
  5534. 3:26:12This is the one where you need to do
  5535. 3:26:13that otherwise it will look from the
  5536. 3:26:15project root and your uh folders and
  5537. 3:26:18your paths will become much more complex
  5538. 3:26:20and is a lot harder to keep track of
  5539. 3:26:22everything. So this is what I recommend.
  5540. 3:26:24keep on testing. So both of the methods
  5541. 3:26:26work seamlessly. All right. So that was
  5542. 3:26:28an introduction to how you can structure
  5543. 3:26:30the projects and how you can work with
  5544. 3:26:32Python pass. In the handbook over here
  5545. 3:26:34in Python pass there is a whole section
  5546. 3:26:36with a lot more instructions and working
  5547. 3:26:39with Python pass can be a little bit
  5548. 3:26:40tricky but it's also too much for now to
  5549. 3:26:42really dive into. The only thing that
  5550. 3:26:44you should really need to understand
  5551. 3:26:46here like the mental model whenever you
  5552. 3:26:48want to for example access data you want
  5553. 3:26:50to write to or read files is you should
  5554. 3:26:52really think about look where am I what
  5555. 3:26:54folder is my python script in so for
  5556. 3:26:56example here in the analyzer.py I am in
  5557. 3:26:59here then if I want to access the data
  5558. 3:27:02what you can then do is you could simply
  5559. 3:27:04follow the structure by saying you go in
  5560. 3:27:06the folder and then you do a you do a
  5561. 3:27:08forward slash and then you access the
  5562. 3:27:10file if you want to go one level up. So
  5563. 3:27:13you are for example in the sales
  5564. 3:27:15analysis and you want to access the
  5565. 3:27:17Paris weather. What you then do? So let
  5566. 3:27:19me actually show you that. So then what
  5567. 3:27:21you use is you use two dots. So this
  5568. 3:27:24means and then a slash. This means we go
  5569. 3:27:27one level up. So let me zoom in a little
  5570. 3:27:30bit. So we are in analyzer.py which is
  5571. 3:27:32in the sales analysis folder. Let's say
  5572. 3:27:34I want to go to this data folder. Now I
  5573. 3:27:36go one level up. I go into data and now
  5574. 3:27:39the sales CSV is not there but the Paris
  5575. 3:27:42weather CSV is there. So now if I check
  5576. 3:27:45this, this should also work. Look, now
  5577. 3:27:48we can access data that's outside of the
  5578. 3:27:51folder. So if we go in, we simply use
  5579. 3:27:54the folder names or the file names and
  5580. 3:27:57we use forward slashes. If we want to go
  5581. 3:27:59up, uh, we do it with the two dots. And
  5582. 3:28:01this this can stack. You can change
  5583. 3:28:03this. So you can also like if you have a
  5584. 3:28:05really big project, you can also
  5585. 3:28:06literally go three folder levels up. Uh
  5586. 3:28:10it works exactly the same way. So this
  5587. 3:28:12is just also one of those things where
  5588. 3:28:14you just need to get started. You need
  5589. 3:28:15to just start working on stuff and then
  5590. 3:28:17you run into issues where you're in a
  5591. 3:28:19file like I cannot access this. I'm
  5592. 3:28:22getting errors. Python is throwing me
  5593. 3:28:23errors. Then this Python pause section
  5594. 3:28:25will give you like simple rules to
  5595. 3:28:27follow, how you can check, how you can
  5596. 3:28:29debug, how you can find your files and
  5597. 3:28:31give you a few like differences as to
  5598. 3:28:33how you should go about it. So make sure
  5599. 3:28:35to bookmark this uh handbook and also
  5600. 3:28:37use chatgpt. Then we get into working
  5601. 3:28:40with files. So yeah, I want to spend
  5602. 3:28:42some time here because this is also
  5603. 3:28:44super important for when you are uh
  5604. 3:28:46going to work on AI projects because AI
  5605. 3:28:49is always about processing some incoming
  5606. 3:28:52data and we want to do something with
  5607. 3:28:53that to usually automate something and
  5608. 3:28:56there data comes in a lot of shape way
  5609. 3:28:58shapes and and forms. So we can have for
  5610. 3:29:00example CSV files, JSON files, XML
  5611. 3:29:02files, te text files or even paret files
  5612. 3:29:05which are efficient ways for for storing
  5613. 3:29:07lots of information. And the good news
  5614. 3:29:10is Python has like excellent libraries
  5615. 3:29:12for all of these. Um, that was so nice
  5616. 3:29:14also when I started out as a data
  5617. 3:29:16scientist. Whatever like kind of like
  5618. 3:29:18data set people would throw at me
  5619. 3:29:20whether it was Excel, CSV, a parket or
  5620. 3:29:23like a SQL database like within a couple
  5621. 3:29:26of minutes you could tinker with a
  5622. 3:29:27library and you could make a connection.
  5623. 3:29:30So now let's start to play a little bit
  5624. 3:29:32with our sales data. So again make sure
  5625. 3:29:34you have pondas installed. You should
  5626. 3:29:35already have this uh already. Now we are
  5627. 3:29:38going to adjust our analyzer.py and
  5628. 3:29:40we're going to copy and paste this chunk
  5629. 3:29:43in there again just to get a feel for
  5630. 3:29:46what we can do with this not to fully
  5631. 3:29:47understand everything line by line. So
  5632. 3:29:50if we come in here and let's see I'm
  5633. 3:29:52going to close this out. We can first of
  5634. 3:29:54all read the CSV file. So this is the
  5635. 3:29:57CSV file that we could just that we just
  5636. 3:29:59created right. So we now have it in a
  5637. 3:30:01pandas data frame over here. Now we can
  5638. 3:30:04also look at the shape which is like how
  5639. 3:30:06many rows and columns do we have? So we
  5640. 3:30:08can print that. Those are common
  5641. 3:30:09operations and we can also add more
  5642. 3:30:12columns to it. So we can calculate the
  5643. 3:30:14total. So let's have a look at this. So
  5644. 3:30:16you can see we have quantity and price.
  5645. 3:30:18And now if we run this. So we do we take
  5646. 3:30:20the data frame and we take the quantity
  5647. 3:30:24column over here which we can do through
  5648. 3:30:26indexing similar how we would do with a
  5649. 3:30:28dictionary. That's how pandas works. We
  5650. 3:30:31take the quantity and we take the price
  5651. 3:30:33and we multiply that and we store that
  5652. 3:30:35into a new column. Now when we look at
  5653. 3:30:38the data set or the data frame, you can
  5654. 3:30:40see that we have a total value in here
  5655. 3:30:43that we can also uh check. So this is
  5656. 3:30:45how we can now start to use pandas as
  5657. 3:30:48pretty much as Excel. We can now also
  5658. 3:30:50create an output directory if it's not
  5659. 3:30:52already there yet. So we already created
  5660. 3:30:54that, right? So let me actually get rid
  5661. 3:30:56of this. move to trash and then we
  5662. 3:30:59create the directory. So now we have
  5663. 3:31:01that one more time and now we can save
  5664. 3:31:03it in multiple ways. So you can see
  5665. 3:31:05before I show you how you can export it
  5666. 3:31:07to a CSV file, right? Well, we can also
  5667. 3:31:09output it to JSON. There we go. We now
  5668. 3:31:11have a JSON file. Very convenient. We
  5669. 3:31:13can output it to Excel. So now you will
  5670. 3:31:16get an error where it says look we need
  5671. 3:31:19let's see we need open py excel. So let
  5672. 3:31:22me actually show you that full error.
  5673. 3:31:24This is now this is also very common
  5674. 3:31:26when you're working with Python and it
  5675. 3:31:27says something like module not found and
  5676. 3:31:29in this case we need open pi excel in
  5677. 3:31:31the background as well. So what we can
  5678. 3:31:33do is we can open up our terminal again
  5679. 3:31:35and you know how to do this right now.
  5680. 3:31:36Whenever you need something in python
  5681. 3:31:38you just do pip install open pi excel
  5682. 3:31:40and now it will get that into our
  5683. 3:31:43virtual environment. We can close out of
  5684. 3:31:45this and now let me clear this up. I
  5685. 3:31:48think we should already be good to go.
  5686. 3:31:50So now do to excel. I don't think even
  5687. 3:31:52we have to run uh all of the other parts
  5688. 3:31:54again. Look, now we have an Excel file.
  5689. 3:31:56Like literally like this is an Excel
  5690. 3:31:57file that we can just like open in
  5691. 3:32:00Microsoft Excel. So you can see there we
  5692. 3:32:03go. We created an Excel file. Now let's
  5693. 3:32:05see. We can also do a CSV file. And now
  5694. 3:32:08you have the totals in here. And you can
  5695. 3:32:11see all of the output parts created over
  5696. 3:32:14here. And it prints it. So this is now
  5697. 3:32:16also a little automator script that we
  5698. 3:32:18can have. So let's see if I delete this
  5699. 3:32:20file over here and completely get rid of
  5700. 3:32:22the output. Instead of going through it
  5701. 3:32:26uh line by line with the interactive
  5702. 3:32:28session, I can also just hit the play
  5703. 3:32:30button or on my keyboard do uh command
  5704. 3:32:33enter and now it will run in the
  5705. 3:32:35terminal. You can see boom all
  5706. 3:32:37everything it created the folder, it
  5707. 3:32:38created the JSON file, excel file and
  5708. 3:32:40the CSV file. Now this is going to set
  5709. 3:32:42the stage for pretty powerful
  5710. 3:32:44automations, right? You can also already
  5711. 3:32:46start to think about some data analysis,
  5712. 3:32:48some data that you get via an API and
  5713. 3:32:50just every time that you want to run
  5714. 3:32:51this just like run this script or later
  5715. 3:32:53you can also schedule this so it becomes
  5716. 3:32:55fully automated and now you have all of
  5717. 3:32:56these files here. So let's say you want
  5718. 3:32:58to send like weekly sales reports to uh
  5719. 3:33:00to your sales manager or something like
  5720. 3:33:02that. You can create a simple script do
  5721. 3:33:04the calculations and send it to it send
  5722. 3:33:06it to him in an Excel file because
  5723. 3:33:08that's what he understands is he's not a
  5724. 3:33:10programmer. all ways that you can work
  5725. 3:33:12with the Python programming language and
  5726. 3:33:14similar to exporting the files with
  5727. 3:33:16pandas we can also like read in these
  5728. 3:33:18files again so within pandas if you want
  5729. 3:33:20to read in a specific CSV file so let's
  5730. 3:33:22say you have a data folder and in there
  5731. 3:33:24is a file called file CSV you can do
  5732. 3:33:26read CSV or we can read a JSON or we can
  5733. 3:33:30read excel and all of these functions
  5734. 3:33:32also come with their own set of
  5735. 3:33:34parameters where you can tweak it you
  5736. 3:33:36can there are literally like 15 to 20
  5737. 3:33:38types of arguments that you can plug
  5738. 3:33:40plug in there to skip rows to convert
  5739. 3:33:42certain data formats to have specific en
  5740. 3:33:46encoding files all possible really the
  5741. 3:33:48sky is the limit there. So just so you
  5742. 3:33:50know you can export you can take data
  5743. 3:33:52you can read all kinds of formats you
  5744. 3:33:54can manipulate it and then you can also
  5745. 3:33:56export it again in all types of formats
  5746. 3:33:59to do whatever really you want. If you
  5747. 3:34:01want to learn more about this like
  5748. 3:34:03pandas uh just a documentation great
  5749. 3:34:05resource the JSON module reading files
  5750. 3:34:08and also I keep saying it chat GPT plug
  5751. 3:34:10it in. What can I do with pandas? Give
  5752. 3:34:12me an example. I want to read XML data.
  5753. 3:34:15How do I do this in Python? I want to
  5754. 3:34:18work with an Excel spreadsheet in
  5755. 3:34:19Python. How do I do this? All possible.
  5756. 3:34:22Okay, let's get to the last component of
  5757. 3:34:25the practical Python session is
  5758. 3:34:27organizing code. This is a big one. It
  5759. 3:34:29took me it took me way too long to like
  5760. 3:34:32to properly figure out how to do this
  5761. 3:34:34because it's not that hard but no one
  5762. 3:34:36like just showed me how to do this uh
  5763. 3:34:38professionally really because when you
  5764. 3:34:41are starting out as a beginner when you
  5765. 3:34:43are working with Python files it's
  5766. 3:34:45almost always that you have an idea I
  5767. 3:34:47want to do something and you start in
  5768. 3:34:49one single file right so here we have
  5769. 3:34:51the analyzer.py Pi this is we work on
  5770. 3:34:53something and oh here this is something
  5771. 3:34:54completely else we we work with data but
  5772. 3:34:57in the real world in real projects you
  5773. 3:34:59want to make your code modular. So you
  5774. 3:35:02want to have tiny files ideally that
  5775. 3:35:04have some specific logic and then
  5776. 3:35:06whenever you want to use that logic you
  5777. 3:35:08import it into another file. You can do
  5778. 3:35:11that and I'm going to show you how you
  5779. 3:35:12can do that right now. It's similar to
  5780. 3:35:14the imports actually that we use for the
  5781. 3:35:15packages. So what does that look like
  5782. 3:35:18and what are the benefits? Well, your
  5783. 3:35:19code becomes reusable. becomes way more
  5784. 3:35:21readable because instead of having
  5785. 3:35:23thousand lines in one big file which is
  5786. 3:35:25called maincript.pby where everything is
  5787. 3:35:29you can now have calculations I don't
  5788. 3:35:31know user info export data visualize
  5789. 3:35:34data you have all of these files within
  5790. 3:35:37your project that now have a descriptive
  5791. 3:35:39name that are short that you can easily
  5792. 3:35:41read and understand. So let's create a
  5793. 3:35:45uh let's start by creating a helper
  5794. 3:35:46function in our sales analysis folder.
  5795. 3:35:49We are going to create a helpers.py
  5796. 3:35:51folder and we're going to plug in these
  5797. 3:35:54functions. So let's actually do that.
  5798. 3:35:55Come over here. So sales analysis new
  5799. 3:35:58file. We do helpers.py
  5800. 3:36:01and we plug this in. We can get rid of
  5801. 3:36:03this. So now you can by now you should
  5802. 3:36:06already be familiar with the concept of
  5803. 3:36:08functions. And you should be able to
  5804. 3:36:10read this and understand what it's
  5805. 3:36:12doing, right? So calculated total it's a
  5806. 3:36:15function. It takes the quantity and the
  5807. 3:36:17price as input parameters and then it
  5808. 3:36:20returns the quantity times the price. So
  5809. 3:36:22it calculates the total. Here you can
  5810. 3:36:24see we have a multi-line dock string
  5811. 3:36:26that we have in here or it's it is in
  5812. 3:36:28triple quotes but you could also do
  5813. 3:36:30multiple lines in here to give a
  5814. 3:36:32description of what this function does.
  5815. 3:36:34And then we're going to format the
  5816. 3:36:36currency. So, we're going to take any
  5817. 3:36:38number which is the input parameter, the
  5818. 3:36:41amount, and we're going to format it in
  5819. 3:36:43a string where we say, look, we're going
  5820. 3:36:44to put a dollar sign before it. It's an
  5821. 3:36:46F string, so we can put in the amount.
  5822. 3:36:49And then this is Python's way of saying
  5823. 3:36:51we just want two decimals. Also syntax,
  5824. 3:36:53something you just need to see. We can
  5825. 3:36:55also change this to one, to five, or to
  5826. 3:36:58two. So now we've created helper
  5827. 3:37:01functions. So let's come back to what we
  5828. 3:37:04can do with this. So now we can actually
  5829. 3:37:06use these functions. So now if we come
  5830. 3:37:08over to our analyzer.py and let's see
  5831. 3:37:11we're going to I'm going to copy paste
  5832. 3:37:13this. So we can just do do it line by
  5833. 3:37:15line here together. Analyzer get rid of
  5834. 3:37:18everything that's in here and we're
  5835. 3:37:19going to make this a lot simpler and
  5836. 3:37:20we're going to paste this in. Look what
  5837. 3:37:22we're doing right now. So now we import
  5838. 3:37:25pandas spd. This is we know that we can
  5839. 3:37:28do this right because we installed
  5840. 3:37:29pandas in our virtual environment. So
  5841. 3:37:31now pandas so now python knows I can
  5842. 3:37:34import this. But look, here's the cool
  5843. 3:37:36thing. We have now created our own
  5844. 3:37:39module called helpers. Remember modules
  5845. 3:37:42is a single single file and from within
  5846. 3:37:44there we can import functions. So we can
  5847. 3:37:47say from helpers we import calculate
  5848. 3:37:50total and format currency which are the
  5849. 3:37:52exact names of the functions. So they
  5850. 3:37:54need to be exact otherwise you get
  5851. 3:37:56import errors. So now if I run this you
  5852. 3:38:00see we don't have any uh import errors
  5853. 3:38:03right now. We can import import these
  5854. 3:38:05functions and it it needs to be exact.
  5855. 3:38:08And now we can go ahead and we can read
  5856. 3:38:10the CSV data. And now we can calculate
  5857. 3:38:12the total for each row by creating a for
  5858. 3:38:16loop over the data frame. Again, don't
  5859. 3:38:18worry about the syntax what we're doing
  5860. 3:38:19over here. But we're going to create the
  5861. 3:38:21totals. And now the totals you can see
  5862. 3:38:24is a list of numbers in here. And that's
  5863. 3:38:27now very easy because we have our
  5864. 3:38:28helpers functions. And what this
  5865. 3:38:30essentially does is say look we have go
  5866. 3:38:32over all the rows in a data frame and
  5867. 3:38:34then take the quantity take the price
  5868. 3:38:36and and put those into the calculate
  5869. 3:38:38total function. So that's how we can
  5870. 3:38:41work back and forth between different
  5871. 3:38:43files. And in a similar format uh we can
  5872. 3:38:46also format the currency in here. So if
  5873. 3:38:48we then do everything now all of a
  5874. 3:38:51sudden we have a sales report. You can
  5875. 3:38:53see we have all all of the uh we have
  5876. 3:38:56all of the totals for all of the
  5877. 3:38:57categories. It's formatted using the
  5878. 3:39:00dollar sign and it has two decimals over
  5879. 3:39:02here. So now instead of having
  5880. 3:39:04everything in one file, we make things
  5881. 3:39:07modular. And now your helpers functions
  5882. 3:39:10could you could have like plenty of
  5883. 3:39:11functions in there and they could be
  5884. 3:39:13helpful not only in the analyzer.py
  5885. 3:39:15file, but maybe you have another script,
  5886. 3:39:17another analysis where you need to do
  5887. 3:39:19the same uh the same operations. All
  5888. 3:39:21right, let's cover what we've learned in
  5889. 3:39:23this practical Python section because
  5890. 3:39:26we're making big steps right now. This
  5891. 3:39:28is how you use Python in the real world.
  5892. 3:39:29You now know how to organize and
  5893. 3:39:31structure your project. Uh you know how
  5894. 3:39:34Python finds files, right? How you can
  5895. 3:39:36do that whether it's data files or
  5896. 3:39:38whether it's Python files. You have
  5897. 3:39:41created code that reads real data and
  5898. 3:39:43saves real results. And you also created
  5899. 3:39:46reusable functions in separate files.
  5900. 3:39:48This is how real Python works. All
  5901. 3:39:50right. And with that we have come to a
  5902. 3:39:52section on error handling. Also
  5903. 3:39:55something really important because as a
  5904. 3:39:57programmer you are going to make errors
  5905. 3:40:00and even if you don't make errors it can
  5906. 3:40:02also just happen that your program your
  5907. 3:40:04code might be totally fine but just
  5908. 3:40:06because of the data that's flowing
  5909. 3:40:08through things or data that's either not
  5910. 3:40:10available or available within an API it
  5911. 3:40:13your program will respond differently
  5912. 3:40:15and then it will crash. So there are
  5913. 3:40:17ways to go about this and to handle
  5914. 3:40:19this. So when it comes to error
  5915. 3:40:21handling, there are different types of
  5916. 3:40:24errors that you make as a as a
  5917. 3:40:26programmer and also errors that are
  5918. 3:40:27beyond your control. So you as the
  5919. 3:40:30programmer can for example have typos
  5920. 3:40:32and syntax errors, right? Forgetting a
  5921. 3:40:33comma or using a a dot instead of a
  5922. 3:40:36comma or forgetting a cola colon. You
  5923. 3:40:38can also have logic errors. So for
  5924. 3:40:39example, dividing by zero uh that really
  5925. 3:40:42only shows up when your code runs or
  5926. 3:40:44using a variable before it's defined or
  5927. 3:40:47using the making a mistake with local or
  5928. 3:40:49global variables or calling methods that
  5929. 3:40:51don't exist. That's all stuff that you
  5930. 3:40:53as a programmer can do. But beyond that
  5931. 3:40:56when for example you are interacting
  5932. 3:40:58with a system and a user for example
  5933. 3:41:00inputs ABC when it needs to be a number.
  5934. 3:41:03So for example like what's your age and
  5935. 3:41:05that's ABC it cannot do a comparison on
  5936. 3:41:07that or a file gets deleted if you after
  5937. 3:41:09your program starts or an API that
  5938. 3:41:11you're using is suddenly offline or
  5939. 3:41:13changed. So you should know you should
  5940. 3:41:16be aware of these types of different
  5941. 3:41:18errors. Now here are then some examples
  5942. 3:41:20of what can happen in the real world. So
  5943. 3:41:22a syntax error right? So for this I'm
  5944. 3:41:24going to come back to my hello.py. Let's
  5945. 3:41:27see hello.py to give some examples. So
  5946. 3:41:30here you can see a syntax error. Look,
  5947. 3:41:32we we have an if statement and we are
  5948. 3:41:34missing the colon. So right now Python
  5949. 3:41:38will say look we expected the colon in
  5950. 3:41:41here. So we can put that in here. But
  5951. 3:41:43now also it says look the x is not
  5952. 3:41:45defined. So that's another error that we
  5953. 3:41:47have in here. So now if we say x equals
  5954. 3:41:492 now we're all good and we have fixed
  5955. 3:41:51the program. In this case you also have
  5956. 3:41:53runtime errors. So look at this. So for
  5957. 3:41:55example this we don't see any error. So
  5958. 3:41:59we have 10 and we divide it by zero.
  5959. 3:42:00This is not something we can do uh also
  5960. 3:42:03not in Python. So now when we run this,
  5961. 3:42:05this is a runtime error because like you
  5962. 3:42:07will not see it until you run it. That's
  5963. 3:42:09why it's called runtime division by
  5964. 3:42:10zero. So that's another error. You can
  5965. 3:42:12also for example have a variable that
  5966. 3:42:15doesn't exist or a type error. So let's
  5967. 3:42:17look at this. So over here we have print
  5968. 3:42:19score. Python is like dude I don't know
  5969. 3:42:21what score is. I can help you with that.
  5970. 3:42:24And then you can also for example have a
  5971. 3:42:25type error. So when you take uh a string
  5972. 3:42:28and in this case an integer and we try
  5973. 3:42:31to uh subtract or add the two it says it
  5974. 3:42:33can only connect concatenate strings
  5975. 3:42:36with other strings. So, we've seen that
  5976. 3:42:39it's totally fine to do 5 + 5 or in this
  5977. 3:42:43case hello plus I don't know hi like
  5978. 3:42:47this is all totally fine we can do that
  5979. 3:42:49but when we mix data types then all of a
  5980. 3:42:52sudden Python says ho I'm going to stop
  5981. 3:42:55you there this is not how we do things
  5982. 3:42:57so those are all different types of
  5983. 3:42:59errors that you can get into and here is
  5984. 3:43:03another like common list where you can
  5985. 3:43:05go through I won't cover all of these
  5986. 3:43:07right Now, but what I'm going to show
  5987. 3:43:08you is the try and accept blocks in
  5988. 3:43:12Python because this is a very common way
  5989. 3:43:14to make your programs more robust. And
  5990. 3:43:16with try and accept, we can we can say
  5991. 3:43:19to Python, look, go and try this. And if
  5992. 3:43:22it fails, don't worry about it. Just do
  5993. 3:43:25this. Because if we don't use try and
  5994. 3:43:28accept, our program will stop if it hits
  5995. 3:43:30an error. The examples that I just gave
  5996. 3:43:33you, if you, for example, let's do the
  5997. 3:43:35uh the deficient over here. Let's say if
  5998. 3:43:37we now do uh we do print hi there. If I
  5999. 3:43:41run this, you won't see the print
  6000. 3:43:43because it will never get there. And it
  6001. 3:43:45doesn't matter if I do it in the
  6002. 3:43:46interactive window or I do it in the
  6003. 3:43:48terminal, it will just say look, we
  6004. 3:43:50cannot continue here. So the rest of our
  6005. 3:43:53program will also not be executed. So
  6006. 3:43:55let's say you're building a data
  6007. 3:43:57pipeline and you're getting information
  6008. 3:43:59from let's say five systems. You're
  6009. 3:44:01generating the reports. First you you
  6010. 3:44:04look into system one. You perform the
  6011. 3:44:05calculations. Once you create the
  6012. 3:44:06report, they go to system two. That's
  6013. 3:44:08your whole script. If now there's an
  6014. 3:44:10issue with system one and the API there,
  6015. 3:44:13system 3 4 5 6 and everything after that
  6016. 3:44:15will also fail. That's where try and
  6017. 3:44:17accept comes into play. And how it works
  6018. 3:44:20is like this. We do try, then we do a
  6019. 3:44:23colon, then we do an enter, and then we
  6020. 3:44:25get to the new line, and we have the
  6021. 3:44:27indent, similar to an if statement. And
  6022. 3:44:30now you can still see there's a red
  6023. 3:44:32squiggly line in here because it says a
  6024. 3:44:34try statement must have at least one
  6025. 3:44:36except or a finally clause. So um other
  6026. 3:44:40than like an if statement that you can
  6027. 3:44:41also use isolated with a try we need to
  6028. 3:44:45have an except clause in here as well.
  6029. 3:44:48And then we do it like this. So first we
  6030. 3:44:50say look try to divide this by zero.
  6031. 3:44:53This will fail but we will still print
  6032. 3:44:56hide there. And we can also do it like
  6033. 3:44:58this and it will work. So that's a basic
  6034. 3:45:00try and accept structure and that will
  6035. 3:45:02already get you a long way. Now you can
  6036. 3:45:05also capture multiple errors. So
  6037. 3:45:07depending on whether it's a file not
  6038. 3:45:08found error, a value error, a serial
  6039. 3:45:10division error, but in the beginning
  6040. 3:45:12just focus on when you need to have some
  6041. 3:45:15type of error handling, starting with a
  6042. 3:45:16simple try and accept will really get
  6043. 3:45:18you a long way. This is already more
  6044. 3:45:20advanced. We can also add else clauses
  6045. 3:45:22to it and even a finally clause which
  6046. 3:45:24will always run. All right, and that
  6047. 3:45:26brings us to the last section of the
  6048. 3:45:29building program sections, and that is
  6049. 3:45:31classes. And now, this is going to be
  6050. 3:45:33the most advanced topic that we're going
  6051. 3:45:35to cover in this Python course. And at
  6052. 3:45:37this point, it will probably still be a
  6053. 3:45:39little bit tricky. So, don't worry if at
  6054. 3:45:42any point during my explanation of what
  6055. 3:45:44classes are, how to use them, and even
  6056. 3:45:45what inheritance is when you feel like,
  6057. 3:45:48oh, this is going a little bit too fast,
  6058. 3:45:49and I don't fully get it. That's also
  6059. 3:45:51not the full goal right now. is just to
  6060. 3:45:54get exposure to it so that you are
  6061. 3:45:56familiar with the concept you've seen a
  6062. 3:45:58couple of examples so that later down
  6063. 3:45:59the line in your own learning journey
  6064. 3:46:01whenever in another tutorial or another
  6065. 3:46:04course that you're following when people
  6066. 3:46:05mention classes you at least know oh
  6067. 3:46:08yeah this was this thing that Dave was
  6068. 3:46:09talking about that was a little bit
  6069. 3:46:10tricky a little bit more advanced but I
  6070. 3:46:11know conceptually what it is and I can
  6071. 3:46:13also now use something like JBT to help
  6072. 3:46:15me get a better understanding of what it
  6073. 3:46:17is and fill in my knowledge gaps and
  6074. 3:46:19what we're going to do right now is I'm
  6075. 3:46:21going to introduce you to objectoriented
  6076. 3:46:24programming which is really just a way
  6077. 3:46:26to organize code by grouping related
  6078. 3:46:28data and functions together. So one of
  6079. 3:46:30the most important things to understand
  6080. 3:46:32about classes is that everything that
  6081. 3:46:34we've done up until this point you can
  6082. 3:46:37totally do that without classes and you
  6083. 3:46:40can solve almost any programming
  6084. 3:46:42problems without classes but they are
  6085. 3:46:44very useful but most specifically from
  6086. 3:46:48an organization point of view. So you
  6087. 3:46:50can actually create really clean code
  6088. 3:46:53files by structuring classes in a good
  6089. 3:46:57way and putting functions in there. And
  6090. 3:46:58that is what I will show you in this
  6091. 3:47:00section. But also just know that for
  6092. 3:47:02example for the first like 3 to four
  6093. 3:47:04years when I was working with the Python
  6094. 3:47:06programming language, I didn't really
  6095. 3:47:07use classes at all. So if you think
  6096. 3:47:10about organizing your code like as a
  6097. 3:47:12toolbox, if it's without objectoriented
  6098. 3:47:16programming, tools are scattered
  6099. 3:47:17everywhere. So, think of your project as
  6100. 3:47:19like a big toolbox. And here you have a
  6101. 3:47:21hammer, there you have a screwdriver,
  6102. 3:47:23and there you have some some nails. It's
  6103. 3:47:25all in there. You have all the tools.
  6104. 3:47:27And tools really here are functions. And
  6105. 3:47:29whenever you need something, you just
  6106. 3:47:31look into the toolbox. You're like,
  6107. 3:47:32"Okay, let's grab the hammer." And then
  6108. 3:47:34you can start to work with the hammer,
  6109. 3:47:36right? But when you are working uh with
  6110. 3:47:39OOP, object-oriented programming, tools
  6111. 3:47:42are organized in labeled compartments.
  6112. 3:47:44So you have the toolbox, but within the
  6113. 3:47:46toolbox you have specific sections. So
  6114. 3:47:49you know that when you need the hammer
  6115. 3:47:52that is over there. So you don't have to
  6116. 3:47:54look, you don't have to grab in there.
  6117. 3:47:55You can just grab the hammer. That's
  6118. 3:47:57probably the best reference or mental
  6119. 3:47:59model that I can give you about using
  6120. 3:48:02classes. Can you still like grab the
  6121. 3:48:04hammer and and jag in the nail without
  6122. 3:48:06without the the organization? Yes. But
  6123. 3:48:09it's easier if you need to grab it more
  6124. 3:48:11often. Okay. So what is a gloss? First
  6125. 3:48:13of all, a class is a blueprint for what
  6126. 3:48:15we call creating objects in Python.
  6127. 3:48:17Objects is just a place where we can
  6128. 3:48:20store all kinds of information under and
  6129. 3:48:22it defines attributes. So what kind of
  6130. 3:48:24data we store in there and methods which
  6131. 3:48:27are functions. So what the class can do.
  6132. 3:48:30Now when you're learning classes right
  6133. 3:48:32now, one of the most tricky things again
  6134. 3:48:34is syntax and methodology. You have
  6135. 3:48:38these things like attributes which is
  6136. 3:48:40data, methods which are the functions.
  6137. 3:48:41And then if I go over here, here you
  6138. 3:48:43have the class definition. And similar
  6139. 3:48:46to how I introduced you to functions,
  6140. 3:48:48right, where we need function name,
  6141. 3:48:50parenthesis, arguments, colon, classes
  6142. 3:48:53also have a peculiar way of like a
  6143. 3:48:56Python specific way of doing things. And
  6144. 3:48:58it's just one of those things. Is it
  6145. 3:49:00logic? I don't know. This is just how
  6146. 3:49:02they came up with it. There are some
  6147. 3:49:04things to it where it's like it's a
  6148. 3:49:05little bit weird, but once you get used
  6149. 3:49:07to it, that's just the way you do it. So
  6150. 3:49:09you'll see things like these underscore
  6151. 3:49:11inits. You'll see this notion of self.
  6152. 3:49:13These are all things that I will explain
  6153. 3:49:15to you and you just need to be aware of
  6154. 3:49:17I need to remember this. This is the
  6155. 3:49:19syntax. So why use classes? So classes
  6156. 3:49:22can help you write more understandable
  6157. 3:49:24programs specifically as they grow as
  6158. 3:49:27they grow. So here's the typical
  6159. 3:49:29progression as a Python developer. This
  6160. 3:49:31is literally what I I went through and I
  6161. 3:49:33want to I want to shortcut this for you.
  6162. 3:49:35So we all start with single files. So
  6163. 3:49:38that's what we've been working on,
  6164. 3:49:39right? So I want to do something. I want
  6165. 3:49:41to get some data. So okay, this is what
  6166. 3:49:43I do. And then at the end I have my
  6167. 3:49:45report and I export my CSV one file.
  6168. 3:49:48That's where everyone starts because
  6169. 3:49:49it's the easiest. And then you get into
  6170. 3:49:51functions. This is where you are right
  6171. 3:49:53now. So remember we created the helper
  6172. 3:49:55functions, right? So now instead of
  6173. 3:49:58doing these, so so actually this example
  6174. 3:50:00was already Oh, sorry this what the
  6175. 3:50:02helper function and the analyzer. So now
  6176. 3:50:05instead of having everything in one
  6177. 3:50:06file, you can see this is now already a
  6178. 3:50:08little bit shorter because this contains
  6179. 3:50:11the uh functions that we can import. So
  6180. 3:50:14that's level number two. And we have
  6181. 3:50:16level level number three. That is where
  6182. 3:50:18you get organized with using multiple
  6183. 3:50:20files. So what I just showed you and
  6184. 3:50:23then in classes level four, that's where
  6185. 3:50:25we'll get to right now where we're going
  6186. 3:50:26to wrap certain functions even we're
  6187. 3:50:30going to nest that inside classes one
  6188. 3:50:32level deeper. Now, in the context of AI
  6189. 3:50:35that you want to probably be working
  6190. 3:50:37towards, you can build really clean
  6191. 3:50:39interfaces, manage complex data
  6192. 3:50:41pipelines, and create your reusable
  6193. 3:50:43components and organize stateful
  6194. 3:50:45operations all using classes. So, let's
  6195. 3:50:48dive into building your first class.
  6196. 3:50:51Let's actually come over here. We're
  6197. 3:50:52going to hello.py. And now we're going
  6198. 3:50:54to use our hello.py to create a class.
  6199. 3:50:56So, to create a class, the syntax is
  6200. 3:50:58first we type out clause. So, with the
  6201. 3:51:00function, it's defaf. Now, it's clause.
  6202. 3:51:03Let's say we want to create a class for
  6203. 3:51:05a dog. So let's say we're creating a
  6204. 3:51:07game and in the game we have a dog and a
  6205. 3:51:09dog can do stuff and it has some
  6206. 3:51:10attributes. So we do that and then we do
  6207. 3:51:14a colon over here and then we get to the
  6208. 3:51:16next line. This is the starting point
  6209. 3:51:18and then we need to add an initializer.
  6210. 3:51:21And this is just one of those things.
  6211. 3:51:22It's a it's a Python function and in a
  6212. 3:51:24class we call it a method but everything
  6213. 3:51:26is exactly the same. This is just one of
  6214. 3:51:27those things where whenever I explain it
  6215. 3:51:29to new students, it's like look, you
  6216. 3:51:31just need to see it a couple of times.
  6217. 3:51:33This is just how we do things in Python.
  6218. 3:51:34Does it look a little bit weird? Yes, it
  6219. 3:51:36does. But just follow along with me. So,
  6220. 3:51:38if I take just this snippet, let me show
  6221. 3:51:41you what what this looks like. So, we go
  6222. 3:51:43inside the class and then we have the
  6223. 3:51:45function the init and then we always
  6224. 3:51:47need to put the self in here and then we
  6225. 3:51:49can plug in parameters there as well. So
  6226. 3:51:52for example every dog when when we want
  6227. 3:51:54to have a dog object it should have a
  6228. 3:51:56name and it should have a breed and
  6229. 3:51:58similar if I for example want to create
  6230. 3:52:00a let's say a class we want to do with
  6231. 3:52:02cat I can do I would do the same thing I
  6232. 3:52:04would do dev I do underscore in it in it
  6233. 3:52:07and then I would plug it in a self and
  6234. 3:52:08let's say uh a cat has a name and in
  6235. 3:52:11this case I want to do a caller and then
  6236. 3:52:14we set those attributes on the class
  6237. 3:52:17itself by setting that equal to what we
  6238. 3:52:20want to plug in there. So, self.name and
  6239. 3:52:22self doc color is color. And then here
  6240. 3:52:26you can see there's an error because I
  6241. 3:52:27forgot the colon. Okay. So, this is how
  6242. 3:52:30you create classes fundamentally. But
  6243. 3:52:32now let's understand what what they're
  6244. 3:52:34doing because now you might be like,
  6245. 3:52:35yeah, okay, but what is this and what
  6246. 3:52:37can we do with it? So, now we have a dog
  6247. 3:52:40and a cat. And similar to how when we're
  6248. 3:52:43working with functions, we first create
  6249. 3:52:45the function and then we use the
  6250. 3:52:47function. With classes, you need to
  6251. 3:52:49initialize them. So remember classes are
  6252. 3:52:51objects and objects need to be created
  6253. 3:52:55and this is a blueprint for creating a
  6254. 3:52:58dog and within our program within our
  6255. 3:53:00application let's say this is a game we
  6256. 3:53:02can have multiple dogs. So we can for
  6257. 3:53:04example get I don't know Jerry and Jerry
  6258. 3:53:08is a dog and then in there we give him a
  6259. 3:53:11name and the name is Jerry and the breed
  6260. 3:53:15is let's say Jerry is a Labrador and now
  6261. 3:53:19we have Jerry over here which is the
  6262. 3:53:21claw's dog and what we can now do and
  6263. 3:53:23now we can for example take Jerry and we
  6264. 3:53:25can say what's Jerry's name and you'll
  6265. 3:53:28find that it's Jerry and what's the
  6266. 3:53:29breed it's a Labrador so you can see
  6267. 3:53:33that Now by creating a class creating
  6268. 3:53:35that blueprint we have now created an
  6269. 3:53:36object and that object is an instance of
  6270. 3:53:39the class dog and right now that class
  6271. 3:53:42has attributes. It has a name and it has
  6272. 3:53:45a breed and similar to how we need to be
  6273. 3:53:49specific about what we put in there with
  6274. 3:53:50functions. If I now for example try to
  6275. 3:53:52create another dog. So let's say we have
  6276. 3:53:54a dog and we call that dog Tim and we
  6277. 3:53:58don't specify the breed. we'll get an
  6278. 3:54:00error because it says look it's missing
  6279. 3:54:02the breed. So this now all everything
  6280. 3:54:05that we learned from functions is still
  6281. 3:54:07does still apply here. So we can also
  6282. 3:54:09for example put a default value in here
  6283. 3:54:12of none of unknown for example and now
  6284. 3:54:15when I create a dog now we can create a
  6285. 3:54:17we can create a dog with just the name
  6286. 3:54:19Tim. So that's how all of these things
  6287. 3:54:21that we've learned so far stack on top
  6288. 3:54:23of each other. So let's go a little bit
  6289. 3:54:25deeper to understand more about uh what
  6290. 3:54:28we can do with classes. So here you can
  6291. 3:54:29see I walked through this example. We
  6292. 3:54:31have the initializer. We can then create
  6293. 3:54:34doc objects using positional arguments
  6294. 3:54:36or with named arguments to be specific.
  6295. 3:54:38And then we can access the the
  6296. 3:54:40attributes and then here like this is
  6297. 3:54:43what it comes out. Yes in it looks weird
  6298. 3:54:44with those double underscores. This is
  6299. 3:54:46in Python this is actually called a
  6300. 3:54:47dunder method. you have like you in the
  6301. 3:54:50beginning you won't encounter it that
  6302. 3:54:52much but there are other places in
  6303. 3:54:53Python where you use this as well double
  6304. 3:54:56underscores it's just how Python works
  6305. 3:54:58you'll need to type it exactly like this
  6306. 3:55:00don't worry after writing it a few times
  6307. 3:55:02it becomes second nature like okay
  6308. 3:55:04clause defaf in it and then we do the
  6309. 3:55:06self in there it's just it's just Python
  6310. 3:55:08special's way of saying look this is a
  6311. 3:55:10setup method right so now let's
  6312. 3:55:11understand the other weird thing in
  6313. 3:55:13there the self thingy because what's
  6314. 3:55:15that why do we need to have self like
  6315. 3:55:17three times in here in order to just
  6316. 3:55:19create a class. So self refers to the
  6317. 3:55:22current object. It's how an object keeps
  6318. 3:55:24track of its own data. So remember
  6319. 3:55:26classes are blueprints and we can have
  6320. 3:55:27multiple dogs. And because of this, this
  6321. 3:55:30is just Python's way to say look when we
  6322. 3:55:33are working with Tim in this case
  6323. 3:55:36self.name is just stored like look this
  6324. 3:55:38is on the instance itself. This is Tim.
  6325. 3:55:40This is not the class level. That's why
  6326. 3:55:43we need to plug self in there. That's
  6327. 3:55:45how Python works under the hood. So you
  6328. 3:55:48can see over here if we have the class
  6329. 3:55:49dog and we just have the name in there
  6330. 3:55:51self.name belongs to this specific dog.
  6331. 3:55:54So you can create buddy it's dog one and
  6332. 3:55:56you can also have dog two call it max
  6333. 3:55:59and then you have the different names in
  6334. 3:56:00here. So you can try this out for
  6335. 3:56:02yourself. Come in here and then you can
  6336. 3:56:04see we have m we have buddy and we have
  6337. 3:56:06max. So that's kind of like a a mental
  6338. 3:56:08model that you can use to remember why
  6339. 3:56:11is why we have the self in here because
  6340. 3:56:13we can have multiple instances. Okay,
  6341. 3:56:16let's continue to a real world example
  6342. 3:56:18because also I remember when I was
  6343. 3:56:21learning classes and you go through
  6344. 3:56:23examples like this. You're like it's
  6345. 3:56:25very hard to like make the connection
  6346. 3:56:26between okay nice that I can give my dog
  6347. 3:56:30a name and a breed but like what like we
  6348. 3:56:32want to build AI programs, right? What
  6349. 3:56:34what does it have to do with dogs? So
  6350. 3:56:36here we go. In the real world when you
  6351. 3:56:38are working with classes, a very common
  6352. 3:56:40use case is to for example build an
  6353. 3:56:42entire class around an API config. So
  6354. 3:56:44when you're for example working with
  6355. 3:56:46open AAI you can say look I want to
  6356. 3:56:48store everything that we have. So the
  6357. 3:56:50API key I want to store the model the
  6358. 3:56:52max tokens the base URL I want to store
  6359. 3:56:55that in a class. So let's actually come
  6360. 3:56:57over here and just get rid of everything
  6361. 3:56:59and plug this in. So now we can see we
  6362. 3:57:02have a clause and we call it API config.
  6363. 3:57:04So now we're getting a little bit more
  6364. 3:57:05serious. So this is not just a dog. And
  6365. 3:57:07now we have that same defaf in it and a
  6366. 3:57:10self key in here but now we say look we
  6367. 3:57:12need an API key. We want to have a
  6368. 3:57:14model. We want to have max tokens. And
  6369. 3:57:16again, don't worry about what this all
  6370. 3:57:17is. This is just a way of look. We can
  6371. 3:57:19now store information in here. So if we
  6372. 3:57:21now have this class config and we have
  6373. 3:57:25that over here, we can now for example
  6374. 3:57:27say look, we can now create a dev
  6375. 3:57:29configuration where we now have this
  6376. 3:57:33class over here. And then if we want to
  6377. 3:57:35have a production configuration with
  6378. 3:57:37another production key, another model
  6379. 3:57:39and other settings, we now have that.
  6380. 3:57:41And I can now access all of this
  6381. 3:57:43information by looking over here at the
  6382. 3:57:45dev config. So in the dev uh config, we
  6383. 3:57:47have GPT3.5 turbo which really cheap,
  6384. 3:57:50it's fast, we can use to test it. But in
  6385. 3:57:52in the production version of our app, so
  6386. 3:57:54in the real world, I want to use a
  6387. 3:57:56beefier model. So I want to use that. So
  6388. 3:57:59now you can start to imagine like coming
  6389. 3:58:01back to the example of the toolbox.
  6390. 3:58:03Right? Now I have a very clean container
  6391. 3:58:06called dev config which is an instance
  6392. 3:58:08of the class API config. And in there I
  6393. 3:58:11have specific settings. And if I want to
  6394. 3:58:13have something else, I just create a new
  6395. 3:58:14instance of this, a new instance of that
  6396. 3:58:17class. And now within my code, I can
  6397. 3:58:19just do oh this is proconfig. Oh, this
  6398. 3:58:21is that dev config. And I can access the
  6399. 3:58:24attributes from from there. Remember
  6400. 3:58:26attributes are the data the data that
  6401. 3:58:29you store on there. So hopefully by now
  6402. 3:58:31you already start to get a little bit of
  6403. 3:58:33a better understanding to where classes
  6404. 3:58:35can fit in. And also you don't need
  6405. 3:58:37them. you could perfectly like write
  6406. 3:58:40everything out in variables and in
  6407. 3:58:41functions and you would still be able to
  6408. 3:58:43get the uh production configuration and
  6409. 3:58:45the dev configurations. This is just a
  6410. 3:58:47cleaner way a cleaner interface of doing
  6411. 3:58:50it using objectoriented programming. And
  6412. 3:58:52one important thing to keep in mind here
  6413. 3:58:54is the difference versus a class and the
  6414. 3:58:56instance because this can get tricky
  6415. 3:58:57when you're working with it. So the
  6416. 3:58:58class is the the specification the
  6417. 3:59:02blueprint itself and then the instances
  6418. 3:59:04are for example the dev config and the
  6419. 3:59:06pro proconfig that you have over here.
  6420. 3:59:08So a common mistake is that you for
  6421. 3:59:10example have this and let's say you want
  6422. 3:59:13to uh you want to use this and you do
  6423. 3:59:16API config and you want to have the
  6424. 3:59:18model and you want to do it like this
  6425. 3:59:20and it's like look there is no model in
  6426. 3:59:22here. I was like, wait what? But I I
  6427. 3:59:24plugged the model in here, right? So I
  6428. 3:59:25have the API config and I have the
  6429. 3:59:27model. But this is the class. This is
  6430. 3:59:29the class blueprint and you need to
  6431. 3:59:31create an instance of that. Let's see.
  6432. 3:59:33Let's get back. So you first need to
  6433. 3:59:36create the instance of that. So that is
  6434. 3:59:37the dev config. So this is now the
  6435. 3:59:40instance. And now the def config has the
  6436. 3:59:42model. So that's how that works. And now
  6437. 3:59:44working with classes in the beginning
  6438. 3:59:46can be tricky. So common mistakes
  6439. 3:59:48forgetting the init. So not having that
  6440. 3:59:50in there. uh not using the self,
  6441. 3:59:52forgetting parentheses, and modifying uh
  6442. 3:59:55the clause instead of the instance.
  6443. 3:59:57Those are all things that you may run
  6444. 3:59:59into. So those that was the introduction
  6445. 4:00:02to classes. So really starting with the
  6446. 4:00:04blueprint and then the attributes in
  6447. 4:00:06there. So that's what we covered.
  6448. 4:00:07Attributes are there to store data. But
  6449. 4:00:10now class you can also add methods to uh
  6450. 4:00:14methods to to classes and methods are
  6451. 4:00:16simply functions. Again this is
  6452. 4:00:17methodology. In clauses, we call it
  6453. 4:00:19methods instead of function. That's just
  6454. 4:00:21the way we do it. And they always have
  6455. 4:00:23the self as the first parameter. So this
  6456. 4:00:25is also something that's in there. And
  6457. 4:00:27you can pretty much do anything with
  6458. 4:00:30these functions in the in these methods
  6459. 4:00:32inside a class. But you can also do
  6460. 4:00:34outside of a class. So let's have a look
  6461. 4:00:36at an example over here where we have a
  6462. 4:00:38data validator. So now this is going to
  6463. 4:00:40get pretty pretty cool. Again, it's a
  6464. 4:00:42lot of code because I want to show you
  6465. 4:00:44like I want to teach you this by reverse
  6466. 4:00:46engineering this because typing all of
  6467. 4:00:48this out right now is is still a lot. So
  6468. 4:00:50you can see we have a data validator
  6469. 4:00:53class over here and we do a very simple
  6470. 4:00:56init. It only inits itself with errors
  6471. 4:00:59and there's a list. So in the beginning
  6472. 4:01:01there's nothing in there. So let's see
  6473. 4:01:03whenever I start this up I have my data
  6474. 4:01:05class and I create the instance of the
  6475. 4:01:08class. Now we have a data validator and
  6476. 4:01:10I can check inside this validator what
  6477. 4:01:13it has. It has the errors which is
  6478. 4:01:15currently an empty list but now instead
  6479. 4:01:18of the attributes that we have in in
  6480. 4:01:20here we also have methods. So you can
  6481. 4:01:24see with this data validator we can
  6482. 4:01:26validate an email we can validate an age
  6483. 4:01:28and we can get the errors. So here is
  6484. 4:01:31specific logic to see look how do we
  6485. 4:01:34validate an email? Well, if the ad
  6486. 4:01:36symbol is not in an email, we can say
  6487. 4:01:38look, there is an error and we append it
  6488. 4:01:40to our list and we return true or false.
  6489. 4:01:43And in a similar way, we can validate an
  6490. 4:01:45age to say look age needs to be between
  6491. 4:01:47needs to be lower than zero uh it needs
  6492. 4:01:49to be between zero and 150 and we check
  6493. 4:01:52that. So what we can now do is we can
  6494. 4:01:56use our data validator and then we can
  6495. 4:01:59call a method. So we use validator and
  6496. 4:02:02then what we can do is we do validate
  6497. 4:02:04email which is the method in here and
  6498. 4:02:06that takes email as a parameter and we
  6499. 4:02:08say look this is a bad email. So what we
  6500. 4:02:11can now do you'll see that this is
  6501. 4:02:13returning false because it got in here
  6502. 4:02:16if it's not in email we say look this is
  6503. 4:02:18false and we can also validate the h. So
  6504. 4:02:21this is now also false or using
  6505. 4:02:24positional arguments where we do so this
  6506. 4:02:26is here we say specifically we do email
  6507. 4:02:28is age is we can also do it similar to
  6508. 4:02:31how we saw with functions right uh where
  6509. 4:02:33we don't specify the email or the h but
  6510. 4:02:35I often say look you don't want to do
  6511. 4:02:37this and then in here we can print the
  6512. 4:02:39errors so now every time we run this and
  6513. 4:02:42we validate the data and an error
  6514. 4:02:44happens it goes into the if statement
  6515. 4:02:45and it uses the errors and it appends
  6516. 4:02:47that to the list that is a lot of
  6517. 4:02:49information going on over here I'm fully
  6518. 4:02:51aware of that. But it just goes to show
  6519. 4:02:54that we can use our data validator and
  6520. 4:02:57we can run it and then we can perform
  6521. 4:02:59certain actions. And every time I run
  6522. 4:03:01this, okay, I can say this is another
  6523. 4:03:03bad email, another bad email. And I run
  6524. 4:03:05this a couple of times. And now when I
  6525. 4:03:07print the errors, you can see that this
  6526. 4:03:08list is now getting very long because
  6527. 4:03:10it's storing all of that information.
  6528. 4:03:12And now you can see that this data
  6529. 4:03:15validator on its own becomes a really
  6530. 4:03:17powerful this validator becomes a really
  6531. 4:03:19powerful object because it can save
  6532. 4:03:21information. We can send new information
  6533. 4:03:23to it and we can build entire data
  6534. 4:03:26pipelines by just spec specifying
  6535. 4:03:28functions over here and then calling the
  6536. 4:03:30methods later down the line. So that was
  6537. 4:03:33showing a pretty extensive example. And
  6538. 4:03:36first I want to show you like look here
  6539. 4:03:37is what the end could look like and now
  6540. 4:03:39let's do a little bit of a simple
  6541. 4:03:41example where we say look let's get back
  6542. 4:03:42to the dog and we do the defaf init and
  6543. 4:03:45this is also good for you as an exercise
  6544. 4:03:47to follow along. So we init we remember
  6545. 4:03:50we had selfname let's just give it a
  6546. 4:03:53name uh we say is the name and then we
  6547. 4:03:55need to plug that in as a argument as
  6548. 4:03:58well and then also don't forget the
  6549. 4:04:01self. So you see also as I'm doing this,
  6550. 4:04:03it's it's one of those things. I know
  6551. 4:04:05the syntax. I know what a clause looks
  6552. 4:04:07like. But like even as you go through
  6553. 4:04:09this, you're like usually you forget
  6554. 4:04:11about these things because you think
  6555. 4:04:12about the about the logic, right? Oh, I
  6556. 4:04:15want my dog to have a name. But luckily
  6557. 4:04:17that's where our uh editor comes in and
  6558. 4:04:19says like look remember you need the
  6559. 4:04:20self in there. And now we can have a dog
  6560. 4:04:23and let's say we have uh let's let's
  6561. 4:04:26have Jerry again. So we have Jerry. So
  6562. 4:04:28we create the instance of the dog name
  6563. 4:04:31is Jerry. So there's Jerry. We now know
  6564. 4:04:35that Jerry has a name and we can print
  6565. 4:04:38that and it's correct Jerry. But now
  6566. 4:04:41let's give Jerry um a method. So Jerry
  6567. 4:04:45can also do something. So now what we
  6568. 4:04:47can do is we can come in here and we say
  6569. 4:04:48look we also want a method and we say
  6570. 4:04:51bark and we just plug in self and then
  6571. 4:04:54let's see we do like this and then we do
  6572. 4:04:56print and then we do bark. So now if we
  6573. 4:05:00do this and we initialize Jerry one more
  6574. 4:05:02time Jerry still has a name but look
  6575. 4:05:05Jerry can now do stuff. Jerry can bark.
  6576. 4:05:07So now Jerry can bark. All right so that
  6577. 4:05:09is how you can add behavior to classes.
  6578. 4:05:12So remember attributes for storing data
  6579. 4:05:15and then methods adding behaviors that
  6580. 4:05:18you can add to this as well. Now then
  6581. 4:05:20the next section over here is class
  6582. 4:05:22inheritance. Now here I want to like
  6583. 4:05:25briefly touched upon this because this
  6584. 4:05:26is definitely a more advanced uh an
  6585. 4:05:29advanced thing in Python. But whenever
  6586. 4:05:31we have a class we can use the concept
  6587. 4:05:35of inheritance to take a class and to
  6588. 4:05:37add more functionality to it. So let's
  6589. 4:05:40have a look over here. So let's say we
  6590. 4:05:42start with a basic clause of an animal.
  6591. 4:05:45So let's come in here. So we have a
  6592. 4:05:46clause. We have an animal. An animal has
  6593. 4:05:49a name and an animal can eat and sleep.
  6594. 4:05:52That's the that's the default class in
  6595. 4:05:54here. Now what we can do is we can
  6596. 4:05:56create a child class to create a
  6597. 4:05:59specific animal. So this is now the
  6598. 4:06:01parent clause and now we create the
  6599. 4:06:03child class. So let me actually copy the
  6600. 4:06:05whole example over here. It will make
  6601. 4:06:06more sense. So in the beginning you're
  6602. 4:06:09probably wondering like why would I use
  6603. 4:06:11this? But with this you can make your
  6604. 4:06:12code even more modular. So let's say you
  6605. 4:06:15have an animal and now here over here
  6606. 4:06:17you have the clause and you specify the
  6607. 4:06:20dog similar to how you normally would
  6608. 4:06:22specify the dog class that we just saw
  6609. 4:06:25but you put animal in here. And what
  6610. 4:06:27this tells Python is it says look take
  6611. 4:06:29the animal class take everything that is
  6612. 4:06:31in here but also add these specific
  6613. 4:06:34functions. So if we have this here in
  6614. 4:06:37memory, we can create a dog buddy and
  6615. 4:06:40now we have the dog and we can add
  6616. 4:06:42create dog number two and that is Max.
  6617. 4:06:44And now you can see without specifying
  6618. 4:06:47this at the at the dog level uh buddy
  6619. 4:06:50and both uh Max can also eat. So they
  6620. 4:06:54are eating, they are sleeping, but they
  6621. 4:06:56can also bark. So that's class
  6622. 4:06:57inheritance and that is really when you
  6623. 4:07:00get to the level where your codebase
  6624. 4:07:01grows and you have more and more uh
  6625. 4:07:04modular bits and pieces and you want to
  6626. 4:07:06extend the capability in there and
  6627. 4:07:08that's all that I want you to know for
  6628. 4:07:09now. So just the concept of inheritance
  6629. 4:07:11let you create a new class based on
  6630. 4:07:13existing ones. You have basic examples
  6631. 4:07:16you can add attributes in the child
  6632. 4:07:18classes that we saw right we added the
  6633. 4:07:20bark to the animal class. You can also
  6634. 4:07:22override methods. So you have the base
  6635. 4:07:25class which already might have a method
  6636. 4:07:27like make sound but then for a cat you
  6637. 4:07:30really want to change that you can
  6638. 4:07:31override things. So to summarize this
  6639. 4:07:33section when to use classes and this is
  6640. 4:07:37all about the programming paradigms. So
  6641. 4:07:40functional programming is all about
  6642. 4:07:42using functions to transform data.
  6643. 4:07:44Object-oriented programming is using
  6644. 4:07:47classes to bundle data and behavior. So
  6645. 4:07:49here's the recap for now. So both
  6646. 4:07:51approaches achieve the same result.
  6647. 4:07:53Classes don't unlock new features in
  6648. 4:07:55Python. They're just a different way to
  6649. 4:07:57organize your code. Choose based on what
  6650. 4:07:59makes your code cleaner and also uh the
  6651. 4:08:02level that you're confident with when
  6652. 4:08:04you're writing and working with your
  6653. 4:08:05Python files. As a general rule of
  6654. 4:08:07thumb, you want to use classes when you
  6655. 4:08:09want to keep track of a state between
  6656. 4:08:11operations. So you want to save data, h
  6657. 4:08:13group related data and functions
  6658. 4:08:14together for organization, create
  6659. 4:08:16multiple instances with similar behavior
  6660. 4:08:18or model real world objects or concepts.
  6661. 4:08:20And you can use functions when it's
  6662. 4:08:22about simple transformations, input,
  6663. 4:08:23output, stateless operations, so it
  6664. 4:08:25doesn't need to remember anything.
  6665. 4:08:27one-off calculations or small scripts.
  6666. 4:08:29And I recommend just start with
  6667. 4:08:31functions. They're simpler often and
  6668. 4:08:33often sufficient. And only you add
  6669. 4:08:35classes when you find yourself passing
  6670. 4:08:37the same data between multiple functions
  6671. 4:08:39when you need to maintain information
  6672. 4:08:41and a state. All right, and that wraps
  6673. 4:08:42up the section on building programs. So
  6674. 4:08:45in this section, we really accelerated,
  6675. 4:08:47right? We went from getting started the
  6676. 4:08:49Python basics, the fundamental building
  6677. 4:08:51blocks to now putting some scripts and
  6678. 4:08:53programs together where you can actually
  6679. 4:08:55see how everything starts to working
  6680. 4:08:57together and we even got into more
  6681. 4:08:59advanced concepts like using classes.
  6682. 4:09:02Now the final chapter of this course is
  6683. 4:09:04all about common tools that you'll work
  6684. 4:09:07with on a day-to-day basis when you are
  6685. 4:09:09working with the Python programming
  6686. 4:09:11languages. So instead of like going
  6687. 4:09:13deeper on Python specific syntax and
  6688. 4:09:15showing you more examples there, I'm
  6689. 4:09:17going to give you really like the full
  6690. 4:09:18toolkit that you need to go out in the
  6691. 4:09:21real world, build things, follow
  6692. 4:09:23tutorials, and you'll literally be
  6693. 4:09:24prepared for everything. So that also in
  6694. 4:09:26the follow-up recommendation courses
  6695. 4:09:28that I have for you on either like the
  6696. 4:09:30data science track or building agents,
  6697. 4:09:32like you can exactly follow along.
  6698. 4:09:33That's really the goal. So let's dive
  6699. 4:09:36into the tools. All right, so let's dive
  6700. 4:09:38into the final chapter of this full
  6701. 4:09:41Python beginner course. And here we are
  6702. 4:09:43going to cover some tools that you need
  6703. 4:09:46when you are working in the day-to-day
  6704. 4:09:48with the Python programming language. So
  6705. 4:09:50I can guarantee you when you go out in
  6706. 4:09:52the world, you'll follow tutorials,
  6707. 4:09:54you'll thank me for this because beyond
  6708. 4:09:56the Python basics, building programs,
  6709. 4:09:58everything that there is to the
  6710. 4:10:00language, these are also really things
  6711. 4:10:02you need to understand and they are the
  6712. 4:10:04following. So we are going to cover git
  6713. 4:10:07and github. Now these are also things
  6714. 4:10:09like if you're already familiar with
  6715. 4:10:11them feel free to skip for all of these
  6716. 4:10:12but you definitely need to understand
  6717. 4:10:14them. So if you're completely new to
  6718. 4:10:15this make sure to watch everything and
  6719. 4:10:18understand it. We're all I'm also going
  6720. 4:10:20to show you how to work with environment
  6721. 4:10:21variables. What they are how to use them
  6722. 4:10:24and then I'm going to introduce you to a
  6723. 4:10:26modern Python tool that can replace pip.
  6724. 4:10:28You remember the thing that we used to
  6725. 4:10:30install packages? and I'm going to
  6726. 4:10:32introduce you to UVI which is really
  6727. 4:10:34awesome and it will make our life as
  6728. 4:10:37Python programmers a lot easier. So
  6729. 4:10:40let's dive in and we are going to start
  6730. 4:10:43with Git and GitHub an absolute
  6731. 4:10:45must-have when you start your
  6732. 4:10:48programming journey. So for the very
  6733. 4:10:50basics if you have never heard of git
  6734. 4:10:52what it is it's like a safe uh system
  6735. 4:10:55for your code. It can track all the
  6736. 4:10:57changes that you make and let you go
  6737. 4:10:59back to previous versions. So that when
  6738. 4:11:01you are for example working over here,
  6739. 4:11:04you create a snapshot and then when the
  6740. 4:11:06next day you continue and you all of a
  6741. 4:11:08sudden realize that you made a mistake
  6742. 4:11:10and you want to go back. That's all
  6743. 4:11:12possible through Git. Because if we're
  6744. 4:11:14here on our file system, we can just
  6745. 4:11:17save the file, right? But that saves the
  6746. 4:11:19snapshot right now and it's not really
  6747. 4:11:21easy to go back or to work on different
  6748. 4:11:24versions or even to work with a team. So
  6749. 4:11:26that's a problem that git uh solves. It
  6750. 4:11:29allows us to go pre to go back to
  6751. 4:11:31previous versions and also collaborate
  6752. 4:11:33with others. You can really think of it
  6753. 4:11:35like Google Drive or Dropbox with
  6754. 4:11:37version control. So why you need it?
  6755. 4:11:40save your progress, experiment with
  6756. 4:11:42things knowing that you can always go
  6757. 4:11:44back, share your projects with others,
  6758. 4:11:45and also to use other AI tools, codes,
  6759. 4:11:48and repositories from other people
  6760. 4:11:50because whenever someone shares code
  6761. 4:11:52online in a tutorial, 99% of the time
  6762. 4:11:54they'll share it via GitHub. And knowing
  6763. 4:11:56how to use git and then also what GitHub
  6764. 4:11:59is will make all the difference. So,
  6765. 4:12:01what we are going to cover is we're
  6766. 4:12:03going to cover the fundamentals of git
  6767. 4:12:05and then also I'm going to show you how
  6768. 4:12:07you can set up GitHub. So, there's a
  6769. 4:12:08difference between the two. That's also
  6770. 4:12:10something you should be aware of. So
  6771. 4:12:11we'll go over a basic setup all very
  6772. 4:12:14quick. This is by no means like a full
  6773. 4:12:16dedicated course on how to use GIP. But
  6774. 4:12:18the thing is in the beginning you only
  6775. 4:12:20really need to understand the
  6776. 4:12:21fundamentals. There are only a hand few
  6777. 4:12:23uh handful of things that you need to
  6778. 4:12:25understand. So that's the nice thing
  6779. 4:12:27about this and that's why I really
  6780. 4:12:28wanted to be part of this course as
  6781. 4:12:30well. Right. So let's start with what is
  6782. 4:12:33version control. So like I've said, one
  6783. 4:12:36of the main problems that GitHub can
  6784. 4:12:38help solve is that we don't have to do
  6785. 4:12:40something like this where we have your
  6786. 4:12:42script and then you want to try
  6787. 4:12:43something, you go to F2 and then you
  6788. 4:12:45want to try final actually final and oh
  6789. 4:12:47it still broke and then you need
  6790. 4:12:48to create a backup. So that is the
  6791. 4:12:51problem Git solves. So how it works, you
  6792. 4:12:54can think of Git as taking a snapshot of
  6793. 4:12:56your code. So you write your code, you
  6794. 4:12:57make your changes, and then you can save
  6795. 4:12:59the the snapshot. I'm going to show you
  6796. 4:13:01how to do that. In Git, this is called a
  6797. 4:13:03commit. So we commit our work and git
  6798. 4:13:06remembers everything every snapshot who
  6799. 4:13:08made it uh when and why. So when you
  6800. 4:13:12when here's your code like for example
  6801. 4:13:14on Monday you calculate the price over
  6802. 4:13:16here and then on Tuesday your client
  6803. 4:13:19says look we want to add a 25% markup.
  6804. 4:13:22So you change it. So then on Wednesdays
  6805. 4:13:24like hey can we actually go back to 20%.
  6806. 4:13:27And in this case that's easy. You just
  6807. 4:13:28go back to Monday's version. Now with
  6808. 4:13:30this like tiny little change like
  6809. 4:13:32changing one digit, it of course
  6810. 4:13:34wouldn't be that big of a difference,
  6811. 4:13:36right? But imagine you're having a big
  6812. 4:13:37codebase, you are working on lots of
  6813. 4:13:39stuff and then all of a sudden it
  6814. 4:13:41doesn't work. Let's go back to the
  6815. 4:13:42previous version. So that's really the
  6816. 4:13:44key concept and a key problem that git
  6817. 4:13:46solves. Uh let's go through a few
  6818. 4:13:48fundamental concepts. This is really
  6819. 4:13:49all. So this overview, this list, this
  6820. 4:13:51is all that you need to know for now. So
  6821. 4:13:54let's start with a repository. That is a
  6822. 4:13:57project tracked by Git. That's why I
  6823. 4:14:00also said that in the beginning when we
  6824. 4:14:02were creating our projects right so when
  6825. 4:14:04we were here when we were let me show
  6826. 4:14:06you this in the finder when we were
  6827. 4:14:09creating this project I already said
  6828. 4:14:10look I recommend to do it with all like
  6829. 4:14:13lowercase and dashes to make sure that
  6830. 4:14:16also when we push this to GitHub that we
  6831. 4:14:18can use the same repository name so
  6832. 4:14:20that's where the repository come from
  6833. 4:14:22that is simply a project tracked by git
  6834. 4:14:25staging is a concept which allows you to
  6835. 4:14:27choose which changes is to save. It's
  6836. 4:14:30like selecting items to put in the box
  6837. 4:14:32before shipping. So let's say you have
  6838. 4:14:33all of your project and you say I want
  6839. 4:14:34to save this, this, and this and this
  6840. 4:14:36and maybe I would don't want to save
  6841. 4:14:38that. Then we have the commit which is
  6842. 4:14:41actually creating the snapshot of your
  6843. 4:14:43code. Then we have pushing. This is
  6844. 4:14:45uploading things to GitHub. So then now
  6845. 4:14:48they also really become available
  6846. 4:14:50online. Then we have pulling which is
  6847. 4:14:52downloading the changes back. So let's
  6848. 4:14:54say you are working with someone else on
  6849. 4:14:56a team. They made some changes. They
  6850. 4:14:58committed the changes. They pushed the
  6851. 4:15:00changes. Now they are online. Now you
  6852. 4:15:02can pull those changes and now you are
  6853. 4:15:05at the same uh version again that they
  6854. 4:15:07are. And we can also clone projects. So
  6855. 4:15:10we can clone repositories from GitHub
  6856. 4:15:12which I will also show you how to do. So
  6857. 4:15:14this is if you're completely new and
  6858. 4:15:16someone shares their work, you don't
  6859. 4:15:18have it on your computer right now, you
  6860. 4:15:19can clone it. So you'll find that Git
  6861. 4:15:22has this like specific vocabulary, but
  6862. 4:15:25it's nothing more than saving files,
  6863. 4:15:27uploading them, and downloading the
  6864. 4:15:29codes to your computer. That's all
  6865. 4:15:32really there is to it. It just has its
  6866. 4:15:34own specific vocabulary. All right, so
  6867. 4:15:37first we're going to install Git on your
  6868. 4:15:41computer. And first you need to check if
  6869. 4:15:43you already have Git. So you can check
  6870. 4:15:45out the Git version. So you can open up
  6871. 4:15:47the terminal either on Mac or on
  6872. 4:15:49Windows, doesn't matter. You do get git
  6873. 4:15:51d- version. And here you can see on my
  6874. 4:15:54laptop that it already says, look, you
  6875. 4:15:56already have this version. So if it says
  6876. 4:15:58something like this for you already, you
  6877. 4:16:00can skip the installation phase. Now
  6878. 4:16:02here are instructions for Windows, Mac,
  6879. 4:16:05and Linux. It's pretty straightforward
  6880. 4:16:07to go through. For Windows, you can just
  6881. 4:16:08go to this website and you can download
  6882. 4:16:10kit over here. You'll have the
  6883. 4:16:12installer. And for Mac OS, there are a
  6884. 4:16:13couple of options. So you can install it
  6885. 4:16:15via homebrew if that's installed. You
  6886. 4:16:17can also alternatively install it via uh
  6887. 4:16:20Xcode command line tools. So if you do
  6888. 4:16:22get desk version Mac, your MacBook will
  6889. 4:16:24probably ask you, hey look, do you want
  6890. 4:16:26to install git if it's not found, you
  6891. 4:16:28can click install. You can wait a few
  6892. 4:16:30minutes and otherwise you can also go to
  6893. 4:16:32the official download page over here to
  6894. 4:16:34find more information. So that should
  6895. 4:16:37all be relatively straightforward by
  6896. 4:16:39now. Oh, and then just make sure that
  6897. 4:16:40git- version in the terminal uh works
  6898. 4:16:43for you after the installation. All
  6899. 4:16:46right, so now that git is installed on
  6900. 4:16:48your system, let's go through how you
  6901. 4:16:50can actually use it and work with this.
  6902. 4:16:52And here is a very simple example, the
  6903. 4:16:55most basic example of how git works. And
  6904. 4:16:57I'm first going to show it here just
  6905. 4:17:00conceptually. We're not going to work
  6906. 4:17:01through it because we first need to set
  6907. 4:17:03up GitHub uh on your end so that you can
  6908. 4:17:05actually push the changes. But high
  6909. 4:17:08level this is how git works. Whenever
  6910. 4:17:10you're working on a project we first
  6911. 4:17:12need to initialize the project. We need
  6912. 4:17:15to create the project in git and we do
  6913. 4:17:18this through git init. So this is these
  6914. 4:17:21are terminal commands. So this is not
  6915. 4:17:22something you run within your python
  6916. 4:17:25script and then execute over here. This
  6917. 4:17:27would be something where you open up a
  6918. 4:17:29terminal and where within your folder
  6919. 4:17:32you run these commands. Now the nice
  6920. 4:17:34thing about uh VS code is that we can
  6921. 4:17:38also do this through the UI. So there is
  6922. 4:17:41a source control menu over here where
  6923. 4:17:44you can for example see right now
  6924. 4:17:45initialize repository. That would be the
  6925. 4:17:48same as running git in it. So throughout
  6926. 4:17:51this tutorial in this section I want to
  6927. 4:17:53show you first how to use the commands
  6928. 4:17:54because that's what's going on under the
  6929. 4:17:56hood. But I always use the visual
  6930. 4:17:59interface from Visual Studio Code
  6931. 4:18:01because it's just a lot easier and you
  6932. 4:18:02don't have to remember the commands. But
  6933. 4:18:04you initialize the repository. That's
  6934. 4:18:06step one. Then you're going to stage
  6935. 4:18:08your changes. So you can say at get add
  6936. 4:18:11and then the dot signals that you want
  6937. 4:18:13to do everything. In most cases, this is
  6938. 4:18:15what you want to do. You just want to
  6939. 4:18:16save all your progress. So this is
  6940. 4:18:18staging. That's how that works. Then we
  6941. 4:18:20commit it. So then we can add a comment
  6942. 4:18:24in there as well. So let's say we added
  6943. 4:18:26or changed the price calculation. We can
  6944. 4:18:28give a little comment for us later or
  6945. 4:18:30for your team to know okay these are the
  6946. 4:18:32changes that I made and then we push it
  6947. 4:18:34to GitHub. So that's how git works. But
  6948. 4:18:37now before running all of this let's get
  6949. 4:18:40into the setup and then we can really
  6950. 4:18:43run the end to end example because like
  6951. 4:18:45you see you need to connect your GitHub
  6952. 4:18:47first. All right. So let's get into the
  6953. 4:18:50GitHub setup. Okay. So, if you don't
  6954. 4:18:52have a GitHub account yet, go to
  6955. 4:18:54github.com and sign up. So, let's see
  6956. 4:18:57over here. I'm already logged in, but in
  6957. 4:18:58here you can do sign up for GitHub.
  6958. 4:19:00Create your account. You can use your
  6959. 4:19:01Google account. Very straightforward.
  6960. 4:19:04And then from there, pick a username,
  6961. 4:19:06email, password, verify your account,
  6962. 4:19:08you can set up your profile, profile
  6963. 4:19:10picture, edit your name, image, whatever
  6964. 4:19:12you want. This is one of the most
  6965. 4:19:14important profiles as a developer. So,
  6966. 4:19:16if you don't already have one, make sure
  6967. 4:19:18to set it up. This is also literally
  6968. 4:19:21what can get you hired. This this might
  6969. 4:19:23be what people ask for on during
  6970. 4:19:25interviews. Clients might want to see
  6971. 4:19:27it. So this is going to be one of your
  6972. 4:19:28most important profiles as a developer.
  6973. 4:19:30More important than your LinkedIn
  6974. 4:19:32profile for getting jobs and getting
  6975. 4:19:34work. Okay. Now step number four is we
  6976. 4:19:36now have your account created and we now
  6977. 4:19:39need to create a link between your local
  6978. 4:19:41computer and the uh online uh GitHub
  6979. 4:19:45account really so that we have a link so
  6980. 4:19:46that when we push the changes our
  6981. 4:19:48computer knows where to send it. So you
  6982. 4:19:51can first set up your name and your
  6983. 4:19:54email. So this is a one-time setup that
  6984. 4:19:56you need to do. So you can say get
  6985. 4:19:58config global and you say your username
  6986. 4:20:00and then you can say for example your
  6987. 4:20:02name and also your email. This is a way
  6988. 4:20:04for git to store all of the information
  6989. 4:20:06so that when you do things on uh your
  6990. 4:20:09computer, git essentially adds this
  6991. 4:20:12information to all of the changes that
  6992. 4:20:14you make. Okay? And then you so you do
  6993. 4:20:16this in the terminal. So one more time,
  6994. 4:20:18you open up the terminal and then it
  6995. 4:20:20would be get config and then you would I
  6996. 4:20:24would for example do eilar. That's how
  6997. 4:20:26you set it up and you also do that for
  6998. 4:20:28the email that you've used. That's a
  6999. 4:20:30onetime setup. All right. All right. And
  7000. 4:20:32then next we need to set up your
  7001. 4:20:33authentication method to let your laptop
  7002. 4:20:36know where your account is and how to
  7003. 4:20:38authenticate so we can actually push
  7004. 4:20:40changes. So the re my recommended
  7005. 4:20:42approach is to do this through the
  7006. 4:20:44GitHub CLI. So there are three ways to
  7007. 4:20:45do it. You can do it with an HTTPS token
  7008. 4:20:48SSH key, but the CLI is really the
  7009. 4:20:50easiest one uh to do it. So on Mac OS
  7010. 4:20:53you can do brew install um gh and then
  7011. 4:20:56you install it. And on Windows, you can
  7012. 4:21:00if you go you go in here, you can
  7013. 4:21:01download for Mac and then you'll see
  7014. 4:21:02download on Windows. And then you should
  7015. 4:21:05that got get that up and running because
  7016. 4:21:06what you can do then it's super easy.
  7017. 4:21:09You can just open up a new terminal. I'm
  7018. 4:21:12already uh authenticated. So I can for
  7019. 4:21:14example do I can check this GH version.
  7020. 4:21:17What's in here? Yes, you can do GH to
  7021. 4:21:19see all of the commands that are in
  7022. 4:21:21here. And then what you can do is you
  7023. 4:21:24can do simply do gh login and there you
  7024. 4:21:28can see where do you want to login. We
  7025. 4:21:29do github.com. We go in here and then
  7026. 4:21:32you can choose what's your preferred uh
  7027. 4:21:33protocol. So you can choose uh SSJs
  7028. 4:21:36which I recommend or http and then you
  7029. 4:21:40can authenticate via the browser. So
  7030. 4:21:41just follow the steps over here. And
  7031. 4:21:43here's what that would look like. So you
  7032. 4:21:45select SSH then you need to select the
  7033. 4:21:47public key. So you can select one of the
  7034. 4:21:48keys that is available there. Then you
  7035. 4:21:50can give it the name. So for example,
  7036. 4:21:52you can do MacBook Pro like 2023. That's
  7037. 4:21:54my MacBook that I'm running this on. And
  7038. 4:21:56then you select authenticate via the web
  7039. 4:21:58browser and then a pop-up will open in
  7040. 4:22:00the browser. You can log in. You'll find
  7041. 4:22:02a one-time code that you then need to
  7042. 4:22:04paste into the browser and then you just
  7043. 4:22:06need to log in, select it, and then you
  7044. 4:22:08should be good to go. You see all of the
  7045. 4:22:10info here right now. This might be a
  7046. 4:22:12lot, but when you go through it, it will
  7047. 4:22:13just be step by step. Just so just to
  7048. 4:22:15follow what the terminal is saying, hit
  7049. 4:22:17enter and select what you want. So and
  7050. 4:22:19otherwise always you can troubleshoot
  7051. 4:22:21with uh JGPT in order to make the
  7052. 4:22:24connection work. Okay. So now we have
  7053. 4:22:26git installed. You understand high level
  7054. 4:22:29how git works. We have authenticated
  7055. 4:22:32your local git with your GitHub account.
  7056. 4:22:35So we now have a sync. So now let's get
  7057. 4:22:37into cloning and creating repositories.
  7058. 4:22:40So two things you'll often do when
  7059. 4:22:42working with git is downloading someone
  7060. 4:22:45other someone else's work cloning and
  7061. 4:22:47creating and starting your own projects
  7062. 4:22:49and saving the progress. So let's learn
  7063. 4:22:52both in this case and we are going to
  7064. 4:22:54start by cloning a repository. So this
  7065. 4:22:57means we can take a look at someone
  7066. 4:22:59else's work and we can download that. So
  7067. 4:23:03let's say we have the following file
  7068. 4:23:06over here. So, you're looking online,
  7069. 4:23:07you're following a tutorial, and you
  7070. 4:23:09stumble upon the OpenAI quick start in
  7071. 4:23:11Python from OpenAI. There are a bunch of
  7072. 4:23:13examples in here, and you want to try
  7073. 4:23:15and experiment with this. Now, what you
  7074. 4:23:18can do with Git now that you have set it
  7075. 4:23:19up correctly, we can easily take this
  7076. 4:23:22project and download it to our computer.
  7077. 4:23:25So, let's go through how you can do
  7078. 4:23:28this. And we can execute a command
  7079. 4:23:31through the terminal to download a
  7080. 4:23:33repository. And in order to do that,
  7081. 4:23:35what you want to do is you want to open
  7082. 4:23:36up a terminal in the folder where you
  7083. 4:23:39want to store the project. So if we come
  7084. 4:23:41over to our Python projects, which is
  7085. 4:23:42what I recommend to uh you have a single
  7086. 4:23:45folder, right? What you can do on Mac,
  7087. 4:23:47you can rightclick and if you go all the
  7088. 4:23:49way to the bottom, so you can see
  7089. 4:23:50services over here, you can see new
  7090. 4:23:52terminal, add folder. What this will do,
  7091. 4:23:55this will open up a new terminal. And
  7092. 4:23:57we're already within this project. So
  7093. 4:23:59you can see right now we are in this
  7094. 4:24:01folder over here. So, we're already at
  7095. 4:24:03the right uh point. And with in this
  7096. 4:24:05case, we don't have to like do the CD
  7097. 4:24:07and navigate through the terminal, which
  7098. 4:24:09I always find a little bit annoying. On
  7099. 4:24:11Windows, you can do the the same thing.
  7100. 4:24:13If you right click a folder, file
  7101. 4:24:14explorer, open in terminal. So, that's
  7102. 4:24:17how to do it. And now, here's how you
  7103. 4:24:19clone uh a repository. So, you don't
  7104. 4:24:21have to do these commands over here. We
  7105. 4:24:23can just go to the repository that we
  7106. 4:24:26want to clone. We click on code over
  7107. 4:24:28here and we copy the URL. So we copy
  7108. 4:24:32this URL. Then we go to our folder over
  7109. 4:24:36here and then make sure we have the
  7110. 4:24:37terminal in here. And then you type in
  7111. 4:24:39get clone and then you paste in the URL.
  7112. 4:24:42Now when we do this, what you'll find is
  7113. 4:24:44that now you can see OpenAI quickart
  7114. 4:24:46Python is now downloaded in here. So now
  7115. 4:24:49I can check in here and I can see
  7116. 4:24:51everything that is within this
  7117. 4:24:52repository. Now if you get an error over
  7118. 4:24:55here, some type of a authentication
  7119. 4:24:57error, just follow what is set in the
  7120. 4:24:59terminal over here. It might be that
  7121. 4:25:01because of how you set it up either
  7122. 4:25:03through HTTP, SSH or GitHub CLI, there
  7123. 4:25:05may be one additional authentication
  7124. 4:25:08step that is required in here and this
  7125. 4:25:10is just a first time setup that you need
  7126. 4:25:12to do and if it then works you can also
  7127. 4:25:14for example later use the SSH or the uh
  7128. 4:25:17GitHub CLI uh command. So in my case
  7129. 4:25:20this would also work. So let's see if I
  7130. 4:25:22go in here and I for example remove this
  7131. 4:25:25come in here one more time like this
  7132. 4:25:27would do exactly the same thing and it
  7133. 4:25:29would also download the repository in
  7134. 4:25:32here. All right. So now the next thing
  7135. 4:25:34that you can do here's quick little
  7136. 4:25:36shortcut. So we now have the folder,
  7137. 4:25:39right? And we could just as well like
  7138. 4:25:41open up Visual Studio Code, create a new
  7139. 4:25:43project, but there's actually a shortcut
  7140. 4:25:44for this. And you can use the code uh
  7141. 4:25:47command. And the first time you do this,
  7142. 4:25:49you need to uh set this up. So in Visual
  7143. 4:25:52Studio Code, if you are in here on Mac
  7144. 4:25:55and you do commandshiftp and then you do
  7145. 4:25:58shell command. So let's see in here. I
  7146. 4:26:00do command shiftp and I do shell
  7147. 4:26:03command. So I do install code command in
  7148. 4:26:06path. If I click this, this is a
  7149. 4:26:08one-time setup. Then what we can do now
  7150. 4:26:11uh and with Windows it's uh it's the
  7151. 4:26:13same thing during installation. Now what
  7152. 4:26:15we can do is I can actually see the so
  7153. 4:26:19let's see I mean change directory into
  7154. 4:26:21this folder. So into the open AI and I
  7155. 4:26:23can tap to autocomplete. I can now go
  7156. 4:26:26into this folder. So now within the
  7157. 4:26:27terminal I am here and then I can do
  7158. 4:26:29code and I can do a dot and then this
  7159. 4:26:32will open up this folder over here that
  7160. 4:26:34you'll see. So in Visual Studio Code
  7161. 4:26:37everything is in here and now I can
  7162. 4:26:39simply just save it as a workspace. Save
  7163. 4:26:42it in this folder. Everything that we
  7164. 4:26:43learned right and now I can just close
  7165. 4:26:45this out come in here and now I have
  7166. 4:26:48this project and I can start working
  7167. 4:26:50with this. So this is just also one of
  7168. 4:26:52those things in the beginning you need
  7169. 4:26:53to see it a couple of times. Uh you
  7170. 4:26:55don't need to use the dot code. You can
  7171. 4:26:57also what you can also even do like look
  7172. 4:26:59I'll give you one more tip. You can also
  7173. 4:27:01just take this you can on Mac you can
  7174. 4:27:03drag it in here also works. So just
  7175. 4:27:06click a little ways to make the whole
  7176. 4:27:08process of getting projects onto your uh
  7177. 4:27:11machine easier. So then coming back to
  7178. 4:27:15the setup you now have it on your
  7179. 4:27:17computer. What just happened? Get
  7180. 4:27:18downloaded all of the files. get
  7181. 4:27:20download all of the history and you can
  7182. 4:27:22now run modify and learn from this code.
  7183. 4:27:25So this is a very fundamental skill. So
  7184. 4:27:27if you'll find that this might this
  7185. 4:27:29video might be the starting point for
  7186. 4:27:31you to do anything with Python. If you
  7187. 4:27:33for example go to my you to my YouTube
  7188. 4:27:35channel to my other videos, you'll find
  7189. 4:27:37that every video where there is a an
  7190. 4:27:40example I'll say look the link to the
  7191. 4:27:42GitHub uh repository is in the
  7192. 4:27:44description. You now know exactly what
  7193. 4:27:46to do in order to get that codebase on
  7194. 4:27:48your computer. and then to also follow
  7195. 4:27:51along. Okay, so that was step number
  7196. 4:27:52one, cloning, but we can also now create
  7197. 4:27:56our own repository remember and now we
  7198. 4:27:58can come back to the project that we
  7199. 4:28:00were working on. So over here, so let's
  7200. 4:28:02say we want to push this to we want to
  7201. 4:28:05push this to GitHub. So let's see how
  7202. 4:28:08that works. And before we're going to
  7203. 4:28:11push everything, there's one more thing
  7204. 4:28:13that we need to add and that is a git
  7205. 4:28:15ignore file. And this is very important
  7206. 4:28:17because there are some files that we
  7207. 4:28:20just don't want to store to GitHub. And
  7208. 4:28:22primarily this is going to be our
  7209. 4:28:24virtual environment. So if I come over
  7210. 4:28:26here and look at the virtual environment
  7211. 4:28:28for example and I look at how big this
  7212. 4:28:31is we can see this is uh this is 270 MBs
  7213. 4:28:35and because this is because there's a
  7214. 4:28:37Python installation in there and we
  7215. 4:28:39don't want this in our version control
  7216. 4:28:41and similar there are other files uh
  7217. 4:28:43environment variables secrets cache the
  7218. 4:28:46Macds store file we don't want that in
  7219. 4:28:49there and git has a feature for that
  7220. 4:28:51through git ignore how you can do that
  7221. 4:28:53is you can come in here do create a new
  7222. 4:28:55file and you do dot and you do get
  7223. 4:28:58ignore and you hit enter. Now you can
  7224. 4:29:00see VS code will also recognize this. So
  7225. 4:29:02you will see a little icon in here for
  7226. 4:29:05this file. And now what you want to do
  7227. 4:29:06is you can copy paste this in here and
  7228. 4:29:10save this. Now this I would say is the
  7229. 4:29:13most minimal setup that you can go
  7230. 4:29:15through. But there's actually a better
  7231. 4:29:16way and something that we use for all of
  7232. 4:29:19our projects. This is kind of like the
  7233. 4:29:20starting point to set it, forget it. You
  7234. 4:29:22never have to worry about it ever again.
  7235. 4:29:24And that is available in the resource
  7236. 4:29:26hub. So if you come in here and go to
  7237. 4:29:28the resources, you see the git
  7238. 4:29:30ignore.zip. So if you download this and
  7239. 4:29:34then come let's see to the downloads. So
  7240. 4:29:37let me actually show you what that looks
  7241. 4:29:39like. We download that open in finder.
  7242. 4:29:42What you can then do is you can unpack
  7243. 4:29:44it. And this is also a hidden file. So,
  7244. 4:29:46if you don't see it, what you can also
  7245. 4:29:48do is just drag and drop the zip file
  7246. 4:29:50into your project and then open it up in
  7247. 4:29:53here. And then let's see. Let me
  7248. 4:29:55actually get rid of this. And I'm moving
  7249. 4:29:57a little bit quick in here, but I'm just
  7250. 4:29:58like moving moving the file. And I'm
  7251. 4:30:01going to unpack it here. And then you
  7252. 4:30:03can see you have the zip. And then all
  7253. 4:30:04you need to do because this depending on
  7254. 4:30:06your system, this can be a little bit
  7255. 4:30:08annoying because it will automatically
  7256. 4:30:09give it a name. It doesn't need it needs
  7257. 4:30:11to be exactly ignore. So it needs to be
  7258. 4:30:14like this. And now you can see we have a
  7259. 4:30:17whole list of all the files that we do
  7260. 4:30:19not want in our version control. All
  7261. 4:30:21right. So that's the get ignore file.
  7262. 4:30:24It's one of those things in the
  7263. 4:30:26beginning you set it, forget it, but if
  7264. 4:30:27you don't do it, uh you'll run into all
  7265. 4:30:29kinds of issues. So very important uh
  7266. 4:30:32and useful feature and useful uh
  7267. 4:30:34resource from the resource hub. So make
  7268. 4:30:35sure you download that uh and we can use
  7269. 4:30:38it for all your projects. So now we have
  7270. 4:30:40our project locally, right? We have
  7271. 4:30:42everything over here. But now what we
  7272. 4:30:44need to do is we want to create a
  7273. 4:30:46project on GitHub that we can send this
  7274. 4:30:50to. So we now go to github.com and we're
  7275. 4:30:53going to click on new. So over here I do
  7276. 4:30:55new repository and then I'm going to
  7277. 4:30:58call this Python for AI. So you can you
  7278. 4:31:02can name it whatever you want but I
  7279. 4:31:04recommend just following along with
  7280. 4:31:05this. And let's see. You can decide if
  7281. 4:31:09you want it to be public or private.
  7282. 4:31:11This is really important. Not for this
  7283. 4:31:13tutorial. You can totally set this to
  7284. 4:31:15public. But this simply means that
  7285. 4:31:16everything that you're going to save and
  7286. 4:31:18store like everyone is going to see
  7287. 4:31:20that. So of course when you are working
  7288. 4:31:22on projects that are private projects
  7289. 4:31:24that you don't want to share, I
  7290. 4:31:25recommend always setting it to private
  7291. 4:31:27as like a default and then only setting
  7292. 4:31:29it to public if you really want to share
  7293. 4:31:31stuff with like the world. Because if
  7294. 4:31:33you want to share stuff with just your
  7295. 4:31:35colleagues or friend, you can also
  7296. 4:31:36invite them through a private
  7297. 4:31:37repository. So this is important. So you
  7298. 4:31:40can select you can select the owner if
  7299. 4:31:42you have multiple uh repository names or
  7300. 4:31:44like I I already have one. So let's for
  7301. 4:31:46me I do like Python 4AI 2 just to show
  7302. 4:31:49you what that looks like. And then you
  7303. 4:31:51can leave everything as is. Make sure
  7304. 4:31:52you set it to private. Uh this doesn't
  7305. 4:31:54matter. And then you do create
  7306. 4:31:56repository. Okay. So now we see this
  7307. 4:31:59interface over here. And what we can now
  7308. 4:32:01do is let's see we can do this. We can
  7309. 4:32:05now connect our local project to this
  7310. 4:32:08project that we just created. And how
  7311. 4:32:11you can do that is through the following
  7312. 4:32:14process. So we can come over here to our
  7313. 4:32:17project. And I'm first going to show you
  7314. 4:32:20how to do this via the terminal. But
  7315. 4:32:22Visual Studio Code actually has a very
  7316. 4:32:24nice interface for this where we can
  7317. 4:32:27just initialize publish to GitHub. So
  7318. 4:32:29this will make our life a whole lot
  7319. 4:32:30easier. But I want to show you like the
  7320. 4:32:33first time right now how to do it via
  7321. 4:32:35the terminal just so you know what it is
  7322. 4:32:37doing uh behind the scenes. So let's
  7323. 4:32:39take things step by step and open up a
  7324. 4:32:42new terminal over here. And then what
  7325. 4:32:45you want to do is first we want to do
  7326. 4:32:47the git init. So when we come in here we
  7327. 4:32:50do get init. And this will create a
  7328. 4:32:54github project with in the folder that
  7329. 4:32:57we are working in. And you will see
  7330. 4:32:59output in the terminal, but you won't
  7331. 4:33:01see anything here in uh the explorer.
  7332. 4:33:04But that is the thing there. This is
  7333. 4:33:06also because it's a hidden file. So if I
  7334. 4:33:08go in here, you can now see that there
  7335. 4:33:10is a git folder with all of the
  7336. 4:33:12information that git is going to keep
  7337. 4:33:14track of. You don't have to do anything
  7338. 4:33:16with this folder, but it's good to be
  7339. 4:33:18aware that this folder is created
  7340. 4:33:20because when it's hidden and you are,
  7341. 4:33:22for example, moving files back and
  7342. 4:33:24forth. If you make copies and you make
  7343. 4:33:26changes and you forget to copy the uh
  7344. 4:33:28git the git folder, then you can lose
  7345. 4:33:30track of those changes locally. So
  7346. 4:33:33that's important to keep in mind. Okay.
  7347. 4:33:36Then what we are going to do is we're
  7348. 4:33:38going to stage your files. So we're
  7349. 4:33:40going to run the command get add. And
  7350. 4:33:43add simply means we're going to stage,
  7351. 4:33:45we're going to select which files we
  7352. 4:33:46want to add, but we want to send to our
  7353. 4:33:49online GitHub project. And the dot
  7354. 4:33:51simply means that we want to do all the
  7355. 4:33:53files. So this is very common. Um,
  7356. 4:33:55unless you really know what you're
  7357. 4:33:57doing, generally what you want to do is
  7358. 4:33:58just want to add all the files. So let's
  7359. 4:34:00do that right now. So we come in here,
  7360. 4:34:02we do get add, and then we do a dot, we
  7361. 4:34:05hit enter. So now it's going to add all
  7362. 4:34:07of the files, and it's they are staged.
  7363. 4:34:10And now the next step is we're going to
  7364. 4:34:11commit our files. So this is actually
  7365. 4:34:13where we're going to save save the
  7366. 4:34:15snapshot. And the syntax for this is get
  7367. 4:34:18commit. Then we do dash m and then we
  7368. 4:34:19can leave a comment. So we can we can
  7369. 4:34:22put anything in here. Initial commit
  7370. 4:34:24would be fine. So I'm simply going to
  7371. 4:34:25copy paste this. Come over here. And
  7372. 4:34:27then I'm going to do let me actually
  7373. 4:34:29clear this up. Uh get a fresh slate
  7374. 4:34:32again. And then we do get commit-m
  7375. 4:34:34initial commit. And now you can see look
  7376. 4:34:37we have created all of these snapshots
  7377. 4:34:39in here. All the information is now
  7378. 4:34:41stored. everything that's in here except
  7379. 4:34:43for the files that were in git ignore.
  7380. 4:34:45All right. And now the next thing we
  7381. 4:34:46want to do is rename our branch to main.
  7382. 4:34:49So this is just a naming convention in
  7383. 4:34:51git. So we make sure that we are on the
  7384. 4:34:53main branch. You can see that over here
  7385. 4:34:55in the lower corner right now. And then
  7386. 4:34:57the final thing we want to do is we
  7387. 4:34:59connect GitHub to our local project. So
  7388. 4:35:02if you come over here to GitHub again
  7389. 4:35:04where also all of these uh settings are
  7390. 4:35:07depending on where you do HTTPS uh or
  7391. 4:35:09SSH you can now add your remote. So you
  7392. 4:35:12can also follow just the instructions
  7393. 4:35:14over here. So I'm going to add the
  7394. 4:35:16remote for my it will probably say it's
  7395. 4:35:18already there but for you it will
  7396. 4:35:19connect it and then the final thing that
  7397. 4:35:22we can do is we push it. So get push u
  7398. 4:35:24origin main. Now I know these these are
  7399. 4:35:27a lot of steps right and when you do
  7400. 4:35:29this for the first time let's see if it
  7401. 4:35:30works. There we go. So, we have now
  7402. 4:35:32pushed all of these changes to GitHub.
  7403. 4:35:35So, congratulations. If you followed
  7404. 4:35:37along, if I now uh when I'm here and I
  7405. 4:35:39do a refresh, you can see look, we now
  7406. 4:35:42have our own private project, our
  7407. 4:35:43private repository with all of our
  7408. 4:35:45files. And again, now coming back to
  7409. 4:35:47this, this is a lot, right? So, but
  7410. 4:35:50remember in this section of the course,
  7411. 4:35:52if you if you've been following like
  7412. 4:35:54from the start for GitHub, there were so
  7413. 4:35:56many things like we created account, we
  7414. 4:35:58did the setup to authenticate, we
  7415. 4:36:00created the repository, now we do all of
  7416. 4:36:02these commands. And you might feel like
  7417. 4:36:04Dave, like working with Git, I'll rather
  7418. 4:36:06just duplicate the folder and have a
  7419. 4:36:08backup like that than doing all of this.
  7420. 4:36:09But you don't want to do that. And like
  7421. 4:36:1280% 90% of what we just did is just a
  7422. 4:36:15one-time thing. And I'm actually going
  7423. 4:36:17to show you how easy it is on a
  7424. 4:36:19day-to-day using terminal commands and
  7425. 4:36:22then later in the next step even how
  7426. 4:36:23it's even easier if you just a visual
  7427. 4:36:25UI. But now that everything is set up
  7428. 4:36:28really the 90% of what you'll do with
  7429. 4:36:30git in the beginning is look right now
  7430. 4:36:32over here let's say we have our file
  7431. 4:36:34over here and we say we have the
  7432. 4:36:36analyzer and we make some changes. So we
  7433. 4:36:39for example say I don't know let's let's
  7434. 4:36:42even just put like a small comment in
  7435. 4:36:45here. So we we make a change there and
  7436. 4:36:47we do another print statement to print
  7437. 4:36:50the uh grand total one more time over
  7438. 4:36:53here. So we made some changes to our
  7439. 4:36:56code. We can save it locally in here.
  7440. 4:36:58But now what we can do is now if we can
  7441. 4:37:00come into our terminal we can check
  7442. 4:37:02using a git status to see what the what
  7443. 4:37:05the changes are. So you can see look we
  7444. 4:37:08have we have made some changes to this
  7445. 4:37:10file over here which are not tracked. So
  7446. 4:37:13now what we can do let's say it's you're
  7447. 4:37:15working on a feature and you like want
  7448. 4:37:17to save it right now or it's end of day
  7449. 4:37:19and you just want to save your work
  7450. 4:37:21right now we can do we can just follow
  7451. 4:37:23the process over here. So we can just
  7452. 4:37:25say look we want to do get add we want
  7453. 4:37:27to add everything in between you can
  7454. 4:37:29also always do a get status. So now you
  7455. 4:37:31can see it's green. We stage the
  7456. 4:37:33changes. Now you can do g commit-m
  7457. 4:37:36and then we can say uh made some changes
  7458. 4:37:40and we commit that. And now we do a g
  7459. 4:37:42push and now it will send all of that
  7460. 4:37:45information. And if we come over here
  7461. 4:37:47you can now see that right now you can
  7462. 4:37:50see it's updated right now. And the cool
  7463. 4:37:52thing about git is now that everything
  7464. 4:37:54is tracked because I can now come in
  7465. 4:37:56here and I can see look made some
  7466. 4:37:57changes and I can see exactly what I
  7467. 4:38:01updated to these files. So that's on a
  7468. 4:38:04day-to-day now that you have set it up
  7469. 4:38:06all really that you need to do with git.
  7470. 4:38:08You just work on your project and then
  7471. 4:38:10whenever you want to save things you do
  7472. 4:38:13a simple update. But there is an even
  7473. 4:38:15better way to work with git and that is
  7474. 4:38:17just using the UI in VS code. So this is
  7475. 4:38:20how I always work with Git. It's super
  7476. 4:38:22easy and it's available from this
  7477. 4:38:25section over here. So you can click on
  7478. 4:38:27the little version control icon and let
  7479. 4:38:30me show you what that looks like. So now
  7480. 4:38:32let's say I want to refer to changes. So
  7481. 4:38:34I want to go back to let's say we want
  7482. 4:38:36to read data and we also don't need this
  7483. 4:38:39in here. We made some changes. You can
  7484. 4:38:41see right now here on the left you can
  7485. 4:38:43see one there's one change meaning we
  7486. 4:38:46changed one file. And if I change other
  7487. 4:38:49files as well. So let's say in the
  7488. 4:38:50helper functions uh I do like um let's
  7489. 4:38:54say I put functions here just just to
  7490. 4:38:57make a quick change you'll find that
  7491. 4:38:58look this is now updating to a two. So
  7492. 4:39:01you can now see git will now tell us
  7493. 4:39:03like look you have two changes in here.
  7494. 4:39:06And now one of the cool things that you
  7495. 4:39:08can do right now is uh you you don't
  7496. 4:39:11really have to stage changes in here or
  7497. 4:39:15uh even come up with your own commit
  7498. 4:39:16messages nowadays in Visual Studio Code.
  7499. 4:39:18You can just click on this and then if
  7500. 4:39:20you uh sign up with GitHub Copilot, you
  7501. 4:39:23can even let AI create messages for you.
  7502. 4:39:25So if you want that like let's see, we
  7503. 4:39:27can skip that for now. That's a very
  7504. 4:39:29nice feature to do because what it will
  7505. 4:39:31do is will look at your files. it will
  7506. 4:39:33look at the changes and it will just
  7507. 4:39:34create a descriptive message for you
  7508. 4:39:36because coming up with commit messages
  7509. 4:39:38is probably one of the hardest things to
  7510. 4:39:40do as a developer and this just make the
  7511. 4:39:42whole process easier. So I recommend to
  7512. 4:39:44check out GitHub copilot. But let's uh
  7513. 4:39:46for now say we made some updates. And
  7514. 4:39:49what I can do right now I can simply
  7515. 4:39:52come in here and I can either hit
  7516. 4:39:53commit. So this would be the same as
  7517. 4:39:55running the git commit with the message.
  7518. 4:39:57But I can also click on here and I can
  7519. 4:39:59do commit and push. And if I do it like
  7520. 4:40:01this you can say look there are no stage
  7521. 4:40:04changes. And I can say look I want to do
  7522. 4:40:06this always. So I want to before doing
  7523. 4:40:07this I want to stage all changes. So
  7524. 4:40:10when this is set up now you can see we
  7525. 4:40:14have successfully let's see made another
  7526. 4:40:17commit with the updates and now all you
  7527. 4:40:20really have to do is come in here make
  7528. 4:40:22changes and whenever you uh and whenever
  7529. 4:40:25you want to push them let's see let's
  7530. 4:40:27come over here whenever you want to push
  7531. 4:40:29them so now the function or the comment
  7532. 4:40:31here is is gone whenever you want to
  7533. 4:40:33push them says removed comment come over
  7534. 4:40:36here get push done okay so hopefully Now
  7535. 4:40:40it's a little bit less scary, right? We
  7536. 4:40:42went from a lot of controls to like how
  7537. 4:40:43do we set this up and all kinds of
  7538. 4:40:45commands to now literally giving a
  7539. 4:40:47comment and then clicking on one button
  7540. 4:40:48in order to save our work and make it
  7541. 4:40:51available uh via git. So this is one of
  7542. 4:40:53those things I know we spend uh quite
  7543. 4:40:56some time here on working with git but
  7544. 4:40:58if this the is this is the first time
  7545. 4:41:00that you're working with code the first
  7546. 4:41:02time programming like this look took
  7547. 4:41:04really long for me to actually figure
  7548. 4:41:06out how to do properly because there's
  7549. 4:41:08just so much that you can do if you go
  7550. 4:41:10over to the resource hub uh and actually
  7551. 4:41:12go to the git cheat sheet you can find
  7552. 4:41:14everything that you can do with git
  7553. 4:41:16there's really a lot to it but what I've
  7554. 4:41:19just shown you on a day dayto-day is
  7555. 4:41:21really like the 80 80 90% that you'll uh
  7556. 4:41:25that you have to do. Now there's one
  7557. 4:41:27more quick thing that I uh want to show
  7558. 4:41:29you and that is also you can also very
  7559. 4:41:31easily create GitHub repositories from
  7560. 4:41:35within git. So for example, if I'm here
  7561. 4:41:37in my Python projects folder and I want
  7562. 4:41:38I have a new idea and I want to start a
  7563. 4:41:40new project, I can create a new folder
  7564. 4:41:42here. Let's say I want to build an AI
  7565. 4:41:44agent. So we we create an AI agent
  7566. 4:41:46folder and now what I can do is I can
  7567. 4:41:49open up uh this folder in a terminal. So
  7568. 4:41:51I go to services, new terminal over here
  7569. 4:41:54and then I can do code to open it up or
  7570. 4:41:58just simply drag and drop it in here. So
  7571. 4:41:59now this is a completely empty uh empty
  7572. 4:42:02folder, completely empty repository. But
  7573. 4:42:04what I can do if I come in here I can
  7574. 4:42:07click on here and look I can now say
  7575. 4:42:09look I can initialize a repository. So
  7576. 4:42:12we create an repository and then uh
  7577. 4:42:14let's say I just do a first file in
  7578. 4:42:16here. So let's say we do just do a
  7579. 4:42:18readme.m MD which is going to be uh my
  7580. 4:42:22awesome agent project. Now we save that.
  7581. 4:42:26So you can now see we have a file in
  7582. 4:42:29here. And now what what the nice thing
  7583. 4:42:31is about Visual Studio Code, we can just
  7584. 4:42:32say do like first init. And then I can
  7585. 4:42:36do commit and push. And what it will now
  7586. 4:42:38do, it will say look there is no remote
  7587. 4:42:41in here. Do you want to add a remote?
  7588. 4:42:43And if we actually cancel out of this uh
  7589. 4:42:46just cancel it, it will say publish. Do
  7590. 4:42:48you want to publish the branch? And then
  7591. 4:42:50we say yes. And then we say there is no
  7592. 4:42:52uh GitHub extension. Do you want to sign
  7593. 4:42:53in? So we do yes. Follow uh with this.
  7594. 4:42:56And then let's see, we open it up again.
  7595. 4:42:58So this is also just a one-time sync.
  7596. 4:43:00And now what you can see now we can say
  7597. 4:43:02look do you want to push this to a
  7598. 4:43:04private or to a public repository? Say
  7599. 4:43:06okay, I want this to be a private
  7600. 4:43:08repository. And now we are going to
  7601. 4:43:10create. Now we have everything set up.
  7602. 4:43:13So now we have really like boiled it
  7603. 4:43:15down to we can just open up a folder
  7604. 4:43:17within Visual Studio Code like try to
  7605. 4:43:20make a change save something uh and then
  7606. 4:43:22it it will like essentially error and
  7607. 4:43:24then we can create the project or we can
  7608. 4:43:26also do it from uh from the beginning
  7609. 4:43:28but this is the process. This is how I
  7610. 4:43:29always do it. So whenever I have a new
  7611. 4:43:31project and now we just come in here and
  7612. 4:43:33if I now like uh make changes in here
  7613. 4:43:36say let's start git will now simply like
  7614. 4:43:39kick into action and say look now we
  7615. 4:43:41have changes in here. Uh so we do the
  7616. 4:43:44quick update do commit push and that's
  7617. 4:43:47all there is to it. So now you can see
  7618. 4:43:49it automatically updates. So for now let
  7619. 4:43:53me go in here. You can also manage all
  7620. 4:43:55of your settings. You change your
  7621. 4:43:56visibility and I'm going to actually
  7622. 4:43:58delete this repository. just get out of
  7623. 4:44:00this. Uh so that's also how you can do
  7624. 4:44:02that if you have a project that you
  7625. 4:44:04don't want anymore. Just wrapping this
  7626. 4:44:05up, but I'm just showing you from like a
  7627. 4:44:07more practical point of view how this
  7628. 4:44:09works in the day-to-day because again
  7629. 4:44:11for me in the beginning it was so weird
  7630. 4:44:13like all of these commands that you
  7631. 4:44:15needed to remember. This is really what
  7632. 4:44:16it comes down to. So this section was
  7633. 4:44:18really important. And that wraps up the
  7634. 4:44:20Git and GitHub portion. You now know the
  7635. 4:44:2390% that you need to know to confidently
  7636. 4:44:26follow all of my tutorials and tutorials
  7637. 4:44:28from other people as well. You know how
  7638. 4:44:30to create repositories, what they are.
  7639. 4:44:33You know how to use Visual Studio Code
  7640. 4:44:34and the terminal in order to manage all
  7641. 4:44:36of this. So now let's get into
  7642. 4:44:39environments and secrets. All right. So
  7643. 4:44:41now that you understand how you can work
  7644. 4:44:43with git and how you can also send
  7645. 4:44:45information and store information to
  7646. 4:44:46GitHub, it's important to understand how
  7647. 4:44:49you can keep your own data safe because
  7648. 4:44:52when you are working on serious
  7649. 4:44:54applications, there are always going to
  7650. 4:44:55be credentials in the form of API keys,
  7651. 4:44:58passwords, and connection strings for
  7652. 4:44:59example to a database. And from a uh
  7653. 4:45:02security perspective, you want to keep
  7654. 4:45:04this as private as possible because for
  7655. 4:45:06some applications with just a single API
  7656. 4:45:09key, someone can have like full access
  7657. 4:45:12to a system. It can pull all your
  7658. 4:45:14customer information. It can send
  7659. 4:45:16messages to customers. For example, if
  7660. 4:45:18you have an API key for a CRM system. So
  7661. 4:45:21you want to be really careful with that
  7662. 4:45:23and you don't want to push that to your
  7663. 4:45:25version control. So you don't want to
  7664. 4:45:27have that in in GitHub really or in git.
  7665. 4:45:30you don't but you just want it to be
  7666. 4:45:31locally only where the application needs
  7667. 4:45:34it. So this is something you'll
  7668. 4:45:36literally find in almost all of my
  7669. 4:45:38tutorials when we are working with AI
  7670. 4:45:40models like OpenAI or Entropic and we
  7671. 4:45:43need the need the API keys. So in order
  7672. 4:45:46to um have a workaround so that we can
  7673. 4:45:49use these these files without pushing
  7674. 4:45:52them to our version control let's
  7675. 4:45:54understand environment variables and
  7676. 4:45:56then the env file in Python and how we
  7677. 4:45:58use them. So let's start with the
  7678. 4:46:00environment variables. So environment
  7679. 4:46:03variables are stored outside of your
  7680. 4:46:05code. So you can think of these as a
  7681. 4:46:07configuration that your program can
  7682. 4:46:09read. So let's say you have an API key
  7683. 4:46:11or a database. We don't really want to
  7684. 4:46:14hardcode that within our file. So let's
  7685. 4:46:17say for example, let's come over here.
  7686. 4:46:19We don't want to do this. So let's say
  7687. 4:46:21let's come over here. We do get our
  7688. 4:46:23data. Uh we don't want let's say this uh
  7689. 4:46:26this this API would need an API key. We
  7690. 4:46:29don't want to do this because right now
  7691. 4:46:31anyone that would have access to this
  7692. 4:46:34file could simply like take this extract
  7693. 4:46:37it and then use it in their own files in
  7694. 4:46:39order to access your system. So this is
  7695. 4:46:42hard coding private or secret
  7696. 4:46:44information. We don't want that. We
  7697. 4:46:46don't want this showing up in our Python
  7698. 4:46:48files. So we want to store them in
  7699. 4:46:50environment variables. And how they are
  7700. 4:46:53how they work behind the scenes is they
  7701. 4:46:56live in your system, not in your code.
  7702. 4:46:58And we can use the OS library in order
  7703. 4:47:01to safely read the API key from our
  7704. 4:47:04environment. So it's only within the
  7705. 4:47:06environment that we need it. And we use
  7706. 4:47:08that by with the following syntax. So we
  7707. 4:47:10import the OS library and then we say
  7708. 4:47:12osenvironment.get
  7709. 4:47:14and then we do for example API key and
  7710. 4:47:16then we can print it. But before we can
  7711. 4:47:19do that, we first need to uh set up the
  7712. 4:47:22environment variables. So let's show how
  7713. 4:47:25this works. So let's see. We can come in
  7714. 4:47:28here. Let's go to our hello.py file.
  7715. 4:47:31This is currently empty. If we come in
  7716. 4:47:33here and let's say I come over here and
  7717. 4:47:35just import this. We can now see look we
  7718. 4:47:38have an API key and we have a database
  7719. 4:47:40and that is the API key, database name.
  7720. 4:47:42We can even set default values. If I now
  7721. 4:47:45run this, what you'll find is that
  7722. 4:47:47database will have a default value of
  7723. 4:47:49DB. But if we go to the API key, it is
  7724. 4:47:52going to say look this is none. There is
  7725. 4:47:55no API key because it is not set.
  7726. 4:47:58Similar if we let's say we remove the
  7727. 4:48:00default value in here and we say again
  7728. 4:48:04the database same thing it will say look
  7729. 4:48:07there is no uh there is no database
  7730. 4:48:09connection key over here. So how do we
  7731. 4:48:12then set that? Well we can do that
  7732. 4:48:15coming over here using an export
  7733. 4:48:18statement. So if we come over here and
  7734. 4:48:22we export this in the terminal session.
  7735. 4:48:25So coming over here to our our project,
  7736. 4:48:28we can actually open this up and then
  7737. 4:48:32set this and we can export it. So we've
  7738. 4:48:34now exported the API key. So this is now
  7739. 4:48:36available within our system. But let's
  7740. 4:48:38have a look at if we now change this to
  7741. 4:48:41API key and we run this file. So we do
  7742. 4:48:45run the Python file. We run it over
  7743. 4:48:47here. You'll still see that it prints
  7744. 4:48:49none over here and the API key is not
  7745. 4:48:52available and similar if we do that over
  7746. 4:48:54here and just for the print statement.
  7747. 4:48:56So no API key also not here. But now if
  7748. 4:48:59I do the export one more time. So I
  7749. 4:49:02export it here in the terminal session
  7750. 4:49:04and I use that same session to run this
  7751. 4:49:06Python file one more time. Now you can
  7752. 4:49:08see that it correctly has access to the
  7753. 4:49:12API key in here. Let me actually save
  7754. 4:49:14that. So now if you save that it should
  7755. 4:49:16also uh print. So now it should also
  7756. 4:49:18print the API key. So you can see that
  7757. 4:49:21through this we can actually make
  7758. 4:49:23information available within our
  7759. 4:49:26terminal session in our system and then
  7760. 4:49:28our Python files can use this. But you
  7761. 4:49:30can see this is a little bit cumbersome
  7762. 4:49:32because now if I like X out of this and
  7763. 4:49:35remove this it's now it's not available
  7764. 4:49:37within the interactive session. And if I
  7765. 4:49:40start a new fresh terminal in here, you
  7766. 4:49:43still find that it prints none because
  7767. 4:49:45now we would have to export it one more
  7768. 4:49:47time. So we export it one more time and
  7769. 4:49:50then it's available. So now if we
  7770. 4:49:51continue to work in here, it's
  7771. 4:49:53accessible. So this is fundamentally how
  7772. 4:49:56it works and how we can make it
  7773. 4:49:57available. But there is a much better
  7774. 4:49:59way to to do this in a much more
  7775. 4:50:01effective way that like takes care of
  7776. 4:50:03this process. We need to set it up once
  7777. 4:50:05and then never have to worry about it
  7778. 4:50:07ever again. And that is through using
  7779. 4:50:09the env file and environment variables.
  7780. 4:50:12So you you'll notice that I follow a
  7781. 4:50:14simil similar uh approach over here as
  7782. 4:50:16to git and github. I first show you kind
  7783. 4:50:18of like the more complex way how it
  7784. 4:50:20works under the hood and then I'm going
  7785. 4:50:22to show you the the simple way that
  7786. 4:50:24makes it really easy to do this. So
  7787. 4:50:27instead of doing the exports all the
  7788. 4:50:29time, what is very common in Python is
  7789. 4:50:32to use files. So what we can do is if we
  7790. 4:50:35come over to our project I can do new
  7791. 4:50:37file I I can do env and you'll find that
  7792. 4:50:40in the git ignore file that we created
  7793. 4:50:43the env file is also already excluded
  7794. 4:50:46out of here. So uh this will not be
  7795. 4:50:48tracked in version control. So you can
  7796. 4:50:50see that even though I added the file it
  7797. 4:50:52only says look only the only changes we
  7798. 4:50:55have is to hello.py Pi and if I create
  7799. 4:50:58for example an env let's say txt file
  7800. 4:51:02and I come over here you'll find that
  7801. 4:51:04this is tracked. So now if I push this
  7802. 4:51:07it will be added to to GitHub which is
  7803. 4:51:10not the case for the file because it's
  7804. 4:51:12in the git ignore. So what we can now do
  7805. 4:51:15over here is we can come in here and
  7806. 4:51:17this is a place where we can now store
  7807. 4:51:19secret information. So all of the stuff
  7808. 4:51:22that we don't want to include in our
  7809. 4:51:23version control which can be things like
  7810. 4:51:25let's see like API keys database URLs
  7811. 4:51:27app settings file paths all stuff that
  7812. 4:51:30we can dump in here. So now what we can
  7813. 4:51:33do let's take this over here this line
  7814. 4:51:36plug that in. So we create our env file
  7815. 4:51:39and now we can use a Python library
  7816. 4:51:42python. M which we can pip install to
  7817. 4:51:45safely load this information. So what I
  7818. 4:51:47can do right now pip install and coming
  7819. 4:51:50back to let's say let's get to hello.py.
  7820. 4:51:53So remember right how do we install
  7821. 4:51:54packages we go to terminal we open up a
  7822. 4:51:56terminal or we do a new terminal and
  7823. 4:51:58then make sure our virtual environment
  7824. 4:52:00is selected which should already
  7825. 4:52:02automatically applied. If you have any
  7826. 4:52:04errors make sure that is selected over
  7827. 4:52:07here and then we can do a pip install.
  7828. 4:52:10So let me actually show you what happens
  7829. 4:52:11if you don't install it correctly. So
  7830. 4:52:12it's going to be from.f
  7831. 4:52:14import load.nf.
  7832. 4:52:18So if I now try to run this, it will
  7833. 4:52:21tell me look there is no module. And the
  7834. 4:52:24way you install this is by doing pip
  7835. 4:52:26install python.n. So now it's installed.
  7836. 4:52:29And now if I run this, we should find
  7837. 4:52:32that we now get the green check mark and
  7838. 4:52:34we can import it. Okay. So what we can
  7839. 4:52:36then do is let's see we can now use this
  7840. 4:52:41simple uh function over here that we
  7841. 4:52:43import from the module and this is going
  7842. 4:52:46to load our env file and it will
  7843. 4:52:48automatically try to find it. So let's
  7844. 4:52:50see what that looks like if we do that
  7845. 4:52:52over here. You can see it says true if
  7846. 4:52:56it cannot find the env file. So for
  7847. 4:52:58example, if I put this in here and move
  7848. 4:53:01this and I do this one more time, it
  7849. 4:53:02will probably say that it cannot find it
  7850. 4:53:05in here. Look, it says false. So this
  7851. 4:53:08has some capabilities behind it where it
  7852. 4:53:10will automatically look in the current
  7853. 4:53:12folder and it will also it's some
  7854. 4:53:14sometimes it's a little bit annoying.
  7855. 4:53:16Sometimes I feel like it works also in
  7856. 4:53:18uh folders above, but sometimes it can
  7857. 4:53:19also get confused. So uh sometimes you
  7858. 4:53:22have to specifically select the path but
  7859. 4:53:24out of the box when it's in the same
  7860. 4:53:26folder over here in the root of your
  7861. 4:53:28project it generally tends to work but
  7862. 4:53:31this is a check that you need to be
  7863. 4:53:32aware of you can also do it explicitly
  7864. 4:53:35right so if I let's say I have another
  7865. 4:53:36folder and I'm just showing this because
  7866. 4:53:38this is stuff that you can encounter in
  7867. 4:53:39the real world and for example you want
  7868. 4:53:41to have your env file here if I now run
  7869. 4:53:44this it will say false and then what I
  7870. 4:53:47can do is I can specify the path so I
  7871. 4:53:49can say look it's in folder and then
  7872. 4:53:51forward slash env. And now you can load
  7873. 4:53:55it. So if you ever run into an issue
  7874. 4:53:57where it cannot find it, just point to
  7875. 4:53:59it specifically. And this just works the
  7876. 4:54:02same way that we learned with the path,
  7877. 4:54:04right? So you can also go up. So let's
  7878. 4:54:06say you were in some folder and you need
  7879. 4:54:07to go up one level. This is how it
  7880. 4:54:10works. So generally you want to keep
  7881. 4:54:12that at the root of the project. Let's
  7882. 4:54:14move that over here. And now from within
  7883. 4:54:16this hello.py Pi file we can simply run
  7884. 4:54:20this. So what it is now doing behind the
  7885. 4:54:23scenes now it is loading these variables
  7886. 4:54:27that we have in here this secret
  7887. 4:54:28information into our session and we can
  7888. 4:54:30now use the OS library to retrieve
  7889. 4:54:33those. So now if I look at this you can
  7890. 4:54:35see look we can now access our API keys
  7891. 4:54:38and now it works regardless of whether I
  7892. 4:54:41am using the interactive session or the
  7893. 4:54:43terminal. So let's see I think the
  7894. 4:54:44database we need to database let's do
  7895. 4:54:46database let's actually change this to
  7896. 4:54:49database URL because it is a URL in this
  7897. 4:54:51case and now we can simply say look we
  7898. 4:54:54have the database using database and
  7899. 4:54:58then database. So now I can run this and
  7900. 4:55:01it will load the API key it will load
  7901. 4:55:03the database and if I run this in here
  7902. 4:55:06you can also see that also through the
  7903. 4:55:08terminal you will get the correct
  7904. 4:55:10information. So, this is the
  7905. 4:55:12introduction to working with
  7906. 4:55:14environments and secrets. It's a little
  7907. 4:55:16hack that you need to know, a little
  7908. 4:55:17trick that you'll see in almost any AI
  7909. 4:55:20video where they're using the Open SDK
  7910. 4:55:23because you need an API key. And this is
  7911. 4:55:25how you do it. You don't want to
  7912. 4:55:26hardcode that. Make sure you create an
  7913. 4:55:28ENV file. You have the right git ignore
  7914. 4:55:30file and then you plug in your API key
  7915. 4:55:33in here. And then in your file, you just
  7916. 4:55:35import the load. Mf library. Make sure
  7917. 4:55:37it's installed via pip. you call the
  7918. 4:55:40load.n function and now you can use the
  7919. 4:55:43OS library to retrieve it from your
  7920. 4:55:45system. Now next up in the Python tools
  7921. 4:55:48section I want to introduce you to rough
  7922. 4:55:51which is a really cool tool that we can
  7923. 4:55:53use to format and lint our code. So this
  7924. 4:55:56is going to make making writing pretty
  7925. 4:55:59code and adhering to certain standards
  7926. 4:56:01and style guidelines super easy and
  7927. 4:56:04convenient. So with Rough you'll get
  7928. 4:56:06three tools in one which I will show you
  7929. 4:56:08right now. that is linting, formatting
  7930. 4:56:10and import sorting. So let's go through
  7931. 4:56:12this. First we have to do a quick setup.
  7932. 4:56:15So we can actually install it in visual
  7933. 4:56:17studio code and what we can do is we can
  7934. 4:56:19go to the extensions one more time
  7935. 4:56:21remember. So go over here extensions. We
  7936. 4:56:24can search for rough. So in here it will
  7937. 4:56:27be this one from Astral. You can click
  7938. 4:56:29here on install. So I I'm also going to
  7939. 4:56:31do a fresh install in here. So that
  7940. 4:56:33takes a couple of seconds. Okay. Now it
  7941. 4:56:36is installed. Let's see. Come back over
  7942. 4:56:38here. So that's the installation. Super
  7943. 4:56:40simple. And now what we can do is we can
  7944. 4:56:42enable formatting on save. And this lets
  7945. 4:56:45FS code automatically format your code
  7946. 4:56:46when you save it. So this is available
  7947. 4:56:48from the settings. So we can open it up
  7948. 4:56:51and then search for format on save. So
  7949. 4:56:54you can either go to the gear icon over
  7950. 4:56:56here, go to settings or do command or
  7951. 4:56:58control and then a comma which will open
  7952. 4:57:01it up. And I will search for format on
  7953. 4:57:02safe. And then you want to check this
  7954. 4:57:04box over here. And then the next thing
  7955. 4:57:06you want to search for is the default
  7956. 4:57:08formatterater. And we're going to set
  7957. 4:57:09that to rough. So here you find default
  7958. 4:57:11formatterater. You'll find a list and
  7959. 4:57:13rough should be in here if you installed
  7960. 4:57:15the extension. So we'll plug that in
  7961. 4:57:18there as well. And now you've
  7962. 4:57:19successfully installed and configured
  7963. 4:57:21rough. So now let's see it in action. So
  7964. 4:57:24what does formatting mean? Well, in the
  7965. 4:57:25beginning we talked about syntax, right?
  7966. 4:57:28So spec there are certain rules in
  7967. 4:57:30Python that you just need to follow
  7968. 4:57:31otherwise you'll run into errors. But
  7969. 4:57:34there are also style guidelines. And
  7970. 4:57:36remember how I talked about the PEP 8
  7971. 4:57:37style guidelines, right? Rough is a tool
  7972. 4:57:39that can help us to adhere to these
  7973. 4:57:42style guidelines. So if I have this
  7974. 4:57:44messy code over here, you can follow
  7975. 4:57:46along by simply copy and pasting this.
  7976. 4:57:48Like we know right now this doesn't look
  7977. 4:57:50good, right? There are too many spaces
  7978. 4:57:52in here. There should be a white line in
  7979. 4:57:55here. Here we have a bunch of here we
  7980. 4:57:58have a dictionary where it's pretty hard
  7981. 4:58:00to read what's in here. So we can
  7982. 4:58:02improve that. and even the spacing in
  7983. 4:58:04between. So, let's take a look at this.
  7984. 4:58:05Now, if I come over here to our editor,
  7985. 4:58:08I plug it in. You'll find that this is
  7986. 4:58:10now a little bit messy, but watch what
  7987. 4:58:12happens when I do command save.
  7988. 4:58:15That's cool, right? The first time that
  7989. 4:58:17I saw that was like, oh, this is so
  7990. 4:58:19awesome. So, now you can just go about
  7991. 4:58:21writing your writing your code and then
  7992. 4:58:24whenever So, let me see. So whenever you
  7993. 4:58:26like make a mistake, you don't add
  7994. 4:58:28whites space, you don't add a space or
  7995. 4:58:30the indentation or anything that is
  7996. 4:58:32weird that is not a syntax error, boom,
  7997. 4:58:34rough will fix that. So that's the auto
  7998. 4:58:37formatting. And you'll find that if you
  7999. 4:58:40use this, all the files that you are
  8000. 4:58:42working with will have a similar setup
  8001. 4:58:44and your code becomes very readable
  8002. 4:58:46because it will also take care of line
  8003. 4:58:48length. will make sure that when you
  8004. 4:58:50have a list with dictionary items in
  8005. 4:58:52here for example that it places nice and
  8006. 4:58:54neatly on new lines. We can even go as
  8007. 4:58:56far and adding adding a comma over here
  8008. 4:58:59and then what it will do it will even
  8009. 4:59:01split that and make it even more split
  8010. 4:59:03up into more new lines. So these are all
  8011. 4:59:05things that you can play with and we
  8012. 4:59:07never have to think or worry about the
  8013. 4:59:09formatting ever again. So let's see
  8014. 4:59:11formatting and that's the most obvious
  8015. 4:59:12one and also the most convenient one.
  8016. 4:59:14But let's have a look at linting and
  8017. 4:59:16import sorting. So linting is finding
  8018. 4:59:18issues and potential errors. So these
  8019. 4:59:21are the yellow squiggly lines that you
  8020. 4:59:23sometimes see that our editor already
  8021. 4:59:24gave through pylons. But rough takes
  8022. 4:59:27this a step further. So if I now for
  8023. 4:59:29example come in here, you can see that
  8024. 4:59:31we have these yellow lines over here
  8025. 4:59:33under OS. And if I scroll on that, for
  8026. 4:59:36example, you can see pilance is giving
  8027. 4:59:39an error or giving a suggestion over
  8028. 4:59:41here. But then rough is also saying look
  8029. 4:59:43we have an uh we have OS but it's
  8030. 4:59:45imported but we don't use it. So these
  8031. 4:59:48are little hints where it doesn't break
  8032. 4:59:50your code but it's overall much cleaner
  8033. 4:59:52if we get rid of this. So now one of the
  8034. 4:59:55cool things that you can do with rough
  8035. 4:59:56is we can form auto correction. So we
  8036. 4:59:59can do this through the command pallet
  8037. 5:00:00and that is command shiftp or control
  8038. 5:00:02shiftp if you're on windows. You can
  8039. 5:00:04type in rough and you'll find that there
  8040. 5:00:06are a couple of actions that you can
  8041. 5:00:08select from here. So one is for example
  8042. 5:00:10fix all autofixable problems. So if I
  8043. 5:00:12click on this you'll find that it
  8044. 5:00:14automatically gets rid of the import OS
  8045. 5:00:17that was in there and now we have
  8046. 5:00:18cleaned up our Python file in just two
  8047. 5:00:21actions. We save it and we also try to
  8048. 5:00:23fix all autofixable problems. Now
  8049. 5:00:26there's one more thing and that is
  8050. 5:00:27import sorting and this is just if you
  8051. 5:00:29like want to really be nice and neat
  8052. 5:00:31when you're working on your Python
  8053. 5:00:32projects. So if I come over here let's
  8054. 5:00:34see if there's an example in here where
  8055. 5:00:36we have some imports. So you can see the
  8056. 5:00:38helper. Let's see. Let's actually get
  8057. 5:00:41into the get data. Yes, over here. Here
  8058. 5:00:43we have a bunch of imports. If I open up
  8059. 5:00:45the command pallet one more time,
  8060. 5:00:46control shiftp or command shift P and I
  8061. 5:00:49do rough. I can also do format imports.
  8062. 5:00:52And what you'll find over here is it
  8063. 5:00:54will it will format the imports in a
  8064. 5:00:56very specific way. And this will just
  8065. 5:00:58help to make all of your code and all
  8066. 5:00:59your imports very similar so that
  8067. 5:01:01whatever file you open there is a
  8068. 5:01:03similar structure and everything reads
  8069. 5:01:05very similar. So that's what Rough can
  8070. 5:01:06do and I absolutely love it. Linting,
  8071. 5:01:08formatting, and import sorting. All
  8072. 5:01:10right. And my final gift to you in this
  8073. 5:01:13full Python beginner course is a tool
  8074. 5:01:16called UV. And this is a more modern way
  8075. 5:01:19to to work with Python and to manage
  8076. 5:01:21your packages and environments. And it's
  8077. 5:01:23a super awesome tool. And all the top
  8078. 5:01:25developers and top teams are adapting
  8079. 5:01:27it. So I really want you to learn it as
  8080. 5:01:29well. And I wanted to start with the
  8081. 5:01:32fundamentals, right? Because as a Python
  8082. 5:01:34developer, you need to understand what
  8083. 5:01:36pip is. You need to know how to work
  8084. 5:01:37with the requirements.t txt. You need to
  8085. 5:01:39know how to manage virtual environments.
  8086. 5:01:42But UI can do all of that and you can do
  8087. 5:01:45it much faster with just a few simple
  8088. 5:01:48commands. So, I won't go into all of the
  8089. 5:01:50details as to why it's so awesome. You
  8090. 5:01:52can read more about this, what it does,
  8091. 5:01:55but I'm just I'm just going to show you.
  8092. 5:01:56And if you want to learn more, they I
  8093. 5:01:58even have an entire video on Yui on my
  8094. 5:02:00channel. And you can also in the
  8095. 5:02:02handbook check why it's so awesome and
  8096. 5:02:05what you can do with it. But let me
  8097. 5:02:07scroll down. I'm going to go to
  8098. 5:02:09installing UVI. So this is what I want
  8099. 5:02:11you to do right now. So on Mac or Linux,
  8100. 5:02:14you can use a curl command and you can
  8101. 5:02:16actually open this up in a terminal. So
  8102. 5:02:18you can copy this and then uh create
  8103. 5:02:20open up a terminal session and just plug
  8104. 5:02:23that in and run it. And on Windows you
  8105. 5:02:26can do it via the PowerShell. So after
  8106. 5:02:29uh instart restart your terminal and now
  8107. 5:02:31here's what you can do with UV. So first
  8108. 5:02:35of all it can help you to go all the way
  8109. 5:02:38from starting a project to creating
  8110. 5:02:40environments to managing packages and to
  8111. 5:02:43even managing versions of Python and
  8112. 5:02:45running scripts. So let me show you uh
  8113. 5:02:48if you have UV now installed and let's
  8114. 5:02:51see let me open up another terminal. you
  8115. 5:02:54know, you can check if it's installed
  8116. 5:02:55correctly by simply doing UV and then it
  8117. 5:02:58should not give you an error, but it
  8118. 5:02:59should give you all of the things that
  8119. 5:03:01you can do with it. If you go, let's
  8120. 5:03:03see, UV Python, you can also just go to
  8121. 5:03:07the official website. So, they have a
  8122. 5:03:09whole bunch of documentation that you
  8123. 5:03:11can go through as well. But as with
  8124. 5:03:13everything in this course, I'm going to
  8125. 5:03:15show you the only thing that you need to
  8126. 5:03:16only things that you need to know right
  8127. 5:03:17now. So all the way back to the
  8128. 5:03:20beginning. If we go to our project
  8129. 5:03:23again, project folder and let's say I
  8130. 5:03:26want to start a new project. I can even
  8131. 5:03:28do that with UI and it's also going to
  8132. 5:03:30allow me to set up a some boilerplate
  8133. 5:03:33that I can use. So I don't have to
  8134. 5:03:35create the same files over and over
  8135. 5:03:36again. So let me show you how to do it.
  8136. 5:03:38I can come in here and then I can go new
  8137. 5:03:41terminal at folder. Again, you can do
  8138. 5:03:43this on Windows and on Mac. And I can do
  8139. 5:03:46UV in it as a starting point. And then
  8140. 5:03:48say, let's say my new project. And what
  8141. 5:03:52you'll find is now it will create this
  8142. 5:03:53project. And in here, there is already a
  8143. 5:03:55bunch of information, already a bunch of
  8144. 5:03:57files. So now what I can do, I can do cd
  8145. 5:03:59into my project. So now we're in this
  8146. 5:04:01folder. And then I can open up, I do
  8147. 5:04:04code, and I do dot. So now I open up
  8148. 5:04:07this project in here. I say I trust it.
  8149. 5:04:10And now you can see that out of the box
  8150. 5:04:12we already have a bunch of files in
  8151. 5:04:14here. So we have a git ignore file which
  8152. 5:04:16is very minimal. I still recommend using
  8153. 5:04:18the one that I shared from the resource
  8154. 5:04:19hub. It puts a python version in here.
  8155. 5:04:21You have a simple main.py file uh that
  8156. 5:04:24you can use to start working in. We have
  8157. 5:04:26a piprotoml in here. And we have a
  8158. 5:04:28readme file. And this piprotoml file is
  8159. 5:04:32is a really interesting file. And next
  8160. 5:04:35uh before I showed you how you can use a
  8161. 5:04:37requirements.txt, txt right where you
  8162. 5:04:39can keep track of everything that you
  8163. 5:04:41installed. So if you go over here to the
  8164. 5:04:42getting started was the packages and pip
  8165. 5:04:45scrolling all the way down. So we went
  8166. 5:04:47through a look we can have a
  8167. 5:04:49requirements.txt or an environment and
  8168. 5:04:51then we can do a pip freeze and it will
  8169. 5:04:53create a snapshot like this and then we
  8170. 5:04:56can install that. Now the tricky thing
  8171. 5:04:58is that every time you install something
  8172. 5:04:59you manually have to make sure to freeze
  8173. 5:05:02it and pip freezes also it adds
  8174. 5:05:06everything in all the packages and also
  8175. 5:05:08all of the dependencies. So it can
  8176. 5:05:09quickly get messy. This is something
  8177. 5:05:10that has always annoyed me about using
  8178. 5:05:13pip and working with Python. But let's
  8179. 5:05:15have a look at how UV handles this. So
  8180. 5:05:18if I come in here and I scroll all the
  8181. 5:05:20way down to okay, we have it installed.
  8182. 5:05:22We're now inside our project. What we
  8183. 5:05:25can now do I can now simply come in here
  8184. 5:05:28and let's say I am working on this
  8185. 5:05:30project and I want to add pandas and I
  8186. 5:05:33want to add numpy. I can do uv at I can
  8187. 5:05:36do pandas I can do numpy and what it
  8188. 5:05:39will do look at what's going on behind
  8189. 5:05:41the scenes. It's first going to install
  8190. 5:05:44everything and it's automatically
  8191. 5:05:46creating a virtual environment and it's
  8192. 5:05:48storing it in the dependencies here as
  8193. 5:05:50well just with one simple command and
  8194. 5:05:52super fast. So now we took care of
  8195. 5:05:55virtual environments of dependencies and
  8196. 5:05:59whenever I want to remove something I
  8197. 5:06:01can do u remove pandas and you can see
  8198. 5:06:04pandas is now gone and I can add it one
  8199. 5:06:06more time uv pandas and it's there again
  8200. 5:06:09and now within here I can simply come in
  8201. 5:06:12here and I can now run this file and it
  8202. 5:06:14will now use the virtual environment
  8203. 5:06:17that is created in here called my new
  8204. 5:06:19project or I should select that. So
  8205. 5:06:21that's one thing you should make sure
  8206. 5:06:22make sure you select it and now we can
  8207. 5:06:24use this in here. So now I can come in
  8208. 5:06:26here and I can import pandas and this
  8209. 5:06:29will now run totally fine. This will not
  8210. 5:06:32give an error. Now if you try this in
  8211. 5:06:33the interactive session it will give an
  8212. 5:06:35error because it will say look we need
  8213. 5:06:37to install the kernel. So that's
  8214. 5:06:39something that you remember right? We
  8215. 5:06:41also need to add yui at ipi kernel. This
  8216. 5:06:45is something you always want to have in
  8217. 5:06:48your project whenever you want to use
  8218. 5:06:49the interactive session. But it's super
  8219. 5:06:51easy to manage and everything is taken
  8220. 5:06:53care of. Now, one of the other awesome
  8221. 5:06:56features of UV is is let's say you add
  8222. 5:07:00this to uh a GitHub repository. So, you
  8223. 5:07:02push this and someone else wants to work
  8224. 5:07:04on this. So, let's say they clone this
  8225. 5:07:06as a fresh repository. We remove this
  8226. 5:07:09and they open up this project completely
  8227. 5:07:12from scratch. UV even even has a
  8228. 5:07:14command. It's called UV sync to come in
  8229. 5:07:17here do UV sync and it will look into
  8230. 5:07:20the project and it will just like
  8231. 5:07:21instantly create everything that's
  8232. 5:07:23needed in order to run over here. So now
  8233. 5:07:26we come back to Python, we can select
  8234. 5:07:28our project and we're good to go again.
  8235. 5:07:31So this is really why you should use UV
  8236. 5:07:34and why it is so awesome. So there's a
  8237. 5:07:37lot more that you can do with it but at
  8238. 5:07:39the most fun fundamental level is you
  8239. 5:07:42can create a project with it. You can
  8240. 5:07:44then use it to uh manage your project
  8241. 5:07:47with the pi project autotoml file and on
  8242. 5:07:49a day-to-day basis this is all you have
  8243. 5:07:51to do. You add packages and you remove
  8244. 5:07:53packages. That's really all that there
  8245. 5:07:55is to it. And you can completely forget
  8246. 5:07:57about pip. You can completely forget
  8247. 5:07:59about like how to set up uh virtual
  8248. 5:08:01environments. Everything will be managed
  8249. 5:08:03in here. So that's why I love using UV
  8250. 5:08:06and why a lot of Python developers are
  8251. 5:08:08adopting this. So as you go through
  8252. 5:08:10tutorials online also from like the big
  8253. 5:08:12firms from OpenAI and Tropic. If you
  8254. 5:08:14look into their tutorials there, they're
  8255. 5:08:16also using UV to like run code and to
  8256. 5:08:18add packages. So that was the
  8257. 5:08:20introduction to UV. And like I've said,
  8258. 5:08:22there is actually a lot more that you
  8259. 5:08:24can learn about it if you go to the
  8260. 5:08:26official documentation, but this is what
  8261. 5:08:28you need to know for now. And then if we
  8262. 5:08:30zoom out a little bit again, right, and
  8263. 5:08:33look at uh all the tools that we've
  8264. 5:08:35learned to use right now, Git and
  8265. 5:08:36GitHub, working with secrets and uh
  8266. 5:08:38within your environment and then also
  8267. 5:08:40using UV in a very short period of time,
  8268. 5:08:43we have covered so much information that
  8269. 5:08:46right now it may feel a little
  8270. 5:08:48overwhelming. Um meaning that as you go
  8271. 5:08:51through as as you go through this with
  8272. 5:08:53me step by step, you can follow along.
  8273. 5:08:55But then if you zoom out and like try to
  8274. 5:08:57understand the bigger picture, you might
  8275. 5:08:59be like, "Oh, it still feels like I need
  8276. 5:09:01to understand how to connect the dots."
  8277. 5:09:03And that's why I created this final uh
  8278. 5:09:06page over here which is a complete
  8279. 5:09:08workflow. And I want you to go through
  8280. 5:09:10this right now as an exercise because
  8281. 5:09:13let's see there's step one all the way
  8282. 5:09:14to let me scroll down all the way to the
  8283. 5:09:18final tips and strategies in there and
  8284. 5:09:21step nine to create a new project to
  8285. 5:09:25install the packages to manage your
  8286. 5:09:26virtual environment and to get it to a
  8287. 5:09:28GitHub repository. Everything is
  8288. 5:09:30explained and repeated one more time and
  8289. 5:09:33this will really bring everything
  8290. 5:09:35together. Also knowing that if you can
  8291. 5:09:37follow this step-by-step page here and
  8292. 5:09:39you successfully do this once, you can
  8293. 5:09:41literally always come back to this page
  8294. 5:09:44and follow it one more time to create
  8295. 5:09:46your new project. And the the setup in
  8296. 5:09:49the beginning is the most annoying part.
  8297. 5:09:51Once you have it set up and you have the
  8298. 5:09:54Visual Studio Code workspace file, so
  8299. 5:09:56you just save save the workspace file.
  8300. 5:09:59Once you have that, it's literally as
  8301. 5:10:01easy as double clicking the file. You
  8302. 5:10:02can go and you just need to push your
  8303. 5:10:04changes to GitHub. But I know like so
  8304. 5:10:06well in the beginning if you don't
  8305. 5:10:08understand this you always feel like you
  8306. 5:10:12have to you have you you're missing lots
  8307. 5:10:14of pieces that connect the dots whenever
  8308. 5:10:16you're following a tutorial online. So
  8309. 5:10:18you'll see someone writing out a Python
  8310. 5:10:21snippet. You understand what it is but
  8311. 5:10:23then you cannot like translate that to
  8312. 5:10:25wait but I'm working on my own project.
  8313. 5:10:27Where do I put this? How do I open that?
  8314. 5:10:29How do we manage that? What is GitHub?
  8315. 5:10:31And this is really really what I wish I
  8316. 5:10:34learned in the beginning because what
  8317. 5:10:35you see right here, the tools, this
  8318. 5:10:37setup, this complete workflow, this is
  8319. 5:10:39the exact process that we use for our
  8320. 5:10:42agency for literally all of our clients
  8321. 5:10:44and these are typically like five figure
  8322. 5:10:46deals. So these come in, clients ask us,
  8323. 5:10:48hey Dave, can you build us this AI
  8324. 5:10:51automation? Can you integrate with our
  8325. 5:10:52CRM and automate our customer support?
  8326. 5:10:54This is the starting point and a lot of
  8327. 5:10:56tutorials and courses on YouTube don't
  8328. 5:10:59show you that because they are just
  8329. 5:11:01working on toy projects and just doing
  8330. 5:11:03it for to create a quick and easy
  8331. 5:11:05tutorial. But I really wanted to give
  8332. 5:11:07you the full playbook to see what it's
  8333. 5:11:09like when you work with Python in the
  8334. 5:11:11real world when you're working on
  8335. 5:11:13serious projects. Congratulations. You
  8336. 5:11:15made it to the end of this course. I
  8337. 5:11:17know this was a big one and really this
  8338. 5:11:20is how I'm feeling for you right now and
  8339. 5:11:22I hope you share that feeling. So let's
  8340. 5:11:24quickly go over what we've learned and
  8341. 5:11:26then let's wrap up this course and show
  8342. 5:11:28you how you can continue your learning
  8343. 5:11:30path and learn all about building AI
  8344. 5:11:32agents. So when you started this course
  8345. 5:11:35you were new to Python, maybe even new
  8346. 5:11:38to programming overall and by now you
  8347. 5:11:41know how to install the Python
  8348. 5:11:43programming language, how to work with
  8349. 5:11:44variables, data types, control flow. We
  8350. 5:11:46looked at organizing your code with
  8351. 5:11:48functions and data structures. Then you
  8352. 5:11:51uh understand right now how to set up
  8353. 5:11:53Python environments and manage
  8354. 5:11:54dependencies. We first saw that how we
  8355. 5:11:56can do that with pip and vans but then
  8356. 5:11:58later I showed you how to do it with UV.
  8357. 5:12:00You know how to use git, GitHub and the
  8358. 5:12:02professional developer tools. And you
  8359. 5:12:04can also connect to APIs, handle errors
  8360. 5:12:06and work with files. You are now no
  8361. 5:12:09longer a beginner. You now have the
  8362. 5:12:11skills to really confidently work with
  8363. 5:12:13Python and tackle real projects. That
  8364. 5:12:16was really my goal with this entire
  8365. 5:12:18video. So you can now go out on your own
  8366. 5:12:20and it doesn't I can guarantee you it
  8367. 5:12:22doesn't matter which video on YouTube
  8368. 5:12:24for example you'll dive into there will
  8369. 5:12:27be no surprises. You'll be able to
  8370. 5:12:29follow along confidently. So
  8371. 5:12:32congratulations. Like I said I'm really
  8372. 5:12:33excited about this that you made it to
  8373. 5:12:35this point and the fact that you are
  8374. 5:12:36still here. You should really be proud
  8375. 5:12:39of yourself because this is a long video
  8376. 5:12:41and there are going to be a lot of
  8377. 5:12:42people watching this video that like
  8378. 5:12:44only watch half an hour, an hour and
  8379. 5:12:47then they think, hm, you know what? This
  8380. 5:12:49is not for me. But you made it all the
  8381. 5:12:51way to the end and I congratulate for
  8382. 5:12:54you for that. You are awesome. Now,
  8383. 5:12:56there's one thing that I'm going to ask
  8384. 5:12:58from you. So, this course is completely
  8385. 5:13:00free. So, if you enjoy if you enjoyed
  8386. 5:13:03it, what my goal with this course is to
  8387. 5:13:05like share my knowledge about Python
  8388. 5:13:07with as many people as possible. And
  8389. 5:13:09now, here's how you can help more people
  8390. 5:13:11discover this course. What I want you to
  8391. 5:13:13do right now, this is the only thing
  8392. 5:13:14that I ask from you is scroll down below
  8393. 5:13:17below this video and please leave a
  8394. 5:13:19comment about your thoughts about this
  8395. 5:13:21course, what you learned, what you are
  8396. 5:13:23going to build next. just make sure that
  8397. 5:13:25you leave a comment. So, because this
  8398. 5:13:27will let the YouTube algorithm know that
  8399. 5:13:29people are interested in this and this
  8400. 5:13:31will really help to push it. Now, while
  8401. 5:13:33you're doing that, also make sure to hit
  8402. 5:13:35the like button and also subscribe to
  8403. 5:13:37the channel like if you're serious about
  8404. 5:13:39learning AI because I'm dropping new
  8405. 5:13:40videos all the time. That's really what
  8406. 5:13:42I ask for you because through that we
  8407. 5:13:44are going to spread this video and we're
  8408. 5:13:46going to push it really far and
  8409. 5:13:48hopefully it will reach a lot of people.
  8410. 5:13:50So, that's all I ask. And then to really
  8411. 5:13:54wrap it up, really this is the last
  8412. 5:13:56thing over here. What's next, right?
  8413. 5:13:58What do we want to do right now? So, if
  8414. 5:14:00you're serious about AI and specifically
  8415. 5:14:02about Genai and you want to learn how to
  8416. 5:14:04build AI agents using the skills that
  8417. 5:14:07you've just learned, I have something
  8418. 5:14:09really cool for you. So, you made it to
  8419. 5:14:11the end. Are you ready to build AI
  8420. 5:14:13agents? when you downloaded the
  8421. 5:14:15resources which by now you should have
  8422. 5:14:17downloaded and if not this is another
  8423. 5:14:19reminder to do it because as a bonus by
  8424. 5:14:22just through downloading the resources
  8425. 5:14:24over here. So you can see download this
  8426. 5:14:26over here. You can plug in zero or any
  8427. 5:14:28tip you want but with zero it's
  8428. 5:14:29completely for free. You download the
  8429. 5:14:31resources and you also get access to the
  8430. 5:14:33data luminina academy and in here I have
  8431. 5:14:36a special surprise for you because if
  8432. 5:14:38you go in here and if you go to the
  8433. 5:14:39courses you'll find the Python course
  8434. 5:14:42over here. If you click on that, you'll
  8435. 5:14:44find bonus videos as well as the
  8436. 5:14:46follow-up course on building AI agents
  8437. 5:14:49and you can access that completely for
  8438. 5:14:51free and you can continue learning here
  8439. 5:14:53inside the data luminina academy. All
  8440. 5:14:55right, and with that we have come
  8441. 5:14:56officially to the end of this full
  8442. 5:14:59Python for beginners course. I hope that
  8443. 5:15:02you found it useful. I'm really glad
  8444. 5:15:04that you are here at the very end which
  8445. 5:15:07shows your commitment again. Now go make
  8446. 5:15:09sure to check out the data luminina
  8447. 5:15:11academy. then I can catch you there and
  8448. 5:15:13you can continue your learning journey.
  8449. 5:15:15And then I hope that you're off to doing
  8450. 5:15:18great things with these skills and
  8451. 5:15:19hopefully you can use them to make the
  8452. 5:15:21world a little bit of a better place and
  8453. 5:15:24we can all navigate this AI revolution
  8454. 5:15:26together because it's super exciting and
  8455. 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.