free python course

 In this course, you're going to learneverything you need to get started with Python just be aware that I have todesign this course for developers so if you have very little or no programmingexperience check out my other Python course for beginners you can see thelink on the top right corner of this video python is the world'sfastest-growing and most popular programming language not just amongstsoftware developers but also amongst mathematicians data analysts scientistsaccountants network engineers and even kids in fact it's the ideal programminglanguage to learn first but what makes Python so special here are six reasonswith Python you can solve complex problems in less time with fewer linesof code than many other languages that's why huge companies like GoogleSpotify Dropbox and Facebook have embraced this beautiful and powerfullanguage here is an example let's say we want to extract the first threecharacters of the text hello world this is the code we would have to write inc-sharp this is how we would do this in JavaScript and here's how we would do itin Python see how clean and simple the language is and that's just thebeginning Python is a multi-purpose language andyou can use it for a wide range of jobs such as data analysis AI and machinelearning writing automation scripts building web mobile and desktopapplications as well as software testing or even hacking so if you want ahigh-paying long lasting career in any of these areas especially AI and machinelearning Python is the language to put those opportunities at your fingertipsin fact according to indeed.com the average salary of a Python developerin the US was over one hundred and fifteen thousand dollars in March 2018and here are four more reasons that make Python the most desirable languagePython is a high-level language so you don't have to worry about complex taskssuch as memory management as you do in C++it's cross platform which means we can build and run Python apps on Windows Macand Linux it has a huge community so whenever you get stuck there is someoneout there to help and it has a large ecosystem of libraries frameworks andtools whatever you want to do it is likely that someone else has done itbefore because python has been around for over 20 years there are two versionsof Python out there Python 2 which is the legacy version of Python and isgoing to be supported until year 2020 and Python 3 which is Python for thefuture in this course you're gonna learn Python 3 hi my name is Muhammed Ani andI'm going to be your instructor in this course I'm a software engineer with 18years of experience and I've taught way over a million people how to code or howto become top professional software engineers to learn more about me and mycourses head over to code with mass comm alright now let's get started alright now we're ready to download andinstall Python the first thing I want you to do is to open up your browser andhead over to python org on this page under the downloads you can see thelatest version of python currently the latest version is 3.7 chances are in thefuture when you're watching this video there is a newer version available don'tworry all the materials in this course will continue to apply with the futureversions of Python so go ahead and download Python then run it if you're on Windows we'regoing to see this checkbox here add Python to paththis is very important make sure to take it otherwise you're not going to be ableto follow the course so now go ahead and install it now let's verify that we have installedPython properly if you're on Windows here in this search bar type CMD whichis short for command prompt now here in command prompt type Python you can seewe have successfully installed Python version 3.7 now to exit press ctrl-zand then enter if you're on Mac press command and spacethis opens up the spotlight search so here type terminalterminal and Mac is like command prompt on Windows now Mac and Linuxwhy default come with an older version of Python that is version 2 so if youtype Python you can see Python 2 here let's type what we want so press ctrl Dto exit and then run Python 3 and this verifies that we have successfullyinstalled Python 3.7 so this environment you see here is what we call Pythoninterpreter here we have this interactive shell that is really usefulfor experimenting with some Python code so here we can write expressions like2+2 or any kind of valid Python expressions this is similar to yourJavaScript console in the browser so if you want to quickly experiment withsomething can simply do it here but to build real programs we need a codeeditor and that's what I'm going to talk about next to build Python programs you have twooptions you can use a code editor or an IDE which is short for integrateddevelopment environment an IDE is basically a code editor with some fancyfeatures such as Auto completion debugging unit testing and so on forboth editors and IDs there are lots of options out there the most populareditors are Visual Studio code or yes code atom and sublime you can use theeditor that you prefer the most popular IDE is PyCharm which is a JetBrainsproduct in this course I'm gonna use the S code because that's my favorite codeeditor and later I'm gonna show you how to install an extension to convert the scode into a powerful IDE for building Python programs so if you don't have V scode head over to code dot visual studio comm and download the latest version ofV ESCO now it vs code open on the top go to thefile menu and then open somewhere on your desk create a new folder let's callthat folder hello world as usual now open thisfolder now here on the left side we have theExplorer panel where you will see all the files and folders in your project solet's add a new file here and call it app dot pi now you may see an error onthe bottom right corner of the screen don't worry about that we're gonna fixthat later in this section so close this now let's write a simple Python programonce again I've designed this course for people with some programming experienceso you should know your variables functions conditional statements like ifelse for loops while loops you should know the basics if you don't please lookat my other Python course for beginners you can find a link on the top rightcorner of this screen so in Python we have a bunch of built-in functions oneof them is print which we can use to print something on the terminal let'sadd a string here hello world but let's make it more fun by adding a happyPersian cat here now let me show you something cool let's add another printstatement here we add a string like an asterisk in Python you can multiply astring by a number like 10 and this will repeat that string 10 times take a lookso save the changes once again you may see this error popping up don't worryabout it we'll fix that later now we need to go back to the terminal to runthis program however we don't have to constantly switch back and forth betweenvs code and the terminal because here we have an integrated terminal you can openthat by pressing ctrl and backtick that is the key before number one on yourkeyboard it's right below the escape button so here's our integrated terminalso if you're on Windows type Python if you're on Mac Python 3 and an app thatPI and here's the output of our program next I'm gonna show you how to convertvs code into a powerful idea for building Python programs in this lecture I'm gonna show you howto convert vs code to a powerful IDE by using an extension called Python withthis extension or plugin we get a number of features such as linting whichbasically means analyzing our code for potential errorsyou also get debugging which involves finding and fixing errors we'll look atthis later in the course you also get auto completion which basically helps uswrite code faster so we don't have to type every character we get codeformatting which is all about making our code clean and readable just like how weformat our articles newspapers books to make them clean and readable we get unittesting which involves writing a bunch of tests for our code we can run thesetests in an automated fashion to make sure our code is behaving correctly andfinally we get code snippets which are reusable code blocks and we can quicklygenerate so we don't have to type them all by hand now don't worry aboutmemorizing any of these as we go through the course you're going to learn aboutthese features now here in vs code on the left side click this icon this opensthe extensions tab so these are the extensions that we can install in vscode to bring in additional functionality here under the recommendedtab you can see the python extension if you don't see this simply type Pythonhere on the top and here's the extension to go ahead andinstall this and then you'll have to reload vs code now here on the bottom right corner youcan see this message linter pilant is not in stock so as I told you beforelinting is about finding potential errors in our code linter is a programor a tool that analyzes our code and finds these potential problems now forPython there are several enters a fter pilant is one of the most popular onesthat this Python extension uses by default so we need to go ahead andinstall pylons as well now to do this first we need to change our Pythonenvironment so if you look here on the bottom left corner you can see thecurrent python that is used in vs code that is python 2 point 6 point 9 on mymachine chances are you see a different versionhere so click here and in this list make sure to select python 3 point 7 so thesechanges our python environment to python 3 point 7 and then we can install pilantby clicking this button ok pilant is installed beautiful in the next lectureI will show you how linting works in this lecture I'm gonna show youlinting and action so let's start by writing some invalid code like thisprint space with no parentheses and then hello work earlier I told you that printis a built-in function and whenever you want to use or call a function youshould always use parentheses now to be more precise this is actually validPython 2 code but because we're using Python 3 here this is invalid code fromPython 3 point of view so now when I save the changes you can see this redunderline here let's hover our mouse over this underline you can see thistooltip it's coming from Pyland and here's the error message missingparenthesis in call to print did you mean print with parentheses that this isthe benefit of linting as you're writing code you can see potential problems inyour code you don't have to wait to run your program to see these errors so nowif we put parentheses here and save the changes you can see that red underlineis gone let's look at another error let's type two plus and then save thechanges earlier we run this code in Python interpreters interactive shellthere we got a syntax or grammar error so ifyou hover your mouse here one more time you can see pylons is telling us thatthis is invalid syntax or invalid grammar it's like an incomplete sentenceso this is linting in action now let me show you a couple useful shortcuts hereon the top look at the View menu here we have these problems menu look at theshortcut on Mac is shift command and M on Windows is probably shift control Mso as you're working with vs code try to memorize these shortcuts because theyreally help you write code faster now let's take a look at these problemspanel so this problems panel lists all the issues in your code in one place soif you have an application with multiple files this is really useful because someof those files may not currently be open so this linter Pylandwill analyze all your files and if it finds any issues it will list them herein the problems panel now you can also put this on the right side of yourscreen so let's put it here so as you write code these problems will appearhere now let's fix this issue so I'm gonna add three here save the changesand you can see the problem disappear and one last thing before we finish thislecture once again on the top let's go to the View menu the first item iscommand palette this is a very important feature in vs code once again look atthe shortcut that is shift command and P on Mac or shift control P on Windows this command palette you can executevarious commands in vs Co if you type lint here you can see all commandsrelated to linting as you can see all these commands are prefixed with Pythonbecause these commands come with a Python extension that we installedearlier so these are additional features available to us in vs code the firstcommand here is select linter in this list you can see various lintersavailable for pilot so as you're reading tutorials or talking to other people youwill hear about linter such as flake ate my pie pep 8 and so on differentdevelopers prefer different linters I personally prefer pilant that is themost popular one and that's the default linter set and the Python extension ofvs code if you're adventurous we can try using other linters on your own thedifference between these linters is in how they find and report errors someerror messages are more meaningful or more friendly the others are moreambiguous so that's all about linting in the next lecture we'll talk aboutformatting code in Python community we have a bunch ofdocuments called Python enhancement proposals or peps here on Google if yousearch for Python peps you can see the list of all these papsunder python.org slash dev slash paps let's have a quick look hereso here are the paps you can see each PAP has a number and a title the onethat is very popular amongst Python developers is pep 8 which is a styleguide for Python code a style guide is basically a document that defines abunch of rules for formatting and styling our code if you follow theseconventions the code that you write will end up being consistent with otherpeople's code now if you have time you can go ahead and read this PAP 8documentation but if not don't worry because throughout this course I'm gonnaexplain the key things in pep 8 in this lecture I'm gonna show you a tool thathelps you automatically format your code according to pap 8so back in vs code let's write some Python code x equals one here I'mdeclaring a variable and setting it to one if you're not familiar withvariables don't worry in the next section you're going tolearn about that so according to peb 8 this code is considered ugly because byconvention we should add a space around this equal sign or the assignmentoperator now since you're starting out with Python you probably don't knowthese rules so let me show you a tool that helps you automatically format yourcode let's revert this back to its original state now we need to go back tothe command palette remember so it's right here under view and the shortcutis shift command and P here if you search for format you can see thiscommand format document the first time you execute this command you're going tosee this message here formatter Auto kept 8 is not installed so there are abunch of tools for formatting Python code the most popular one is Auto kept 8and this is the tool that this Python extension we installed uses to formatour code so let's go ahead and install this good now one more time let's openup the command palette and execute format document see is toolautomatically formats our code beautiful let's take a look at another example I'mgoing to declare another variable Y and set it to 2 and a variable with a longname like unit underlined price I'm set this to 3 now some developers have thishabit of formatting their variable declarations like this so they put allthese equal signs in the same column according to pep 8 this is consideredugly so once again let's format our code that is better beautiful now let me showyou a trick opening up this command palette and searching for formatdocument every time is a little bit time-consuming so I want to show you howto have your file automatically formatted as soon as you save thechanges on the top let's go to the code menupreferences and settings here in the search box search for format on saveso we have this option editor format on savetake this now back to apt at PI I'm gonna change the formatting of theselines make them really ugly now as soon as I save the changes you can see mycode is reformatted beautiful so you have learned that in order to runthis Python program we'll have to open up the terminal window and run Python onwindows or Python 3 on Mac and an app that pi this is a little bit tedious solet me show you a shortcut once again let's go to the extensions panel heresearch for code runner there are multiple code runners outthere the one that I'm talking about is this one with the yellow icon so goahead and install this and then reload vs code now instead of opening up theterminal and manually typing python after pi all you have to do is to pressctrl alt and in you can see the output here beautifuljust be aware that if you make any changes you'll have to save the changesbefore using this shortcut otherwise you're going to see the old result nowthere is a tiny problem here so you can see this is the command that is executedto run this Python program so by default this command is using Python- U and here is the name of our file if you're on Windows that's perfectly finebut if you're on Mac you know that Python refers to Python - here we wantto change this to Python 3 this is very easy once again on the top under thecode menu let's go to preferences settings and then hereunder this dot-dot-dot go to open settings that JSONnow here in the search bar type code - runner dot executors map so these arethe default settings used by this code runner extension you can see thisextension support executing code in a lot of languages like JavaScript Javaand so on now if you scroll down here you can see Python and in front of thatyou can see the command that is used to execute Python code we need to changethis however we cannot change the default settings we should change theuser settings so on the right side after the last setting type a comma and thenin quotes type code - runner dot executors map and then press enter thiswill automatically copy all the settings on the left side to the right side nowwe can easily change one of this so here's Python let's change the commandto Python 3 you only have to do this if you're on Mac and by the way sorry if wehave mentioned Windows and Mac a few times throughout this course that'spretty much it we are not going to differentiate between Windows and Mac inthe future so save the changes and we're done when we talk about Python we mean twoseparate things that are closely related python language and a particularimplementation python as a language is just a specification that defines a setof rules and grammar for writing Python code a Python implementation isbasically a program that understands those rules and can execute Python codeearlier in the course we downloaded Python from python.org this is thedefault implementation of Python called C Python it's a program written in Cthat's why it's called C Python so here in terminal when we run Python we getthis C Python this is the default implementation of Python there are a fewother implementations out there such as JSON written in Javaironpython written in c-sharp and pi pi written in a subset of Python itself asnew features are added to the Python language they are first supported by CPython because that's the default implementation and then they willgradually come to the other implementations in theory if we givesome Python code to any of these implementations we should get the sameresult but in practice that's not always the case certain features may beavailable in one implementation but not another or they may just behave a littlebit differently in a particular implementation now you might ask what isthe point of this why do we have several implementations of Python wouldn't seePython be enough well it's for the same reason that we have multiple operatingsystems or multiple browsers or multiple programming languages after all theseyears B programmers haven't agreed on a single programming language and that'sthe same story with Python implementations however there is onetechnical reason behind these implementations that you should be awareof since JSON is implemented in Java it allows you to reuse some existing Javacode in a Python program so if you're a Java developer and you want to importsome Java code into a Python program you should use JSON instead of C Pythonsimilarly I Python is written in c-sharp so ifyou're a c-sharp developer and want to bring some c-sharp code into a Pythonprogram you will have to use ironpython next we'll look at howexactly C Python execute Python code the programming languages we use like CC sharp Java Python these are all simple text-based languages that we humansunderstand computers don't understand them they only understand machine codeso if we have some code written in C we should convert it to machine code andthat's the job of a C compiler so a C compiler is a program that knows how toconvert or compile C code into machine codehowever this machine code is specific to the type of CPU of a computer so if wecompile a C program on a Windows machine we can't execute it on a Mac becauseWindows and Mac have different machine code just like how people from differentcountries speak different languages Java came to solve this problem Java compilerdoesn't compile Java code into machine code instead it compiles it into aportable language called Java bytecode which is not specific to a hardwareplatform like Windows or Mac now we still need to convert Java bytecode tomachine code so Java also comes with a program called Java Virtual Machine orJVM for doing this when we run a Java program JVM kicks in it loads our Javabytecode and then at runtime it will convert each instruction to machine codewith this model we can run Java bytecode on any platforms that have a JVM we haveJVM implementations for Windows Mac and so on so the JVM implementation onWindows knows how to convert Java byte code into machine code that a Windowsmachine can understand c-sharp and Python have also taken the same routeso there are platform-independent when we run a Python program using C Pythonfirst it will compile our Python code into Python bytecode then it will passthat bytecode to Python virtual machine which will in turn convert it intomachine code and execute it this is how C Python works in the last lecture wetalked about various Python implementation I told you that if youwant to reuse some java code in a Python program you should use Java nowlet's see how JSON makes this possible when you use JSON to run a Pythonprogram instead of compiling your Python code into Python bytecode it willcompile it to Java code so we can take this Java bytecodeand run it using java virtual machine and that's why you can import some javacode into a Python program when using jythonbecause the end result is Java bytecode which will eventually be executed byJava Virtual Machine so that brings us to the end of thefirst section if you have enjoyed this course so far please like this video andshare it with others in the next section you're going to learn Python Basics inonly one hour I hope you enjoyed this section and thank you for watching well hello Marsh here thank you forwatching my Python tutorial I wanted to let you know that this tutorial is thefirst two hours of my complete Python course where you will learn how to usePython in real-world scenarios such as data analysis and visualizationautomating repetitive boring tasks that involve working with files and foldersspreadsheets PDFs data compression sending emails web crawling consumingAPI is like Yelp to get information about businesses and much much more thiscourse comes with a 30 day no questions asked money back guarantee and acertificate of completion if you're interested click the link below thisvideo to access the course all right let's start this section by adiscussion of variables and the built-in primitive types in Python includingintegers floats boolean's and strings so here I'm gonna define a few variablesstarting with the first one students count note that here all theletters are lowercase and we're using an underscore to separate multiple wordsthis is the naming convention we use in Python so here we said students count tolet's say a thousand this is an example of an integer let's look at an exampleof a float so we said rating two for let's say 99here's another variable is published we set this to true or false note that thefirst letter is uppercase and finally let's take a look at an example of astring so we set course name to Python now in Python you can use either doublequotes or single quotes or you can use triple quotes if your string is multiplelines for example here I can put triple quotes and in between them I can add astring that has multiple lights okay now one interesting feature in Python isthat you can initialize multiple variables on the same line for examplelet's say we have coordinates like x and y we can initialize these two on thesame line so we can set X comma Y we set it to 1comma 2 this line is exactly equivalent to these two lines so it's a shortcutand finally just like almost every programming language we can set multiplevariables to the same value for example we can set x and y to 1 so these are thebasics of variables next I'll talk about the dynamic nature of Python in terms of typing programming languagesfall into two categories static languages like C++ C sharp andJava and dynamic languages like JavaScript Ruby and Python in staticlanguages when declaring a variable we need to specify its type for example inc-sharp when declaring this variable we need to set its type to an integer sowith this the type of this variable will always be an integer when we compilethis program or compiler knows that students count is an integer so if youaccidentally try to set it to let's say a boolean later on the compiler willcomplain this is how static languages work in dynamic languages likeJavaScript and Python we don't have this behavior so we don't set a type whendefining a variable we just define a variable by setting it to a value so indynamic languages the type of a variable is determined at runtimenow here if you hover your mouse over students count you can see this is aninteger so when working on a large complex program if you want to know thetype of a variable you can simply hover your mouse over it we also have thisbuilt-in function called type we can pass a variable or an object to it likestudents count and then print this on the console so let's run this programyou can see the type of students count is a class of integer what is thisPython is an object-oriented language so here we have the concept of classes ifyou're not familiar with classes don't worry I'm gonna talk about them indetail later in the course all I want you to know now is that in Python wehave a class called int that represents integers so allintegers are instances of this class let's take a look at a few more examplesso here in this interactive shell let's look at the type of a float once againit's a class called float let's look at type of a boolean this is also a classcalled bool and finally let's look at type I'm a string that's a class calledstir so here's the take away Python is a dynamic language which means the type ofvariables are determined at run time as opposed to compile time sorry the last lecture you learned thatPython is a dynamic language which means the type of variables is determined atrun time so here we have this variable age set to an integer now we can resetthis to a string this is perfectly valid Python code so if we print a age and runthis program you can see our program is running successfully now if you come topython from a static language like C sharp or Java you probably don't likethis but the good news is that in Python 3.6 we have a new feature called typeannotation or type hinting so we can annotate our variables with their typeso we had a colon here and then int for integer now when I save the changeseverything is still valid if I run the program there are no errors becausepython is a dynamic language however there is a new lantern called my PI thatchecks for these type annotations so if you define a variable as an integer andthen set it to a string my pie is gonna complain let me show you so open up thecommand palette and type select linter correctly you can see we are using pilint in this list select my pi now the first time you do this you're gonna seea message on the bottom right corner of the screen telling you that my pine isnot installed so go ahead and install that now on line two you can see a redline under H let's have a look here so my pi is giving us an error incompatibletypes in assignment so this is all about type annotation or type in ting so here we have this variable X set to 1when we run this program Python interpreter will allocate some memory tostore this number 1 so our X variable is purely a label for that memory locationlet me show you so here we have this built-in function called ID we can passthe variable here like X and this will return the address of the memorylocation that X references so now let's print this on the console there you goso this is the address of the memory location where we have stored number onenow one thing you need to know about the built-in primitive types that I'vetalked about so far like numbers strings and boolean is that all these types areimmutable which means their value cannot change so here if we try to update Xpython interpreter is going to allocate some new memory to store the updatedvalue in other words what we have at this original memory location will notbe affected because integers are immutable let me show you this so hereafter we print the idea of X I'm gonna increment X and print its ID one moretime see what we get we get two different addresses so our X variable orX label was originally referencing this memory location at this memory locationwe have the number one because integers are immutable we cannot change the valueat this memory location so on line four when we update X python interpreter willallocate some new memory at this location and then X will reference thisnew memory location now because we don't have a reference to the original memoryat some point Python garbage collector will automatically release this memoryso this is how immutable types work now let's see what would happenif X was set to a mutable type here is an example so in Python we havea concept called lists for storing a list of objects so here we use squarebrackets to indicate that this is a list we can add multiple objects here now online four let's add a new number to this list so we call X dot append and passfour here now let's run the program one more time so as we can see the addressis not changed because lists are mutable so whenever we change them by adding newobjects to them or removing existing ones the changes are applied at the samememory location so this is the difference between mutable and immutabletypes over the next few lectures we're goingto take a closer look at strings so here we have a variable of type string to getthe number of characters in this string we use the built-in Len function nowlook at the intellisense this function returns the number of items in acontainer so it's not specific to strings it's a generic reusable functionwe can pass the a string here and this will return the number of characters inthe string or we can pass a list and this will return the number of items inthe list so here let's pass this course variable and print the length so we have18 characters beautiful similar to many other languages we can access individualcharacters using square bracket notation so to get the first character we usesquare brackets 0 because the index of the first character here is 0 now let'sprint this run the program so we get P now one interesting feature in Pythonthat I personally haven't seen in other programming languages is a negativeindex so here let's duplicate this line and pass negative 1 what do you thinkwe're gonna get well if 0 represents the first character negative 1 takes us backto the end of the string so it returns the first character from the end of thestring let's run this program so we get G similarly we could pass negative 2 andthis will return the second character from the end very powerful now using asimilar syntax we can also slice strings so let's duplicate this line to slicethe string we need to pass two indexes the start index colon the end index sothis will return all the characters starting from the start index all theway up to the end index but it doesn't include the characterat the end index in this example it's going to return zero one and two thesethree characters but not the character at index 3 okso let's run the program we get the first three characters beautiful now wecan exclude either or both these indexes and Python will assume default values solet's duplicate this line and exclude the start index what do you think pythonis going to put here it's common sense it's going to pass zero as the startindex so let's run the program you can see we get the same result so these lasttwo expressions are exactly the same now what if we exclude the end index what doyou think Python is going to put here it's going to pass the length of thestring so let's run the program you can see this returns the entire string andfinally if we exclude both the start and end index again we get the same resultso let's verify this beautiful now one thing you need to take into account hereis that whenever we access an individual character or a range of charactersPython interpreter is going to allocate some new memory and copied thosecharacters into that new memory location because as I told you before strings areimmutable so the value that we have at the original memory location that isPython programming will not be affected we can verify thisso let's print ID of course and then print ID of course of zero and then runthe program you can see two different addresses here that is because stringsand other primitive types like numbers and billions are immutable in Python here we have this message variable setto this string Python programming now let's say we want to display a doublequote right here the problem we have is that this second double quote indicatesthe end of the string so python interpreter will not be able to run thiscode now there are two ways to solve this problem one way is to replace thesedouble quotes at the beginning and end of our string with single quotes sosingle code here and one more here if we run this program we see this double codejust before programming beautiful but let's say for whatever reason you wantto use double quotes here perhaps to be consistent with the rest of our code sohow can we display another double quote in the middle of this string well inPython we have a concept that is borrowed from the C language that iscalled escape character so in Python strings backslash has a special meaningand we refer to it as an escape character so Python interpreter seesthis backslash as a special character it has a special meaning and depending onthe character that comes after that it will interpret it differently let's seethis in action so now when we run this program we can see our double code herebut the backslash character is not there because backslash is an escape characterso in this case it's used to escape the double code now we refer to these twocharacters as an escape sequence in Python we have a few other escapesequences that you should be aware of let me show youso this hash sign is an indication of a comment line so it's not executed youhave seen backslash double quote we also have backslash single code fordisplaying a single quote in our string we also have double backslashes so ifyou really want to have a backslash in your string you should prefix it withanother backslash here is an example let's run this programand here's our backslash and finally the last escape sequence is backslash nwhich is short for new light so here if I add a backslash N and run this programyou can see programming is on the second line now this is OK for a simple stringlike Python programming here but if you're trying to format a complex stringinto multiple lines it's better to use triple quotes otherwise you'll end upwith a lot of pack /n sequences and that looks pretty ugly so here we can usetriple quotes and simply add Python newline programming so when we run thisprogram we get exactly the same result as before but not quite exactly becausehere we have one new line on the top that is because I put Python on a newline if I put Python right in front of double quotes run the program again thatnew line disappears so here are the escape sequences inPython here we have two variables first andlast let's say we want to print my full name on the console so we can defineanother variable full set it to first then concatenate it with a space and onemore time concatenate it with last now when we print full we get my full nameon the console beautiful now this approach are using concatenation tobuild a string is okay but there is a better and newer approach we can useformatted strings so here we can set full to this string and prefix it withan F which can be lowercase or uppercase it's formatted string doesn't have aconstant value like these two strings here it's actually an expression thatwill be evaluated at runtime so here we want to add our first name we use curlybraces to print the value of the first variable after that we add a space andthen we add curly braces one more time to print the last name so at runtimethis expression will be evaluated what we have in between curly braces will bereplaced at runtime now let's run this program one more time we get the exactsame result just be aware that you can put any valid expressions in betweencurly braces so earlier you learned about the built-in Len function we cancall Len here to get the length of this string let's run this program one moretime so we get four we can also replace last with an expression like there's twoplus two let's run this program we get four and four so when using formattedstrings you can put any valid expressions in between curly braces and it's lecture we're going to explorea few useful methods of string objects in Python so this course variable wehave here is a string object which means we can use the dot notation to find allthe methods or functions applicable on strings here we have a large list offunctions or more accurately methods in this lecture I'm gonna quickly show youa few of them you can learn about the rest on your own so here let's say wewant to convert this course to uppercase we can use the upper method and printthe result and we'll get this uppercase string here similar to that we havelower to convert it to lowercase we also have title which will convert this totitle case which means the first character of every word will beuppercase and this is useful for blog posts product titles courses and so onso let's run this one more time we get this string here another useful methodis strip for trimming whitespace so if we have a couple of extra whitespace atthe beginning or end of this string we can get rid of them using the stripmethod and this is useful when you get input from the userso a print course that strip save the changes note that in the previousexamples you can see those extra white spaces at the beginning but when we callthe strip method those spaces are gone we also have left and right strip forremoving the whitespace from the beginning or end of this stringnow if you want to find the index of a character or a substring in your stringyou can use the find method so let's print course that find let's search forpro run the program so the index of pro here is 9 now if I change this tolowercase P we'll get negative 1 because string comparisons are case sensitiveand we don't have these exact three characters in our course variable now ifyou want to replace a character or a sequence of characters you can use thereplace method so let's print course that replace let's replace all capitalpees ways a hyphen and with this we'll get this weird string here and finallyto check for the existence of a character or a sequence of characters inyour string you can use the in operator so let's see if we have programming inthis course object let's run the program and we get false because I realize thatI missed the letter R here so let's run the program one more time this time weget true now we also have the not operator so you can prefix this with notand this time we'll get false so we have covered strings now let'slook at numbers we have a few different ways to represent numbers in Python wecan use decimal numbers that you have seen before we can also represent themin binary format so we prefix the number with 0 B as in short for binary and thenwe'll add individual bits for example 0 B 10 which is the number 2 in binarysystem now let's print X we'll get 2 if you want to print the binaryrepresentation of this number you can use the built in bin function so bintakes any numbers and returns its binary representation there you go we can alsorepresent numbers in hexadecimal format so we said X - 0 X as the prefix andthen we'll add our hexadecimal number let's print X so we get 300 which is inthe decimal system if you want to print this in the hexadecimal format you woulduse the built-in hex function let's run this program one more time and now weget 0 X 12 C beautiful in Python we also have support for complex numbers socomplex numbers in maths take the form a plus B I if you're notfamiliar with this don't worry this is a concept used in mathematics so if youwant to use Python to build web applications you're never gonna use thisbut very briefly let me show you how you can represent complex numbers in Pythonso here we can set X - 1 + 2 J so J in Python is like I or imaginary number inmath you can use either lowercase or uppercase J whatever you prefer nowlet's print X we'll get this complex number hereyou in Python we have all the arithmeticoperators that you have probably seen before for example we can set X to 10plus 3 we have addition I have subtraction multiplication division butwe actually have two kinds of division operators let's look at the first one soprint X as you can see the result of this division operator is afloating-point number if you want an integer you would use a differentdivision operator that is double slash let's run this program so we get 3 wealso have modulus so that is the remainder of a division and finally wehave exponent that is left ^ right so here 10 to the power of 3 'is a thousandnow for all these operators here we have an Augmented assignment operator what dowe mean by that let's say we want to add 1 to X we canwrite a statement like this so x equals x plus 1 or we can use an Augmentedassignment operator so X plus equals 1 these two statements are exactly thesame and what we have on the left side of the assignment operator can be any ofthese arithmetic operators here and one last thing before we finish this lecturein Python unlike languages like JavaScript or C sharp we don't have theincrement or decrement operators so we don't have X plus plus or X minus minus in this lecture I'm gonna show you a fewuseful functions for working with numbers so let's set X to 3.14 oractually let's rename this to PI note that here I have used uppercase lettersto indicate that this is a constant in Python unlike languages like C sharp andJavaScript we don't have constants we only have variables so if we define thisthere is nothing that stops us from changing the value of this variable soby convention we use uppercase letters to tell other developers in the teamthat this pi is a constant and it shouldn't be modified now let me showyou a few useful built-in functions to work with numbers if you want to roundthe number you can use the round function so let's pass PI here and printit so we get 3 we have another useful function ABS short for absolute and itreturns the absolute value of a number so if you had a minus sign here when weprint this will get 3.14 here you go now to see the complete list of built-infunctions in Python here in Google search for Python 3 make sure to add theversion number and then add built-in functions on this page you can see allthe built-in functions in Python now in this list we only have a few functionsto work with numbers if you want to perform complex mathematicalcomputations we have a separate module for that that's the math module so backto our code on the top first we need to import the math module now mass is anobject with a bunch of useful methods for performing mathematical computationsso here we can use the dot notation to see all these methods available to usfor example you can use mass dot floor to get the floor of pi and this returns-4 because here we are using a negative signif you want to see the complete list of functions or methods in the math modulesearch for Python 3 math module here on this page you can see all the functionsand their description quite often when we receive input fromthe user that input comes as a string and there are times that we need toconvert that string to a different type here is an example we have this built-infunction input we can add a label here like X this returns the users input as astring so we store it in this variable now let's imagine why should be X plus 1now when we run this code we're gonna get an error let me show you don't runthis using the code runner because code runner runs this code inthe output window which is read-only so you won't be able to enter a value soopen up the terminal by pressing ctrl + bhakti and run Python different windowsor Python 3 if you're on Mac I've got PI let's add one here look we get thiserror type error this is happening because Python doesn't know how tointerpret this expression because here we have two different outcomes if X isthe string one one outcome is to convert this other operand here to a string andthe result would be 11 the other outcome is to convert X to a number so we'llhave 1 plus 1 and the outcome will be 2 so Python doesn't know how to do typeconversion here and that's the reason we say Python is a strongly typed languagebecause it doesn't do any implicit type conversion on your behalf you have toexplicitly tell Python how you want your objects to be converted to the righttype Java Script on the other hand is a weakly typed language so it does performimplicit type conversion for you now to solve this problem we need to use one ofthe built-in type conversion functions we have int float pull and stir orstring now in this case we don't need to use string here because we already havea string and there is no reason to convert a string to another but thereare times that you may want to convert an object to your string so just beaware of this function now let's take a look at what this functions return and let's delayed line two because thisis the bad boy here save the changes back in the terminal let's run theapplication one more time and enter one so here's what we get number one as aninteger one point zero which is a float and true so int and float are prettyself-explanatory but bull requires a little bit more explanation because inPython similar to JavaScript we have this concept of truthy and falsy valuesso here are the list of false e values empty strings number zero empty listsand none which is an object that represents the absence of a value thisis exactly like null in C based languages so if we have any of thesevalues and we try to convert them to a boolean using the bull function theresult will be boolean false anything else would be true let's take a look ata few examples so here in the interactive shell I told you that numberzero is considered false II so when we convert it to bool we'll get false anyother numbers are true or true the-- so here's an examplebula one is true if we add a negative number we also get true ask for stringsan empty string is false e so we get false any other strings is truth e soeven if I had the string falls here the result is true because this is a nonempty string so here are the faulty values in Pythonwhenever these values are used in a boolean context they will be equivalentto boolean false alright now let's talk about conditionalstatements so I'm going to start by defining a variable H and sending it to22 now let's see if H is greater than or equal to 18 so in Python we have thesecomparison operators just like the other languages that you have worked with wealso have equal and not equal now let's rewrite this back to greater than orequal to 18 now here's an interesting fact about Python in Python we don'thave braces which means we're not gonna spend two decades fighting over where toput this braces shall we put them here or here no more nonsense like that it'sover that's it no more so instead we put a colon at the end of this line now notethat when I press ENTER this cursor is automatically indent so we useindentation to specify a code block here we can add a print statement adult wecan have another print statement this is also part of this block now to terminatethis block we simply remove the indentation now here we can have zero ormore elseif blocks in python we call them Elif here we add another conditionlike if H is greater than or equal to 13 once again we have indentation let'sprint teenager and finally optionally we can have an else block once again colonprint with one or more statements in this case we want to print child finallywe'll have let's say all done now note that currently we have two spaces forindentation but when I save the changes auto-pay page kicks in and reformat ourcode according to pay paid according to pap 8 we should use four spaces forindentation take a look save the changes now we have four spacesyou can also use tabs but only if you're maintaining a code that is written withthat style if you're starting a new project prefer four spaces as thestandard but you cannot mix tabs and spaces in Python three that's notallowed now let me show you a shortcut so herein a new file let's just type if look at these three items with this square iconthese are code snippets so here on if-else I press ENTER and thisautomatically generates this snippet this came with the Python extension thatwe installed at the beginning of the course so here you can change thecondition to whatever X is greater than onewhat is this past keyword this is basically a statement that doesn't doanything it's here purely to fill this if block because we cannot have an emptyif block like this I say have the changes look we have this red underlinedhere that is not valid Python code so if you want to have just an empty block youuse the pass keyword in Python just like the other languageswe have three logical operators we have the logical and the logical or and notlet's take a look at a few examples so I'm gonna start by defining a variablename sending it to Maj now let's say this is the input that we get from theuser we want to check to see if name is an empty string how do we do that wellearlier I talked about the faulty values in Python so we have 0 empty of stringnan and an empty list these are all considered false e so let's talk aboutan empty string if this is interpreted as false then if we apply the notoperator on it will get true right so to check to see if name is an emptystring we can simply write a statement like this if not named color that's itprint name is empty now let's run this program obviously we don't get thatmessage however if I change this to an empty string and rerun the program weget name is empty but what if I add a white space herewell white space is not considered true see because it's not an empty string solook if I run the program we don't get the message to fix this issue we cansimply call dot strip method to get rid of all the white space now let's run itone more time beautiful so this is our not operator let's take alook at an example of ant so I'm going to set H to 22 now let's see if H isgreater than or equal to 18 and age is less than 65 we say you are eligiblegood pretty easy right now here a question how do we write thatexpression in math we write it like this well more accurately we should add theequal sign here so age is between 18 and 65 right I have good news for youin Python you can simply write this expression that's perfectly fine this iswhat we call chaining comparison operators so we can rewrite thisexpression in a simpler and more meaningful way this is one of thereasons that Python is a highly popular language because the syntax is so cleanwithout any clutter it's easy to understand and it comes with all thesebest practices and standards for writing clean code so let's rewrite this to 18like this good now let's run the program obviously this person is eligible so here we have this piece of codesimilar to what we wrote in the last lecture if the person is 18 years orolder we set the message to eligible otherwise we set it to not eligible in Cbased languages we have this operator called ternary operator that allows usto rewrite this piece of code in a more compact way let me show you how thatlooks like so we set message to we add our condition so if age is greater thanor equal to 18 we add a question mark if that is truewe set the message to eligible otherwise indicated by a colon we set it to noteligible if you have worked with C sharp JavaScript C++ Java you have seen thisbefore if not don't worry let me show you the Python way so in Python we canrewrite this expression almost in plain English so message is eligible if age isgreater than or equal to 18 otherwise it's not eligible isn't that easy sothis is the ternary operator in Python in Python we have two types of loops sounlike some languages that have four or five different kinds of loops here weonly have two types we have four loops and while loops their syntax is verysimple and clean let me show you so we start with the four loops with fourloops we can iterate over any object that is a trouble here are a fewexamples we can iterate over strings so for X in Python because strings inPython are a trouble which means we can iterate over them so in each iterationour loop variable X will hold one character let me show you so weterminate this line with a colon just like our if clauses now useindentation to specify the block of statements so we simply print X run theprogram this is what we get here's another example we can loop over listsso let's say we have a list of names a b and c colon print x there you go so weget ABC here now what if you want to loop over a sequence of numbers that'swhen we use the built-in range function let me show you so for x in we call therange function pass a number like 5 look at what happens now to keep this exampleclear I'm gonna comment out these few lines so the shortcut on Mac is commandand slash on Windows is control slash now let's run this programso when we call range of 5 we get numbers 0 to 4 we can pass a startingnumber like 2 to 5 let's run this one more time so now we get to 3 4 we canalso pass a third argument here called step let me show you so I'm going tochange this zero to ten let's say we want to displayall the even numbers between zero to ten so we passed two here that is our stepnow when we run the program we get zero to four and so onnow one thing you need to understand about this range function is that itdoes not return and list let me show you so I'm gonna comment out these two linesas well let's just print range of 5 what do we see we see range of 0 to 5 wedon't see a list object in contrast if we had a list like 1 2 3 4 5 see this ishow we see a list printed in the terminal so what is returned from therange function is not a list it's a different kind of object it's a rangeobject let me show you so here I'm gonna call the built-in type function nowlet's look at the type of this object it's an instance of a class calledrange so our range function returns a range object range objects in Python areiterable like strings and lists so we can use them in for loops now what isinteresting about this range objects is that they take a very small amount ofmemory so here if we pass let's say 5 billion we are not gonna get a list of 5billion elements you have a small object that can be iterated over in eachiteration it will produce a new number like 1 2 3 4 and so on in contrast if wehad a list of 5 billion items that list would take significant amount of memoryso this is the difference between list and range objects so here we have a list of names let'swrite a simple program and check to see if you have a name that starts with J inthis list so we can use our for loop for name in names now if name that startswith J perhaps we want to display a message like found now if this list hasa million objects as soon as we find the first object we want to jump out of thisloop we don't want to continue looping for performance reasons so this is wherewe use the break statement you have probably seen this before when pythoninterpreter sees this statement it will terminatethis iteration so now we jump out of this loop let's add another scenario tothis program if we loop over all the names in this list and we don't find aname that matches our criteria perhaps we want to display a different messageto the user like hey we couldn't find a name that starts with J so typically howwe implement this in other programming languages is like this on the top wedefine a flag like found and set it to false then here as soon as we find anobject that matches our criteria we set this flag to true and then after our forblock we check to see if not found we print not found let's save the changesgood run the program obviously we have a name that starts with J so foundbeautiful now let's change this to a John around the program not found so ouralgorithm is working properly but in Python there is a cleaner way toimplement this scenario we don't need this found flag so let's delete it fromhere and here all we have to do is to get the same result is to change thestatement to else so we have four else blocksin Python this else Clause is executed if our for loop completes successfullywithout an immediate break so if we iterate over all the objects in thisiterable then this else Clause will be executed so now when we run this programwe get the exact same result the other type of loose we have inPython our while loops so let's build a simple guessing game I'm going to definetwo variables yes set to zero and answer set to five now we can write a whileloop like this while answer is not equal to guessonce again : here we have indentation we can get the input from the usermake a guess now as you know this returns a string so we need to convertthis to an integer and then store it and the guest variable now as I told youbefore this code runner extension runs our code in the output window which isread-only so we cannot enter values there to fix this issue on the top let'sgo to preferences settings then click here and open settings at JSONnow here we need to add a new setting that is code - runner that run interminal by default it's false we need to set this to true save the changes nowwhen we run this program using code runner it runs it in terminal so here interminal window let's add a number like 1 2 3 4 as soon as we enter 5 the gamestops so this is our while loop similar to for loops we have an else block herewe can optionally use that this is only executed if the while loop completessuccessfully without using a break statementyou to define a function we start with thekeyword def which is short for define or function definition here you can see wehave a few code snippets the first one is for defining a function so just pressEnter so here's the basic syntax we start witha function name like increment now press tab in parenthesis we define parametersif they exist in this case let's have a couple of parameters like number and whyso we want to increment a number by a given value right also you can see inthis line is terminated by a colon and right after that we are usingindentation to specify the body of this function just like our if and fourclasses now we can call this function like this so increment parenthesis giveit a couple of values like two and three now note that when I save the changesyou're going to see two line breaks after this function so save there you goso you have two line breaks because that's the style that pepp eight definesso we should always have two line breaks after our functions now these functionsby default return the non or a null value so even though we don't have areturn statement here this function is still returning a value let me show youso print the return value of increment and run the program look we get not nowlet's return a value like number plus by run the program again now we get fivebeautiful in Python unlike many other languages out there we can returnmultiple values from our functions we simply put them in parentheses so herewe add parentheses let's say we want to return the original number as well asthe updated number so number comma number plus PI now let's see what we getwhen we run this program serve run it so in parentheses we get two which is theoriginal number and the updated number what is this this iswhat we call a top-up which is basically a read-only list so earlier in thecourse you have seen lists like numbers we use square brackets 1 2 3 this is alist we can add new objects to it we can remove existing objects a topple is likea list but we cannot modify it so we cannot add new objects to it we cannotremove existing objects now to convert this list with topple we use parenthesesinstead of square brackets okay delete another useful feature we havehere is called keyword arguments so currently if someone looks at this codethey may not be able to tell what exactly these arguments are for we canuse keyword arguments to make our code more readable for example here we canprefix the second argument with something like this by equals now we canread this code like plain English increment two by three so this is whatwe call a keyword argument it's just a way to make our code more readable alsosimilar to a lot of languages out there we can assign default values to theseparameters for example we can set a default value for the by parameter sonow we don't have to pass a second argument here and when we run thisprogram the value of y will be set to 1 by default and one last thing before wefinish this lecture earlier I talked about type annotation or type hinting wecan use that feature in our functions as well so here we can annotate theseparameters as well as the increment function itself so here we had : int forinteger and here also : int and finally for the function itself before this :that terminus this line we need to add an arrow and then we'll add the returntype of this function so integer as well now in this case we have a red underlinehere we i annotated this function to return aninteger but I'm returning a topple so more accurately this should be topplesave the changes and the error is gone there are times that you may want topass an arbitrary number of arguments to a function here is an example let's saywe have a function called multiply that currently takes two parameters a and Band this function would simply return a times B and then we can call it likethis so far so good but what if you want topass a variable number of arguments here like four and five well one way is toput these arguments in a list then we need to replace these two parameterswith a list and we should also change the implementation of this function herewe need a loop to iterate over this list and multiply all its elements that isperfectly fine however this syntax is a little bit noisywouldn't that be nicer if we could pass these numbers or these arguments herewithout these additional square brackets let me show you how to do this so all wehave to do is to prefix this parameter with an asterisk now let's print listand see what we get when we call the multiply function so save the changesrun the program what do we get here we get a top hole because of theseparentheses so when we add an asterisk before a parameter Python will see thatparameter as a topple so when we pass an arbitrary number of arguments Pythonwill automatically package them into a toppleas I told you before a topple is like a list so we can loop over it get all thenumbers and multiply them together let me show you real quick so we start bydefining a variable total we set it to one next with a loop so for number inlist : here we simply do total times equal number and finally we return totalthe changes good run the program actually I forgot to print the resultsso let's print it here run it one more time so here's the total in the last lecture you'll learn aboutthe syntax for passing a variable number of arguments to a function we have avariation of this syntax and that's what I'm gonna show you in this lecture solet's start by defining a function call it save user here we add one parameteruser but instead of one asterisk we use double asterisksso first let's print this user parameter here and see what we get when we callthis function so save underline user now instead of passing an arbitrary numberof arguments here we should pass an arbitrary number of keyword argumentsremember keyword arguments name a codes value so here we can pass multipleproperties about a user for example we can pass ID equals 1 name equals adminand so on so here we have two keyword arguments let's run this program and seewhat we get when we call this function I'll save the changes and run this iswhat we get look at the syntax here we have curly braces and in between them wehave multiple key value pairs here's the first one here is the second one this iswhat we call a dictionary if you're a JavaScript developer thissyntax is familiar too this is like an object in JavaScript nowif you're not familiar with JavaScript objects or dictionaries in generaldon't worry later in the course you have a comprehensive section about datastructures in Python and there I'm gonna cover lists tuples dictionaries and soon now to finish up this example here we can use square bracket notation to getthe ID or name of a user let's run this program one more time so ID is 1 andname is admin beautiful in Python we have two types of variableslocal variables with the function scope and global variables with the file scopeso in this example this message variable is a local variable in the greetfunction its scope is the greet function so we can access it anywhere in thisfunction now in Python unlike languages like C sharp orJavaScript we don't have block level scope so if we define this variableinside of an if block it is still accessible outside of that block let meshow you so here I'm gonna add if true colon inside of this if block you'redefining the message variable but still accessible outside of the if block sohere we can print message the same applies if we have a loop here a forloop or a while loop so in Python we don't have block level scope no matterwhere we define a variable in a function it is always accessible in that functionafter it is defined so that's all about our local variables now let's talk aboutglobal variables if we put this message variable outside of this function nowit's a global variable so it's accessible anywhere in this point in anyfunctions so here in the greet function we can print it on the terminal let'stake a look so here recall greet run the program we get a now let me show yousomething interesting here the greet function I'm gonna assign a new value tothe message variable let's set it to be run the program again obviously we get Bhowever if I bring this print statement outside of this function and run theprogram again let's see what happens we get a what's going on here didn't wechange the value of the message variable not really in this case this messagevariable becomes a local variable in the greet function because by default pythonenforces good programming practices as you probably knowglobal variables are evil we shouldn't change them in a function because thiscan cause a side effect in other functions so in this case when pythoninterpreter sees line 5 it will create a new localvariable called message even though it has the same name as our global variableon line 1 these two are completely separate now I've seen some tutorialsand books teaching you bad programming practices they show you how to modifythe value of a global variable inside of a function so this is how we do it weuse the global keyword and reference the message variable when Python interpretersees this it will realize that in this function we don't want to create a localvariable we want to use the global message variable that we defined earliernow if we run this code instead of a we're gonna get B because the changeswill be visible after we exit this function and that is the reason I saidyou should avoid using global variables or if you really want to use them makesure not to modify them inside of a function because this can create a sideeffect in other functions maybe other functions rely on the original value ofthat variable so avoid using the global statement it's a bad practice it's evil alright let's finish up this section bylooking at debugging in vs Co so I had this simple program with this multiplyfunction that we talked about earlier if you want to follow along with me headover to bit Dudley /pi gist GIS T here on github you can see my guestsimply copy paste this code we're going to use this code to explore debug in vsCo so below this function we have three statements to print start the result ofcalling the multiply function and print finish so to start debugging first weneed to add a breakpoint so here on line eight you can use your mouse to put abreakpoint here or if you have taken any of my courses before you know that Ialways put a lot of emphasis on using your keyboard because professionaldevelopers use their keyboard not their mouseso using f9 you can add or remove a breakpoint now open up the debuggingpanel here on the top click this icon here this will create a JSON file calledlaunch that JSON with a bunch of configuration for debugging you can seethis file in the project folder inside of this vs code folder here is launchedat JSON now you never have to touch this file we just have to create it the firsttime now let's close this back to the debugging panel now after this file iscreated in this drop-down list you can see various configuration options for adebugging session from this list select python current file integrated terminalso we're going to debug the current file in the terminal that is integratedinside of vs code there is also another one with an external terminal now tostart a debugging session press f5 so here on the right side you can see myintegrated terminal I'm going to close this because it's cluttering the view soso here is the breakpoint activate it now we are on this line we can step overeight by pressing f10 if you're on a Mac keyboard you should hold the functionkey that is on the bottom left corner of your keyboard so step over now on line 9we are calling a function so we want to step into this function to see what isgoing on there for this press f11 now here we are inside of the multiplyfunction on the left side inside the variables panel you can see thevariables that are local in this scope so we have numbers which is the argumentpassed to this function let's step over one more time at f10 now we are at thebeginning of our loop one more time f10 now at this point you can see a fewother variables here so we have our total we have the current number that ispicked in this iteration you can also create watches here if you want to lookat the value of a variable that is not listed in this panel now let's say youinspected all the variables and you want to step out of this function to do thatpress shift and f11 now we are out back on line 9 f10 onemore time and one more time and the debugging session is finished alright let's finish up this section bylooking at a few very useful shortcuts for writing code fast first I'm going toshow you the shortcuts for Windows users and in the next lecture we will look atthe shortcuts for Mac so if you're a Mac user feel free to skip this lecture sohere we are on line 9 and my cursor is right at the beginning of the line let'ssay you want to move the cursor to the end of the line instead of pressing theright arrow to go all the way to the end we can simply press the end key and hereis the cursor or if you want to move the cursor to the beginning of the linesimply press the HOME key there you go similarly if you want to move the cursorto the beginning of the file press ctrl + home here it is or ctrl + end/2 go tothe end of the file now let's say we want to move this line up instead ofcutting it from here and then copying it somewhere else we can simply move it upby pressing Alt + the up or down arrows or if you want to move these two linesup and down simply select them then hold alt and then up or down very easy now ifyou want to duplicate a line or multiple lines simply select them now hold downshift alt and then press a down key we can duplicate it as many times as youwant there you go here's another useful shortcut if you want to convert thisline or maybe these two lines into a comment simply hold down control andpress slash using the same shortcut you can remove the comment so you can toggleit very easy and finally if you want to type the name of a variable or afunction like multiplied you don't have to type all characters here are a fewways to type this quickly we can just type the first few characters and herein the intellisense you can see that so if you press ENTER this is what we callauto-completion here's another way so instead of writingthe first few letters you can just pick any letters in sequence and type them soI can type mty or I can just type mpy or why there you go here it is so I hopeyou enjoyed these shortcuts and thank you for watching alright now let's take a look at theshortcuts for a Mac keyboard so here we are on line 9 and my cursor is right atthe beginning of the line if you want to move the cursor to the end of the lineinstead of using the right arrow to go all the way simply hold down thefunction key and press right here it is or you can press function and left tojump to the beginning of the line similarly you can press function and upto go to the top of the file or function and down to jump to the end of the filepretty useful now let's say you want to move this line up instead of cutting itfrom here and then copying it somewhere else you can simply move it up byholding down alt or option and then pressing the up arrow or down very easyor we can select these two lines hold down the alt or option key move it up ordown here's another useful shortcut we canconvert these two lines into a comment by pressing command and slash and thenwe can remove the comment using the same shortcut so we can toggle it and finallyif you want to type the name of a variable or a function like multiply youdon't have to type all the letters like multiply that is very slow you can typethe first few letters like mult and here in the intellisense you can see it'sselected so press Enter or you can pick any characters in sequence and type themlike mty here it is or we can type an py or m TP so you can abbreviate it any wayyou want I hope you enjoyed these shortcuts and thank you for watching one of the questions that often comes inprogramming interviews is the fizzbuzz algorithm you might be surprised thatthere are a lot of developers out there with even years of experience but theydon't know how to solve this simple programming problem that's why I decidedto include this in my course so let's see how this algorithm works and thenyou can spend 10 to 15 minutes on this exercise on your own so here we have afunction fizz buzz that takes an input and depending on the input we give it itreturns different results here are the rules if the input that we give it isdivisible by 3 it will return the string fist let me show you so we run thisprogram we get fizz if the input is divisible by 5 it willreturn buzz take a look here's buzz now the thirdrule if the input is divisible by both 3 and 5 it will return fizzbuzz so let'spass 15 here we'll get fizzbuzz for any other numbers it will return the sameinput so if I pass 7 it's not divisible by 3 or 5 it will return 7 itself sospend 10 to 15 minutes on this exercise you will see my solution next all right let's see how we can solvethis problem so we get the input and check to see if input is divisible by 3then we can set a variable like result to phasenow let me temporarily simplify these rules because I want to show you areally cool technique so let's imagine if the input is divisible by 3we'll return fizz otherwise we'll return bus so elves : we set the result to buzzand finally we'll return this result variablethis is one way to implement these rules but it's not the best way there is abetter and cleaner way let me show you so instead of defining this resultvariable and then returning it we can simply return this string here and alsohere and then we can get rid of line six so we remove one unnecessary line ofcode this was one technique the other technique I want to show you is when youhave an if statement and in your if blockyou're returning a value you don't really need an else clause because ifthis condition is evaluated to false the control moves to the else clause and allwe're doing here is returning a different value so this is the onlypossible outcome so here we can remove this else clause and simply return busso with this technique I remove an unnecessary indentation as well I'vemade our code more linear okay now let's go back to our original algorithm so ifthe input is divisible by three we'll return fizz now we check to see if theinput is divisible by five we'll return buzz so here we don't really need anElif because if this condition is false we'll get here anywayso we can check if input is divisible by five we will return buzz once again ifthis condition is false the control moves here now we check to see if theinput is divisible by three and it is also divisible by five then we willreturn fizz buzz now this expression is a little bit long I would prefer to makeit more readable by putting parentheses around the first and second parts likethis that is cleaner now if this condition is also false the controlmoves here that means our number is not divisible by three or five so we shouldsimply return input once again we don't need an elseor another if we simply return the input now let's run this program and see ifit's working properly or not so we call our function with three and we get fizzbeautiful let's call it with five we get Buzz perfect what if we call it with 15we should get fizz bus however we get fees what is going on here the reasonthis happened was because when we pass 15 here line two is executedobviously 15 is divisible by three so that is why we immediately return fizzto solve this problem we need to move this condition which is more specific tothe top so I've selected these two lines using alt + up I move these lines upbeautiful all right now let's run the program one more timeso we get fizzbuzz once again let's test it with three now we get fares let'stest it with five when writing functions don't assume that your function isworking make sure to test it with all different kinds of values let's test itwith five we get Buzz beautiful what if you pass seven which is not divisible bythree or five we get seven beautiful so what you see here is the simplest andmost elegant implementation of the fizzbuzz algorithm and that brings us tothe end of this section in the next lecture we're going to explore datastructures in Python you're going to learn about lists tuplessets and dictionaries I hope you enjoyed this section and thank you for watching you you made it this far and that makes methink that you're really enthusiastic about learning Python so I highlyencourage you to enroll in my complete Python course where we go way beyondthis crash course you will learn how to use Python in real-world scenarios suchas data analysis and visualization automating repetitive boring tasks thatinvolve working with files and folders spreadsheets PDFs data compressionsending emails web crawling consuming api's and much much more this coursecomes with a 30 day no questions asked money back guarantee and a certificateof completion if you're interested click the link below this video to access thecourse once again thank you for watching please support me by liking and sharingthis video and also subscribe to my channel to get free new videos everyweek thank you and have a great day 

Post a Comment