Learn Python with Jupyter Notebook from scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the introduction for this course what you should know before you take the course you should have a basic working knowledge of using a computer you should also have a basic working knowledge of using the Internet who should take this course the course is designed for beginners to Python and Jupiter notebook also designed for beginners to coding and programming in general what will you learn on the course we'll start off by installing Jupiter notebook will then learn how to run the typical notebook server we'll learn about some common Jupiter commands we'll learn about the components that make up the Jupiter notebook will learn about exploring the notebook dashboard we'll explore the user interface within the Jupiter notebook who create notebooks we'll look at Python expressions Python statements would take a look at variables and how to create variables in Python we take a look at data types in Python we will learn how to cast data types that is how to change from one data type to another we'll learn about Python operators will learn:about conditional statements will learn about loops will also learn about Python functions the format of the course is video based and the duration is 2.5 hours long thanks for watching bye for now hello and welcome to this video what is jupiter notebook the jupiter notebook is an interactive computing environment that enables users to experiment with code and also allows users to share the code the jupiter is a loose acronym which means Julia Python and are these programming languages were the first target languages of the Jupiter application but nowadays the notebook technology also supports many other languages the notebook is a document that can consist of live code rich text interactive widgets equations video images and so on these documents basically provide a complete and self-contained record of a computation that can be converted to various formats and then shared with others hello and welcome to this video in this video I'll be showing you how to install anaconda and also how to set up the Jupiter notebook to begin open up your Google search bar and inside the search bar just type in anaconda distribution and press Enter and just select the first on the list so I'm going to click on this one here that says anaconda Python slush or distribution click on that and that will detect the operating system you have if you're running a Mac it will detect you have a Mac so I'm just gonna scroll down to the bottom here and right at the bottom it will detect my operating system so it has detected that I'm running a windows-based operating system and it presents me with the Windows installer as of the time I am recording this video the current version is 3.7 when you do visit to do your own download the version may change just download the most recent version that you see so to download I have under the windows there are two links one for a 64-bit and one for a 32-bit I've got a 64-bit so I'm gonna click on this 64-bit graphical installer so you can see here is downloading on the bottom left hand corner of my screen I wait for that download to complete and then I'll run the Installer the anaconda installer has completed downloading so that's it here so to run it I just double click to begin the installation so it's trying to launch just click on next and then click to agree and there are two ways you can install it you can install it just for your user profile which is a recommended one or you can use or install it for all users if you're going to use the all users you need to have admin privileges I just want to install it on one profile so I'm going to click on the top option which is going to install it just for me so I click Next and then it tells you the destination folder where it's going to install it tells you the space required 2.9 gigabyte and tells me the space I have got available so make sure you do have enough disk space in your designated installation directory so I'm going to click Next and I'm going to accept this option here that's been checked and I'm going to leave this one that has been unchecked it says not recommended so I'll click install to install so we just wait for the installation to complete so just gonna give it a few minutes to run through the installation once the installation is completed you will get this as completed and just click on the next button and click Next and then if you want to learn more about anaconda in the cloud you can leave that checked I'm gonna uncheck that if you want to learn more on anaconda you can leave that checked I'm gonna leave this unchecked and click finish another way you can set up the Jupiter notebook is by using the Python package manager which is known as pip this is recommended only for the experienced Python users so before you set up the Jupiter notebook using people you must make sure you already have Python installed and then you need to make sure you have the most recent and updated version of the Python package manager which is known as pip and the way you can do that if you are using a Mac if you've got a MacBook Mac comes pre-installed with python version 2.7 so if you want to upgrade people on a Mac you'll you will have to type in P 3 which means that you are referring to people three and not version 2.7 so you do P 3 on a Mac space install - - upgrade pip and that will break people if you're on a Windows based computer you don't need to type in pip three just type in pip install - - upgrade pip and that will operate to the most recent version of pip and then if you want to install the TripIt on notebook using the Python package manager you type in pip three if you're on a Mac install under in Jupiter if you're running a Windows based computer you type in pip space install Jupiter so if you are doing this on a Mac you obviously have to do that on your terminal if you're doing the installation on a windows-based computer you have to do this on the command prompt for new users it is highly recommended that you install the Jupiter notebook by the Anaconda way because if you install kondeh anaconda will also install python and the jupiter notebook so let's take a look at what anaconda has installed we go to our programs menu and look for the anaconda folder so this is my anaconda 3 folder if I expand that I can see what it has installed it install the anaconda Navigator anaconda PowerShell prompt and a condom prompt the jupiter notebook which is what we are really interested in here and then we've got these reset spider settings so we can see here by installing anaconda it also installs the jupiter notebook so that is it for this video in this video we installed anaconda and anaconda also installed the jupiter notebook for us thank you for watching bye for now hello and welcome to this video in this video I'll be showing you ways to start the jupiter notebook you can start the jupiter notebook server from the command line if you are using a windows-based computer that will be the command prompt if you using a Mac or a Linux based computer that will be the terminal so once you've got your command line opened you type in this command Jupiter space notebook and that will start the Jupiter server the other way to start the Jupiter notebook server is from the all programs menu in your windows-based computer if you go to the anaconda folder within the all programs there should be an icon there for Jupiter notebook you can run it from there as well once the Jupiter notebook server is started it opens up the Jupiter notebook in your default web browser and it does that on localhost and the port it uses a double eight double eight let's launch the Jupiter notebook from the all programs menu on our windows-based computer so if we click on our programs go to start all programs and there should be the Anaconda three folder so if you just expand it and inside there you see the Jupiter notebook so just click on this and that will start it will launch a console screen like this and then it will also launch the Jupiter notebook in your web browser so this is what the Jupiter notebook dashboard looks like once you have launched the Jupiter notebook and inside this dashboard area here it gives you a list that shows a list of notebooks files and subdirectories in the directory where the notebook server was started so if you're launching the Jupiter notebook from the all programs menu it will start from the root directory where the Jupiter notebook was installed and it also lists some directories and subdirectories from that root directory so your directory listing will be different from mine depending on what you've got in your specific directory where the Jupiter notebook has started inside the root of your directory most of the time you can start a notebook server in the highest level directory that contains notebooks all right with this basically is going to be the root directory and can also be the home directory if you are on a Mac or space computer you can also specify the directory that you want the notebook to start from and you do that by using by starting the Jupiter notebook server from the command prompt while the jupiter notebook is running inside the console area here so if you look at look at the terminal interface here they come online it gives you a lot of information here it tells you where the notebook is starting from so it's serving the notebook from the local directory which is on my C Drive on that the users directory and then on that the profile administrator alright and then it tells you where the Jupiter notebook is running at in the web browser which is localhost colon double 8 double 8 to shut down or exit the Jupiter notebook server he goes to control dash C on your keyboard and that should shut down the Jupiter notebook server once you shut down the Jupiter nobu server you will not be able to access the Jupiter notebook on the web browser you can see here because I've shot the server down you can see here is not able to contact the server I have shown you how to start the Jupiter local server from the programs menu on a windows-based computer which opened up the console and also opened up the notebook in your web browser on localhost colon 8080 8 8 I'm not going to show you how to start the Jupiter notebook from the command line which is the command prompt on a windows-based computer but the process is the same on the terminal notice that when you start the Jupiter notebook from the Anaconda folder within the all programs menu it will start up from the root directory of your profile where the Jupiter notebook was installed when you start in from the command line you can specify where you want it to start from I've got a project directory here it's an empty directory I'm going to make the Jupiter notebook start from this project directory so to do that I go to all programs and inside the anaconda folder we've got the anaconda prompt so this is what I'm going to use so I click on the anaconda prompt and our wait for it to launch so you can see tells me the base which is so this is the default where the jupiter notebook will start okay unless you change it I want to change that to my desktop so I do CD desktop I press enter and I do CD there's a folder called projects on my desktop so I'll just just CLS to clear the screen so now I have navigated to this folder here called project that's why I want to start the Jupiter notebook so I just type in Jupiter space notebook press ENTER and it will start the Jupiter notebook in cities trying to start it you can see here because there's nothing in that root directory that's why you can't see any sub directories here because the actual directory is empty all right now you can see here told me where the Jupiter notebook is being served from it tells you the path the directory path always a good idea to pay attention to what's going on in the console in case there's anything that you are not sure with or if it doesn't work the way you expect it all right so running the Jupiter notebook from a specified directory is also useful for project based stuff so that if there are certain things you want to keep in a specific directory then you can serve the Jupiter notebook server from that directory in this video I showed you a couple of ways of starting the Jupiter notebook born from the command line where you could specify a directory for the ipython notebook to be served from and I also showed you how to start it from the anaconda folder within the or programs menu of your windows-based computer when you start it from the anaconda folder there is a jupiter notebook icon that you can run and by default it serves jupiter notebook from the root directory of your profile and when the interpreter notebook opens up it opens up in your default web browser on localhost colon 8080 8:8 the port number double eight double eight so that's it for this video on running the jupiter notebook server thank you for watching bye for now hello and welcome to this video in this video I'm going to show you some common and useful Jupiter commands all Jupiter commands are prefixed with the keyword Jupiter before the subcommands are issued the Jupiter keyword basically is the primary namespace for all sub commands let's take a look at a table showing some common Jupiter commands so this is a table here and we have some useful and commonly use Jupiter command first one here in the table is the command to start the Jupiter notebook you just type in Jupiter space notebook and that will start the Jupiter notebook application if you want to see all the available commands that Jupiter has and you want some information as well you just type in Jupiter space dash dash help and that will show you the available commands that Jupiter has if you want to see the location of the configuration directory you type in Jupiter space dash dash calm - dir if you want to see the location of the data directory you type in Jupiter space - - data - dir if you want to see the location of the runtime directory you type in Jupiter space - - runtime - the i/o if you want to show all the Jupiter directories and the search paths you type in Jupiter space - - path if you want to print out the directories and search paths in a JSON format you type in Jupiter space - - JSON so let's open up the command prompt in anaconda and show you how these commands work I'm going to illustrate how these commands work so in my Windows computer I'm going to go to all programs and I'm going to look for the anaconda 3 folder which is this folder here I'm going to expand that and I'm going to select the anaconda prompt I'll click on that and I should open up this console this Seminole if you're doing this on a Mac or a Linux based computer you can just do this on your terminal so you can see essays base that is the base directory as where the Jupiter notebook application will start from so if I want to start the Jupiter notebook application and I do not want the web interface to show this is the command I will type or typing Jupiter space notebook and they do a space - - no - browser well that means it will start the Jupiter notebook but it will not show me the browser interface or press ENTER and that should start the Jupiter notebook in this base directory but even though it gives me the location of the web browser interface it will not launch it because I've said I don't want the browser to display to shut down the server you just type in control - C and that will stop the server so let's stop the server now that we have issued these commands I just do control C and that will stop the server okay so you can see I've done a control C it has shut down the server alright so I'm just going to clear my screen by typing in CLS so that I can type in more commands the next command I want to type in is the help command so if I want to see the available commands on some information I just type in Jupiter space - - help if you don't want to type in help you can type in - H that will also do the same thing and press ENTER you can see here it gives you some information about the Jupiter notebooks it tells you you say here Jupiter interactive computing and gives you some optional arguments all very useful information and to clear the screen again type in CLS so that I can type in more command the next command up into typing is to show the location of the configuration directory so I just type in Jupiter space and it will be - - config - d.o.a press ENTER and that shows me my configuration direct the next command I want to show the location of the data directory so type in Jupiter space - - data - dir and press Enter you see that shows me the location of my data directory if I want to show the location of the runtime directory our typing Jupiter space - - wrong time - dir press ENTER and that gives me the location of the runtime directory if I want to show all the Jupiter directories and the search path I type in Jupiter space type in - - path with an S and press Enter and that will show me all the paths okay it shows me the location of all the Jupiter directories and their search path you can see it's listed quite a few the final command I am going to type in is going to be a command that will print the directories and search path in machine readable JSON format so to do that type in Jupiter again space - - J Sun and press Enter you can see here is giving me the path so in this video I've shown you some commonly used Jupiter commands thank you for watching bye for now hello and welcome to this video in this video we will take a look at the components of the jupiter notebook the jupiter notebook application is a client-server application a client-server application basically is a distributed application structure that partitions task or workloads between the providers of peer resource or a service which are usually called servers and the service requesters which are usually called clients so the server which is represented by this box here is the resource provider and then we have the client in terms of jupiter notebook that could be your web browser because the jupiter notebook also has a web component which is a web browser which will act as the client to the server so the client will be requesting services from the server which is the provider of the resource in a client-server application you can also provide resources to other clients and clients can include other computers it could be remote and you can access the server which can be remote over the internet using different types of client like your mobile phone your laptop or your computer device the main components of the jupiter notebook include the notebook web application we also have the kernel and then we have the notebook documents so let me give you a brief description of each of the components of the jupiter notebook the first is the notebook web application this is basically an interactive web application that you can use to write and run your code interactively you can also use it to all four notebook documents ii jupiter notebook component is called the kernels the kernels basically are separate processes started by the notebook web application and it usually runs in the users code and it runs in a given language the default language is Python but he can run in other languages and what it does it returns the output from the notebook web application back to the notebook web application and the kernel basically handles things like complete computations for interactive widgets tab completion introspection and other bits and pieces so the kernel basically interacts with the notebook web application the third component is called the notebook document the notebook document is basically a self-contained document that contains a representation of all the content that is visible inside the notebook web application this includes the inputs you have and also the outputs which are produced from the kernel okay it also includes narrative text equations images you can also include videos rich media representation of objects and each of the notebook documents has its own kernel so there is a kernel for Python there's a kernel for other programming languages as well so that's it for this video in this video I just gave you a brief introduction to the various components of the Jupiter notebook thank you for watching bye for now hello and welcome to this video in this video we are going to take a quick look at the notebook dashboard to begin we have to start the notebook server so I'm going to be doing this on a Windows 10 machine so in the all programs menu I've got to look for the Anaconda three folder which is this folder here and in there there is an icon here for jupiter notebook if i click to run this icon it will start up the jupiter notebook server from the root directory where it was installed if i don't want to start it from the directory way it was installed I can use this anaconda prompt command and then specify a directory where it should be started from but for this video I'm going to start it from the default which is where it was installed so I'll click on the icon for jupiter notebook and it will launch this jupiter notebook interface you see it launches the web browser and it also launches this here so from here you can see where the jupiter notebook is running at it tells you serving the notebook from this local directory which is see users administrator and it will list everything in that directory inside the dashboard so let's take a look at the dashboard so this is what the jupiter dashboard looks like when you first start up the notebook server your web browser will open to this notebook dashboard the dashboard basically will serve as a home page for the notebook its main purpose is to display the notebooks and the files in the current directory for example the current directory is showing here is this directory sees large users like administrator and it will list what is got in that directory which it is listed here yours will be different from mine because what you've got in your directory will obviously be different from my directory okay and then we've got the breadcrumbs at the top here at the top of the notebook list here it will display clickable breadcrumbs these are all clickable breadcrumbs of the current directory by clicking on these breadcrumbs or these subdirectories in the notebook list you can navigate your filesystem so if you want to see any of these yet just yeah you can see they are all clickable links to their respective directories ok if you want to see what's running in the dashboard you click on running and it shows you what about is running at the moment you can see there's no terminal running there's no notebook running also if you want to upload you can click here to upload files and so on tells you here when the these sub directories were last modified they still need to named arrow here basically is used to sort the list the directory sub directories in this list here you can see the arrow is pointing down which means it is sorting them in alphabetical order if you want to sort it the other way say from Z to a you can see the arrows gone up and it's flipped it and sorted it from z to e so I'm going to put it back and then you can see here this is just referring to the file size if you want to quit the dashboard you can click on quit or you can click on logout I'm going to quit logout and that are successfully logged me out of the dashboard ok and then if I want to quit the server I just type in this command here ctrl C and that will quit the Jupiter server so that is it for this video thank you for watching bye for now hello and welcome to this video in this video we are going to take a look at the notebook user interface when you create a new notebook or when you open an existing notebook you will be presented with the notebook user interface this user interface allows you to run your code although your notebook documents interactively the notebook user interface has three main areas we have a menu we have the toolbar we have the notebook area and the cells I have got my dashboard open and I have got one notebook inside my dashboard at the moment the notebook is not running so to run it I'm just gonna double click on it and that will run the notebook so you can see here the notebook is running it has now presented me with the user interface so I'll start with the menu bar this area here is known as the menu bar and the menu bar has menus for actions on the notebooks the notebook cells and the kernel it communicates with the file here basically is you can use this file option inside the menu you can use that to change the file name for the notebook and then you've got the Edit you want to edit and go to view you've got insert allows you to insert cells a bowl or cells below this here is called a cell ok this border area here is called the cell where the code is and then you have the kernel which is running at the moment we've got widgets so you can save the notebook the state of the widget you can clear the notebook which you can download the widget and so on and then you've got the help menu ok so that it is but this area here is known as the menu bar and then we've got here this line here is called the notebook toolbar period ok the toolbar has several buttons for the most common actions so if you want to see what each of the buttons do just hover your mouse over each button for more information for example if i overlay tells you that is a safe and check point and that tells you that's inserting a cell this is cut selected cell copy selected cell paste and this says move selected cells up move select a cell down this enables you to run the cell this interrupts the kernel this one restarts the kernel with a dialogue and this basically restarts the kernel the notebook has mood indicators mood indicators basically indicate which mode the cells are if they're in edit mode or if they are in command mode you can tell that in command mode if he's got a blue strip around the cell so if you click here if I click on this now if he's got a green strip around the cell it's in edit mode so you can see here this icon here tells you it is edit mode if I click outside the edit mode you can see now this is showing as the command mode so it's very important to know that there are two mode indicator which you can identify by the colors around the cell so if you got a blue color around the cell that's a command mode which means you can issue command if you've got a green strip around it you are in the edit mode which means you can edit the previous code you've got in the cell also here inside the toolbar area we've got this icon here which is a command palette so if I click on that it gives you the command group so if you want to use shortcuts for setting things you can do that from here all the navigation and actions in the notebook interface are available using the mouse through the menu bar and the toolbar which are both inside the notebook area so that's the menu bar and this is the toolbar so you can use the mouse to navigate through the various actions you want to perform to select a cell with your mount you just click on the cell and that selects it and if you want to change the mode for example the mode at the moment is edit mode you just click outside the cell and it changes the mode to the command mode so that is it for this video in this video we took a look at the notebook user interface thanks very much for watching bye for now hello and welcome to this video in this video we are going to be creating a new notebook before we create the uniboob I just want point out a few things a notebook will have the file extension dot ipy and be also a notebook consists of three basic type of cells they are code cells which will include the input and output of the live code Tyrone's in the kernel and then we have the markdown cells which are narrative text that contains embedded latex equations we also have the raw cells which include on formatted text also notebooks can be exported to different static formats which include HTML and PDF before we can create a new book we have to start the server so the jupiter notebook server i'm going to start it from a specified directory i've got a directory on my desktop called my notebooks is an empty directory at the moment but this is where I want the Jupiter notebook server to start from and any notebook I create will be inserted inside this directory so to begin I go to my terminal I look for my anaconda folder and then I'll click on this that says anaconda prompt this will give me the prompt which will give me the default location for anaconda and I'm going to change that to start from my desktop and on my desktop I'm going to change directory to a folder called my notebooks alright and I'll just clear the screen so now I'm in the directory to start the Jupiter notebook server I just type in Jupiter space notebook and that will start the Jupiter notebook server in that directory I have specified alright so is trying to launch the Jupiter notebook so this is the dashboard and you can see the dashboard here this is the root directory of the this directly on my desktop here that's what the Jupiter notebook dashboard is pointing to it's empty at the moment because they there is no notebook list there's nothing in that territory so to create a new notebook there is a new option that is new you click on this new button at the top here and all these are called kernels so whatever colors you see here depends on what's installed on the server alright so these are my available kernels and I'm going to click python 3 because i want to create it in Python 3 so it's going to open up a new cell this is what is called is and if you see here the default cell is a code alright and if I click on the drop down you can see the other time there's a mark down and there's a row and be convert but we're going to leave the default which is code so I'm going to click on it and this is where you can write a live code so I'm just going to type in print and just say hello wall so I've just typed in a simple print statement that's going to say hello world and to run this cell you can click on the Run button here or you can do you can do shift and enter okay so I'm going to click run and that will run the cell you can see here it has given me the output of that cell so we notice here the notebook is untitled at the moment so I need to give it a name to do that you double click on it and I'm going to call it hello world and then I'll click on this rename button you can see the name of the notebook has changed if you want to see the notebooks that are currently running you can click on your home screen here and you can see this is running you can tell that it's running because it's got this green icon next to it I've only got the one notebook at the moment but it's possible to have multiple notebooks running at the same time also while the notebook is running there is a box here you can check if you check on it it gives you some options you can duplicate the notebook you can shut it down you can view you can edit and you can also delete so I'm just going to uncheck that box but you see those options when you have the box checked if you have it on check the options disappear if I take a look at my project directory on my desktop you can see here that it has saved the notebook this is the notebook here with the extension IP Y and B it has saved into my projects directory if you have other notebook files you can also upload them using this upload button or you can just drag them into the notebook area here in the dashboard the notebook shows the green icon when the notebook is currently running and notebooks remain running until you explicitly shut them down closing the notebooks page is not sufficient to shut the notebook down so if you want to shut it down you click on this check there and then there is an option to shut the notebook down notice I've shut it down and the icon now is no longer green so that is it for this video in this video we created a new notebook thank you for watching bye for now hello and welcome to this video on what is Python Python is a general-purpose programming language this means it can be used to write computer programs for various things like games data science websites and so on Python is also a high-level programming language high-level programming languages mean that the languages of writing computer instructions in a way that is easily understandable and close to human language Python is portable which means we can run Python programs in the various different operating systems like Windows Mac OS Linux without any changes python is an interpreted language Python is called an interpreted language because it goes through an interpreter which turns code you right into the language understood by your computer's processor Python is strongly typed strongly typed languages don't convert data from one type to another type automatically python has a huge set of libraries a Python library is a collection of programs you can incorporate into your own program without writing code for them let's take a look at a list of application types you can create with Python web applications these are applications you can access using a web browser Android applications these are applications that runs on Android devices like Android phones and tablets games you can create various types of games with Python scientific applications you can create various types of scientific applications with Python system administration applications so you can use Python to create applications to monitor various types of systems you can also create console applications a console application basically is a computer program designed to be used by a text-only computer interface let's take a look at a list of software applications that have been created using Python so some of these are quite famous and popular first on the list is YouTube and then we have Google we have Dropbox this program lets you save files to a cloud-based service that you can then access from anywhere in the world we've also got reddit reddit is one of the biggest open communities on the web you have a question you want to talk about something in specific or if you want to find tons of information regarding a particular topic for example gardening or anything you can just look on Reddit and find related information next we have Spotify Spotify allows you to listen to add free music of your choice this is streaming service that allows you to stream music without any advertisement finally we've got Instagram Instagram is very popular it has both an app side and also a web site as well these are just a few list items of software that were created using Python there are so many others but these are just some field that you may have come across so that is it for this video on what is Python thanks for watching bye for now hello one welcome in this video I will introduce you to high low level programming languages what are high level programming languages these are languages that only humans and understand so computers can't understand them unless they are compelled or interpreted they need an interpreter or a compiler for the computer or the machine to understand what the programming is trying to get it to do examples of high level programming languages include Python Java C sharp C++ PHP Ruby and there are many others what are low-level programming languages these are languages that only machines can understand they do not need an interpreter or a compiler they are closer to the computer hardware examples include machine and assembly language this is a brief illustration of high and low level languages so you can see the nearer the language is to the hardware of the machine the far site is and it doesn't need to be interpreted because it's so close to the computer hardware whereas the further away it is like we've got these low here they are further away from the hard way so they need they're easier for programmers to understand because they contain English related words but not machine to understand so for the machine to understand what this block is saying it needs to be converted into machine code using a compiler or interpreter a differences between high-level and low-level programming languages high-level languages are easier to learn low-level languages are more difficult to learn high-level languages are near to human languages as easy to read like basic English while low-level languages from from even languages so only machines know what they are talking about you need a translator like a compiler and interpreter to convert a high-level language into machine language you know translator is needed for low level languages called the machine hardware knows what they're talking about programs written in high-level languages are slow in execution because obviously they have to compile or interpret them our program developed in low-level languages are much faster in execution because there is no compiling or interpretation going on the hardware understands the language so it's easy or easier to execute the instructions so these are the key differences between high level and low level programming languages thanks for watching and bye for now hello and welcome to this video in this video I'm going to introduce you to compilers and interpreters what is a compiler a compiler is used to translate the entire source code into machine language before the code is executed so basically what that means is that the computer for the computer to understand what is you're trying to get it to do you have to use a compiler to compile or translate convert your code into a code that the machine can read alright examples of languages that are compiled with languages you have to compile before the code is executed clothes c and c plus plus so let me illustrate how the compiler works so let's say you have your source code and your source code is basically your computer code that you're right so let's say inside the source file you have this you've got x equals 7 y equals 8 and then the sum is equal to X plus y and then you want to print the value of the sum using the print function now the computer will not understand this so what needs to happen you need to use the compiler to convert that code into machine code the machine code is something like this computers only understand zeros on one so the compiler compiles it into machine code and then it executes the code it then passes it on to the computer memory and the computer memory then outputs the result in this case which is 15 so that's basically how a compiler works compiler will compile the entire code into machine code before it passes the information to the CPU to display the result what is an interpreter an interpreter does a similar job like a compiler the key difference with interpreter is that the interpreter will translate or convert one line of code at a time okay into machine language before the code is executed examples of interpreted languages include Python and Perl so let me show you an illustration of how an interpreter would work so let's say you have your source file and you have this of code inside the source file at this stage the computer would not understand that so for the computer to be able to interpret what you're saying you need to use an interpreter so the way the interpreter works is that it will convert a line at a time so for example it would do x equals to seven compile that and run it you'll do y equals to eight it will translate or convert that and then run it it does line by line in comparison to compiler that compiles the whole code into machine code before it executes in case of a interpreter it does it line by line and then eventually it will produce the result this is a brief table that illustrates some key differences between compilers and interpreters compilers basically would transform the entire source code while interpreter will transform line by a line of the source code the compilers will generate a machine code first before it executes the interpreter does not generate any machine code the because compiler generates intermediate machine code it uses more memory the interpreter uses less memory compiled languages run once so once you've compiled it you can run it anywhere because it's already been compiled while the interpreter the source code has to be interpreted each time you run the file the compiler basically is more difficult compared languages because is did more harder to find problems or debug issues while the interpreter is much easier to debug the compiler is faster and the interpreter is much slower so these are some key differences between compilers and interpreters so that's it for this video thanks for watching bye for now hello and welcome to this video in this video we are going to take a look at Python expressions an expression is anything that has a value for example the number 3 4 + 5 and the string hello texts are referred to as strings in Python an expression can contain operators like the plus operator I can also contain upper hands for example in the example 4 + 5 4 is the upper hand also 5 is an upper hand while the plus is known as an operator I've got my notebook dashboard open I'm going to create a new notebook so here in this area here I'll click on the drop down for new and I'll select Python 3 which is going to interpret and I'll give the notebook a name I'll double click on it and I'm going to call it Python [Music] expressions and I'll click on the rename button to rename it so it's now same Python expression so you can see I've got a blue strip which means I'm in the command mode inside the cell so I'm just going to issue a simple command I'm going to say 3 plus 4 and to run the cell I just click on run cell or you do Shift + Enter so I click run and that gives me the output of 7 let me enter another expression I'll do 7 times 2 and I run the cell click on run and that gives me a value of 14 let me enter a string expression this time so a string which is known as a text has to be enclosed in quotes you can either enclose it in double quotes or single quotes but you can't mix the quotes so say hello well run the cell I click on run cell and it gives me the output hello world in these example expressions here the 3 here is known as an upper hand the plus is known as an operator the 4 is also called an upper hand alright and here also in this second cell we've got the 7 has an upper hand the Asterix represents multiplication in Python which is known as an operator the 2 is an upper hand and in this cell here we've got a string value which is basically a text so in order for Python to understand that this is the text you have to enclose it in quotes so on either side of the text so you can have either single quotes on either side or double on either side you can't mix single and double quotes in this video I gave you a brief introduction to Python expressions thanks for watching bye for now hello and welcome to this video python statements are basically a set of instructions that you give to the computer to perform a task or a series of tasks Python statements can contain one or more expressions it can also be on a single line or it can consist of multiple lines to illustrate examples of Python statements I'm going to create a new notebook so on the new here I'll click on the drop down I click Python 3 Python 3 contains the Python interpreter that will interpret the code who write into a machine readable format that the computer can understand so I'll click Python 3 and I will just stop click to give it to give it a name so I'll change the name to say Python statements and I'll click rename so this notebook is going to be called Python statements so you can see we've got a blue strip here which means I'm in the command mode so I'm going to start up with a single line statement it's gonna be a simple expression I'm going to say 9 times 9 and I'm going to run this cell by clicking on the Run button and that gives me 81 so this is known as a single line statement because this statement all the instructions is just on one line so depending on what you want the computer to do you can have a statement that consists of several hundred even thousands lines of code depending on the task you want the computer to perform so I'm going to give you an example of a multi-line statement so I'm going to use a for loop so I'm going to say for I in range and a range is basically an inbuilt function in Python which you can use to specify a range so I'm going to say 13 I'll specify the range and then I will add the colon the colon is very important it creates an indentation level so if I press ENTER you can see here it's giving me an indentation level so I can add another line of statement I'm going to add a print function so I'm going to get it to print the value of I so let me click to run the code you can see he has printed out from zero to 12 all right so when you specify a range the first numbers usually is zero okay hence it has not printed out 13 because zero here represents the first range okay so this is an example of a multi-line statement because this statement is on two lines let me explain what this code is in this cell number two here the four basically is used to iterate over a range of values so here I'm saying this 4 is going to be used to loop through a range of 13 numbers a sequence so the eye here is going to be what is going to store the value so I say for I in range range basically is a inbuilt function in Python so way basically using this for loop to look through this range and we're going to print out each value of this I so I here contains all the values so what is going to do the first value is going to print is going to be 0 so it prints from 0 to 12 which gives it 13 values okay so that's basically what that code is doing in this video I gave you a brief introduction to what Python statements are so a statement can contain one or multiple lines of code depending on the task you want the computer to perform thanks for watching bye for now hello and welcome to this video python comments can be very useful they can be used to explain your Python code to yourself and to others also comments can be used to prevent execution of code when you are testing your code so you may have certain aspect of your code that you don't want to run during execution to achieve that you can add comments to that aspect of code which prevents the execution of that code so this can be very useful during testing purposes there are two main types of comments in Python we have a single line comment and a multi-line comment so the single line comment is represented by the hash symbol while a multi-line comment you can hide are represented by three double quotes on either side of the code you want to comment or you can have three single quotes on either side of the code you are trying to comment I've got my Jupiter dashboard I'm going to create a new notebook so on the new your click Python 3 and I'm going to call this notebook Python comments and then I'll click rename inside the cell I'm going to issue out a simple print function here and I'm going to get it to print out the text hello old and next to it I'm going to add a single line comment which is represented by this hash symbol when the comment is on the right hand side of the code it does not affect the code running but when you place the comment in front of the code it will affect the code so if I click run here it will give me the output because the comment is on the right hand side so notice in the second cell here I have placed the comment in front of the code notice that's commented out all of the code so it will prevent this code from being executed so if I click on the Run button you see nothing gets executed because of the comment so be very careful where you place your comment you place it in front of the code it will comment out the entire line but if you place it on the right hand side as we've done in cell number one it does not affect the code from being executed so these are known as single line comment so let's give you an example of a multiple line comments so to do that you do trees quotes on either side all right so you can press Enter so you either have three double quotes or three single quotes you can't mix the quote and then any text that is enclosed between these quotes will be commented out and the code will not be executed in this cell here we've got a multi-line comment because it spans multiple line this is one line this is another line so we can see that the multi line is enclosed by these quotes so we have three double quotes before and three double quotes and I notice it has turned all the text in between the quotes red which means that when I run this cell those lines of code will be ignored the only line that will print is this print function here that says hello wall so if I run this cell by clicking on the Run button you can see here is printed out hello world and it has ignored this here which is the multi-line comments so comments are very useful in Python they help you explain what your code is doing and also can help you comment out setting lines of code if you don't want those lines of code to be executed so that is it for this video thank you for watching bye for now hello and welcome to this video there are three basic data types in Python we have the numbers data type this basically includes integers which are known as int and floating-point numbers which are known as float and integer basically is a whole number and a floating-point number is basically numbers that includes decimal we also have the string data type which basically is a text or a sequence of characters it's also referred to as STR and then we have the boolean data type which is a true or false value is also known as the bull you can get the data type of any object by using the type function in Python so basically you pass in a value in between the parentheses and this type function will return the type of data type so let's create a new notebook and experiment with some data types so I'm going to create a new notebook so I'll come here say new click on Python 3 and I will give the notebook in name and I'm going to call it Python data types so we're gonna experiment with the basic data types in Python I'm going to use the type function to enable or detect the type of data type it is so I am going to start with an integer which is a whole number so I'll do the type command and inside this type function I'm going to pass in a value which is 80 so 80 is a whole number so I click on this wrong command you see here it has returned that this type of data is an integer so an integer is a whole number you can also include negative numbers so if I type in do a type and inside that type function by passing negative 30 and run it also return an integer because they can contain both positive and negative values so let's try and get a data type that is a floating point a float is basically a number that includes decimals so we do the type and inside this function with two 28.5 and run this cell you can see it does return a float you can also have a negative float value as well so if I do type and in between are doing negative one point zero and do a run it also returns a float next let's try and get his string data type so we'll do it type remember with a string you always have to include the values in quotes so I'm just going to say hello and I do a run you can see here it has returned that this is a string data type which is specified by the word STR next let's do a boolean data type so I'm going to do a type and inside this type function I'm going to say 7 is greater than 6 and this should return a bool value which means it is true I'll click run you can see it's returned a bull if I do it the other way I do it type and say 7 is less than 6 it will also return a bull value because 7 is not less than 6 so it would be a false value which would be a bull so if I click run you can see here it has returned a bull value data types are a very important concept in Python so when you have to store in variables is good to know the type of data type you are storing so that is it for this video on basic Python data types thank you for watching bye for now hello and welcome to this video what is casting casting basically is the process of converting from one data type to another data type there are several functions that you can use in casting for example if you want to cast a value that is in a different data type to an integer you use the int function if you want to cast to a floating-point number you use a float function and if you want to cast to a string you use the STR function let's create a new notebook so I'm going to click on the drop-down click Python 3 and I'm going to give this a name I'm going to call it costing data types and I'll click the rename button so let's cast a value that is a float into an integer to do that we're going to use the int function so type int int and inside that int function I'm going to pass in a value that is a floating-point so I do 2.8 and I'll run this cell you can see here it has returned two which is a whole number and an integer is converted the value of 2.8 which was a floating-point into an integer data type so let's try and convert a whole number into a floating-point number so we're going to have to use the float function and inside the fluid function I'm going to pass in a whole number which is integer so let's passing 40 and then I'll run that you can see here is converted it to 40 point 0 which is now if floating-point number next let's convert an integer into a string so to do that I'm going to use the STR function and we're going to pass in a value that is a whole number so let's pass in value of 3 now if I run this it will convert this into a string datatype so I click on run you can see here it's converted into a string because it has quotes on either side anything with quotes on either side is treated as a string so that's basically how casting works so that's it for this video thank you for watching bye for now hello and welcome to this video what are variables variables are named containers for storing data values unlike other programming languages Python does not have a specific command for declaring a variable in Python a variable is created the moment you assign a value to a named container there are a few rules that you need to know before you create variables in Python a variable name must start with a letter or the underscore character the variable name can contain alphanumeric characters and the underscore character so you can contain from characters a to Z numeric from 0 to 9 and be on the score character a variable name cannot start with a number also variable names are case sensitive so for example if you declare variable called name with uppercase n and you're trying to access that variable with lowercase n you will get an error another important rule is that you cannot name your variable names after Python key words there are certain key words that are reserved for the Python programming language which you cannot use as variable names on the screen here have got a list of some reserved words in Python they are called key words so these are key words that the programming language actually uses so when you create a variable you cannot use any of these words listed in this table let's create some variables so first I need to do is create a new notebook so I'll click on the drop down and click Python 3 will give the notebook in name and I'm going to call it Python variables I'll now click rename and that will rename it to Python variables so let's create a simple variable the first thing you need to do is have a named container so I'm going to create a variable so name is going to be the container so to the moment you assign a value to the name container that's when it becomes a variable so the name container in this case of call it name and you use the equals to sign to assign values to variables so I'm going to because this is going to be a string I'm going to enclose the value in quotes all right so I've just created a new variable and I assigned it a value of blue line so if I click run nothing will happen because the value is stored inside this name so if I want to retrieve the value inside this variable what I can do I can come here and say print and I'll pass in the name remember the variable names are case sensitive so I have to reference it in lowercase because I created the name in lowercase so now if I run the cell you can see here is return the value you can also change the value of a variable container just by referencing the name of the variable so if I can come here I'll call the variable again and I can change the value say for example I want to call the variable I change the name from blue lime to Jack and I tried to do a print statement again and pass in the name of the variable which is name it will now return Jack so even though you've assigned a value to a variable you can always change what the variable stores just by reassigning the value let's create a couple more variables here so I'm going to create another one I'm going to call this greetings and I'm going to assign a greeting to it so I'm going to enclose the value in text I'm gonna say hello world all right so that's gonna be the value that this variable called greetings is going to store so I'm gonna run it nothing will happen so each time I want to reference this variable I can just call it by its name if I call it greetings and return and click on the run you can see here it has returned the name what it's told okay if we want to return it without the quotes we can wrap that into a print function and inside the print function we just call the name of the variable which is greetings and run you can see printed out without the quotes around it I've noticed have spelt being world wrong so if I want to fix that all I need to do is called the variable by his name which is greetings and I'm going to fix that by changing that so say hello world and just run that so now if I call this variable inside a print function it will then print out hello world let's create one more so I'm going to call this variable new underscore yeah and I'm going to give it a value of 20 20 because this is a numerical value you don't need to enclose the value in quotes I'll click run so now if I want to access the value of this variable I just call the variable by its name which is new on the score yeah and click run you can see it gives me the value that is stored in that variable container with some programming languages you have to specify the datatype for a particular variable before you assign it Python doesn't do that Python you can just create something and just assign a value to it in this video I introduced you to variables in Python and we also created a few variable examples thanks for watching bye for now hello and welcome to this video what is a Python list a Python list is a collection of data that can be of mixed data types unlike variables that can only store one value in a container a Python list can store multiple values inside Tayna each item in the list is separated by a comma and you can create a list by using square brackets for example you can create a list called fruits and you assign the values or the items for that list inside square brackets and you separate each item by a comma you can access individual items in a list by the index position so the first item is always index zero the second item in a list is index one and so on also you can change the order in which an item is positioned in a list by changing the index position let's create a new notebook so I come here dove new Python three and I'm going to double click and give it a name I'm gonna call it Python list I'll now click rename so you can see here we have an inner book called Python lists so let's go ahead and create some lists in this cell I have created a new list called animals and have assigned some values or elements to the list if I want to access any item or elements from the list I will have to do that using the index number so the first item on the list will always have an index of 0 the second will have an index of 1 and so on to access an individual item from a list you do that using the index position so you can see here in this cell I'm using the print statement to print out the index of the item one so that is going to be dog because the first items going to be zero so if I run this cell you can see here is printed that dog has the first index okay the first index is zero but the item with the index of one is dog you can also have negative indexing negative indexing means you can access an item from the end of the list using a negative so if you're doing a negative one that means you're accessing the very last item in a list if you're doing a negative two you're accessing the second last item on the list you can see here accessing negative two which means I expect it to return penguin so if I run this now you can see it has returned penguin I'm creating another list here in this cell called fruits and is got three items in this list so I'm just going to run the cell to create it to access an item from the list you just reference the index for example here I want to access the fruit called cherry I just call the name of the list and passing the index by clicking run you can see here it has returned cherry if you don't want the quotes in close just to a print statement and wrap it around a print statement like I did here in this cell number two that will return the item without quotes another thing you can do you can change the value of an item in a list for example the list called fruits I want to replace the value of apple with orange all I need to do is reference the name of the list passing the index of all I want to change which is zero zero is Apple and then assign a new value which is orange so if I run that that will change that if now call the name of the list should no longer have Apple listed you can see the position of Apple has been replaced by orange you can also add items to a list by using the append method so in this cell here I'm going to add Apple to this list so you do that using the append metal so you call the name of the list which is fruit dot append and inside the parentheses for that method you pass in the name of the item you want to insert and normally that will add that at the end of the list so if I run that it will add that to the list so if I now call the name of the list we should have Apple listed at the end here I'm creating another list here with mixed data type so you can create a list that has a mixture of data types and you can also have a list include on the order list so in this list here called mixed on the score data inside the items I've got a string I've got an integer I've got a float I've got a boolean and I've got a list see this list here created your call fruits I'm adding that to this new list so let me run that and that creates it so if I want to access an item for example if I want to access the integer from that list so I reference the name of the list which is mixed data and I pass in the name the value or the index of the integer is one which is 47 so if I run that now that gives me the value you can also remove items from a list now there are a few ways you can do that you can use the pop function so you call the name of the list in this case fruits dot pop and inside the parentheses you pass in the index of the item you want to remove from the list so in this fruits here in deck number three is going to be Apple if you don't supply the index it will automatically remove the last item from the list this is the second way you can use the remove method I've commented that both because I only want the first method to run so you can do it fruits to remove I'm passing the value of the item you want to remove you can also use the Delete key you do de el fruits and then you pass in the index of the item and that will also remove it from the list but in this example I'm only going to use the pop method so I'm going to run this cell and you can see here it tells me it has removed Apple from that list so if I type in fruits I run the cell you can see Apple is no longer list another thing you can do is look through a list and you can do that using a for loop so in this example here I'm saying for X X is going to represent each item in the list so I say for X in the list called animals I wanted to print X so to print all the items if I click run you can see he has printed out all the items in the list another thing you can do is check the length of the lists if want to find out how many items around the list this is the function there is a function called Len so because I want to print it out I'm wrapping it inside this print function and inside the Len function you pass in the name of the list so if I run this now he gives me 8 tells me that that list called animals has 8 items in it another thing you can do is clear or empty a list to do that there is a special function called clear so this is a list I want to empty called fruit so you do fruit store clear you have the parentheses you run that and that should clear the list so if I type in fruits now it should return an empty list you can see it's returned an empty list so that is it for this video in this video we'll learn about a Python list thanks for watching bye for now hello and welcome to this video what is a Python tuple a tuple is a collection of data that can be of mixed data type in Python a tuple can store multiple values in comparison to a variable that can only store one value each item in a tuple is separated by a comma you can also create a tuple using parentheses for example you can create a tuple called fruits and then use the equals two to assign values to be tuple which are placed inside parentheses to access the individual items in a tuple you do that by their index so the very first item will have an index of 0 second item will have an index of 1 and so on also one very important distinction between a tuple and the list is that a tuple cannot be changed once you have created that you can't add items to the tuple and you cannot remove items from the tuple it is immutable let's go ahead and create some tuple so in this cell here I'm creating a tuple called animals I'm using the equals 2 to assign values to teachables and the values are placed in between the parentheses so I'm just going to run the cell to create the tuple so to access an item from the tuple you use the index of that item for example if I want to access this item called goat this will have an index of three because the first item has an index of zero one two three so all I need to do is come here and call the name of the tuple which is called animals my square bracket passing the index of the item so if I run that that gives me goat you can also use negative indexing to access the values of a triple negative index basically will access the item from the end of the list so here accessing negative one which means I'm accessing the last item from the list which is tiger so if I run this you can see he has given me the value of tiger you can also specify a range of indexes to be returned from a tuple by specifying where to start and where to end the range so in this example here I'm using a print function to print out items from the list so I'm using a range so all I'm saying that I want to print from index two to five so what I will do it will start the search from index number two which is giraffe and it will end it before index number five it will not include index five so it will give me the index number two which is giraffe and index number three which is good index number four real part but it will not give me index number five which is lion so if I run that you can see he has given me cure of good hanley apart you can also use negative indexing on a range once you create a tuple you cannot change or that means you cannot add to it neither can you change the values so in this cell here if I try to change the value of this tuple by trying to reassign the index of 0 which is this bear if I try to replace that what kangaroo I will get an arrow so if I run that you can see here it tells me here tuple object does not support item assignment that's because once you create a tuple you cannot append to it you cannot change it another thing you can do is loop through a tuple looking basically means it will iterate through the tuple and print out each item so I'm saying here I'm using a for loop so I'm saying for X in animals print X X will represent each item so if I run the cell you can see here is printing out all the items in the tuple if you want to find out how many items there are in a tuple there is a special function called Len which enables you to return the length of the tuple so here I am wrapping the Len function inside the print function and I'm passing in the name of the tuple inside the Len function so if I run that that returns the length of the tuple which represents the item in the tuple you can also join tuples together so in this example here I'm going to be creating three tuples so the first one is called letters and I'm assigning it three values ABC second tuple is called numbers assigning a three values 1 2 3 the third tuple is called letters on the score numbers and the values for this I am joining using the plus operator to add the tuple code letters - DG post called numbers so let me run this cell so now if I references tuple called letters on the score numbers if I run that you can see it gives me ABC 1 2 3 the key thing to remember about a tuple is that once a tuple has been created you cannot change the value neither can you add to the tuple so the tuple is unchangeable or immutable once it has been created so that is it for this video in this video we'll learn about Python tuples hello and welcome to this video what is a Python dictionary a Python dictionary is a collection which is on ordered which can be changed and which is also indexed a Python dictionary is created by using curly brackets also a populated Python dictionary will have keys and corresponding values so that data inside a populated dictionary is paired paired in the sense that they have keys and the keys have corresponding values you can access the items of a dictionary by referring to its key name inside square brackets a values of items in a dictionary can be changed also a dictionary can be nested that means you can have dictionaries inside other dictionaries I have created a new notebook and inside the notebook I have got the code here to create a new dictionary so I'm creating a dictionary called countries underscore cities you use the equals to sign to assign values to the dictionary and you enclose the values in curly brackets that's the opening curly brackets and this here is e closing curly brackets so these here on the left are the keys and then these here on the right are the corresponding values so each item in a dictionary must have a key and the key must have a value the key is always on the left and the value is always on the right and then they are separated by the : so you can see here these are all keys and these are the corresponding values so I'm going to run the cell and I try to run this cell I encountered an error that's because he's telling me here the key that's called Croatia he told me where it made the error have left out the closing quote so I need to come back here where the cursor is flashing and add the closing quotes so if I run that again that should not work you can access the items in a dictionary by referring to the key all referring to the values or referring to both in this example here I am accessing the item in additionally by the key so you can see that's the name of the dictionary in square bracket passing in the value of the key which is Italy if I run this I expect Rome to return as the value so let me run that you can see here it has returned Rome as the value you can also use a special function called get to return the value of the specified key so this is a name of the dictionary and I'm using the get function and inside the get function and passing in the key in this case Egypt and if I run the cell it will return Cairo so if I run that you can see it has returned to Cairo you can also change the value in a dictionary so in this cell here I'm changing the value of the key that is called United States currently the key for that is New York I'm going to change it to Atlanta so if I run this cell now it should have changed that to Atlanta before I run the dictionary and just passing the key United States if you change it you should see the change we just made which is Atlanta issued not show Atlanta has a value instead of New York so let me run that you can see now is returned Atlanta you can also add items to a dictionary inside this cell here I'm adding a new key which is Japan and I am setting the value to Tokyo inside this dictionary called countries on the score City so I'm going to run this cell you can notice here that I've got an indentation error that's because I've accidentally indented so you can see where we cursor is flashing I need to move back so that I'm indented properly if I run that again you can see now that has worked so if I print the dictionary it should not include the new key I've just added which is Japan so I click to run I can see here is added Japan as well thus Japan is the key and Tokyo is the value you can also remove items from a dictionary there are several ways to do this the first way is by using the pop method so you call the pop method on the dictionary and you pass in the key of what you want to remove so I passed in the key Japan and this will remove the item for the specified key another way to do that is by using the Delete key so you type in DL then name of the dictionary and you pass him the key inside square brackets and this will remove the item from the specified key another way to do that is to use the pop item method and inside the pop item a tour this will remove the last inserted item all right I've commented up both because I don't want that to run I all I want to run the pop method so let me run that and that will have run that and also this print function here prints out the modified after removing Tokyo you can see Tokyo is no longer on the dictionary list after we've removed it using the pop method you can also look through the dictionary keys to do that you use the for loop which is used to iterate over the dictionary keys so we say for X in the dictionary called countries underscore cities you print X X basically will represent each of the keys so if I run that you can see here all is done is printed out just the keys if you want to print out just the values there is a special function called values so you add that function to the name of the dictionary and you print text and that will return only the value so if I run the cell you can see it's only returned the values for the dictionary if you want to get both the keys and values there is a special function called items that you can call on the dictionary so here in this cell I'm saying for X comma Y comma in countries underscore cities or items so this will print out the keys and value X represents the key and Y represents the values so if I run the cell you can see here is printed out the key and the corresponding values do you want to check the length of a dictionary there's a special function called Len you can use that to print the length so you wrap that inside this print function and then you pass in the name of the dictionary inside the parentheses for the Len function if I run the cell you can see it's returned 6 tells me the length of my dictionary is 6 which means I have 6 keys and their corresponding values you can also have nested dictionaries which means you can have a dictionary inside another dictionary so in this cell here I'm creating a dictionary that has other nested dictionary so name of the dictionaries family you can see he's contains other dictionary this is the first dictionary called first child second dictionary called second child and third dictionary called third child so if I click to run the cell that should create the dictionary if you want to access a nested dictionary you can do that by referencing the name of the parent dictionary and then in square brackets you pass in the name of the nested dictionary you want to access so in this cell here I want to access the dictionary called second child if I run the cell you can see he's giving me the keys and the corresponding values for the dictionary called second child you can also clear or empty a dictionary by using the clear method so I'm calling the clear method on the dictionary called family if I run that - you clear so if I now call the dictionary you should return an empty dictionary if I run that you can see here it has returned an empty dictionary so that is it for this video in this video we'll learn about Python dictionaries thanks for watching bye for now hello and welcome to this video what our Python operators Python operators are used to perform operations on variables and values there are different types of operators in Python so I'm going to cover some of the operators in Python the first one is the arithmetic operators so these are basically used with numeric values to perform common mathematical operations so they include things like plus subtraction multiplication division and this here is called the modulus operator the next type of operator is the assignment operators and this type of operators are basically used to assign values to variables so these are what the symbols look like you've got the equals to the plus equals minus equals multiplication equals division equals and modulo equals we also have the comparison operators which are used to compare values and they include double equals two if you want to compare if two values are strictly equals to each other you use the double equal to sign if you want to check if one value is not equal to another you use this if a value is greater than is that we value is less than the value is greater than or equals to where value is less than or equals to so these are all comparison operators the final type of operator I'm going to cover in this video is called the logical operators they are used to combine conditional statements include things like and or or not I have created a new notebook so inside this cell here I'm going to add some operators and I'm going to run through the code to explain what the operators do I have added some code into this notebook cell to illustrate how arithmetic operators work so I'm going to start with the addition operator so here I'm creating two variable variable X and variable Y variable X I have given a value of 7 variable Y I'm giving a value of 5 so I'm using the print function to print the value of x plus y so this here is the addition operator alright so I will run the cell later I'm not running the cell now I'm just showing you the examples of the operators within the arithmetic operator here we've got two values value x value y i'm using the print statement to print the value of x subtract the value of y so this here is the subtraction operator next we've got the multiplication the multiplication in python is represented by the Asterix again we've got two values x and y we are using the print function to multiply the value of x times the value of y and then here we have two variables X is equal to 12 y is equal to 4 and we're using the print function to divide X by Y slash is known as the division operator we've got one more which is the modulus operator so we've got two values values X equals seven value y equals five we're using the print function to print X modulus Y modulus basically means when you divide by a number it will only only return the remainder from that division for example if you divide 7 by 5 basically 5 can go into 7 once remainder 2 so the modulus operator will return the remainder which is 2 so let me run the cell and you can see the output you can see here the first value is 12 which is X plus y so 7 plus 5 is 12 and the second value here is 2 so if you take away 7 from 5 which is the subtraction operator that gives you 2 the third value here says 35 which is multiplication if you multiply 7 by 5 that will give you 35 next one is the division if you divide 12 by 4 that will return 3 and for the modulus operator modulus will always return the remainder so 5 can go into 7 one remainder one time remainder 2 so he returns the remainder which is 2 so this is how the arithmetic operator works I've added some code into my second cell in my notebook this is the second cell and this code here is going to illustrate how the assignment operator works assignment operators basically used to assign values to variables we already use that in the previous example for the erect arithmetic operator you can see all this equals to sign here we're using it to assign values to variables all right so there are different types of assignment operators so here I've got a variable called City have given it a value of London using the equals 2 which is the assignment operator so here I'm tell in the print function to print the value of city here I've got two values to variables x equals to 7 and then x equals 2 plus equals 2 when you have a plus equals so you're basically saying add these three to the value of x so when you print X X will not print 10 because X is 7 and we're saying we're calling the value we call an axiom we're adding plus equals 4 means add 3 and then using the equals 2 to assign the 3 to the 7 making it 10 so the same process with the - if we do a negative equals 2 that means you're taking 3 away from the value of X same thing with the multiplication what that is saying is that you are multiplying 3 by 7 with the division the same thing you are multiple you are dividing 3 the value of 3 here / equals to me divided equally to dividing that by 3 they'll return to same example with the module loss here we've got the variable x equals to 7 then x equals 2 the percent equals o which is modulus equals to 3 what that means is that for the modulus operator you're going to divide 3 by 7 and return whatever is left so this here print X will return 1 because 3 can go into 7 2 times it will have 1 remainder that's what this print X is going to return so let's run this cell and then we can see so you can see here these are all the values let's go to the top of the value says the with printing X here which is the value of city and you can see here prints London and then the next one here we have the very variable X and we are adding 3 to it so we print X X now becomes 10 so the same thing here we've got the variable X which is 7 we using the negative equals 2 it will subtract 3 from that that will return 4 and then here we are multiplying 3 by 7 give us 21 and here for the division we're dividing 3 by 6 gives us 2 and here for the modulus 3 goes into 7 2 times remainder 1 so the modulus will return 1 I have added some more code to a new cell here to illustrate how the comparison operators works so comprising operators are basically used to compare two values so let me run through the examples here here I've got a variable x equals 2 seven variable y equals 2 3 I'm using the print function to check the comparison where you have a double equals 2 it means you are comparing so you're saying print X is equals to a single equals 2 is used to assign a value where you have a double equal to is used to compare a value so know the difference here x equals to 7 is a single equal to that is used to assign values to variables here in the print function I am checking comparison here so I'm checking if X is equals to Y all right so this if I run the cell this is going to return false because 7 is not equal to 3 if we look in this example x equals 7 y caza 3 print x or you have the question mark it means print X is not equal to Y this will return true because X which is 7 is not equal to 3 and then we have again I'm going to use the same variables for the examples variable X is 7 variable Y is 3 I'm using the print function to print is X greater than Y this will return true because 7 is greater than 3 same thing here we're checking is X less than Y this is return false because 7 is not less than 3 again the same thing we're checking X is less is greater than or equal to Y this will return true because 7 is greater or equal to 3 in this example the same thing check if X is less than or equal to Y this will return false because 7 is neither less than or equal to 3 so let me run the code and you can see the output with a comparison operator you always get a true or false value because you're checking things is this equals to what and so on so you always get a boolean result boolean basically is it true or false outcome I have entered some code into another cell and this cell here is going to illustrate how the logical operators work logical operators are used to combine conditional statements ok so here what a variable x equals to 7 and I'm using the print function to check some conditions so I'm saying X is greater than 3 and this and here is a logical operator and X is less than 10 this is going to return true because 7 is greater than 3 and 7 is less than 10 all right so if we look at this example here x equals to 7 we're going to use a print function to check the comparison we're saying X is greater than 3 or X is less than 4 this is going to return true because one of the con decision where you have an all all you need is one of the conditions to be true and that evaluates to true if you have an and both conditions must be true for it to return true you can see this X is greater than three is one condition and then X is less than ten is another condition the and here means that both conditions must be true for the outcome to be true with the or logical operator you only need to have one of the expression to be true and that will return true so in this case X is greater than three that will reach true that returns true okay but seven is not less than four you can see here says X less than four seven is not less than four so this part of the expression is false but it will evaluate to true because one of the condition in the comparison is true when you use the or operator here we send X is seven we're using the print function to use the not part of the logical operator we say not X is greater than 3 and X is less than 10 this is going to return false because naught is used to reverse the result so let me run the cell and you can see the outcome you can see here first outcome is true second one is true and the last one is false in this video we learnt about some of the operators in Python thank you for watching bye for now hello and welcome to this video in this video we are going to learn about Python conditional statements what are conditional statements conditional statements are statements that perform certain type of computations or actions based on certain condition which will evaluate to true or false these conditions are known as boolean conditions there are three main types of conditional statements there's the if statements the L if statements and the else statements what are if statements if statements are used to check conditions before executing a certain block of code they help make your programs make smarter decisions and they will only run or execute the code inside the if block only when the condition for evaluates to be true if statements use comparison and logical operators to check whether conditions are true or false I have created a new notebook and inside this cell I have some code here to illustrate how the if statements work so you write an if statement using the if keyword so I have a couple of variables here variable a has a value of 40 variable B has a value of 80 so I'm using the if statement here to check if variable B is greater than a now that is the condition so the greater than sign is what we use to check the condition so B has 80 and a as 40 so B is definitely greater than a so that condition will evaluate to true so the code inside the if block so when you write an if statement you have the colon and then underneath the colon is the block of code that will execute when the condition is true so this print function here will execute this code that says B is greater than a because that condition is true if the condition was false nothing will happen the code will not execute so let me run the code by clicking on run command you can see it's executed the code inside the if block which is this text that says B is greater than a what are l if statements L if statements are used to check multiple expressions until they find a condition that is true when they do find a condition that is true it will only execute the block of code as soon as one of the conditions evaluates to true so if you're checking for a few condition it will execute the code he finds for the first conditions that evaluates to true I have a block of code inside my second cell to illustrate how the if statement works so I have two variables variable a has a value of 40 variable B has a value of 40 C they both have the same value so I've got an if statement which is checking is B greater than a so if B is greater than a the code inside the if block which is a print statement will execute in this condition the condition is false because both of them have the same value so that code inside the if block will not execute and then we have the code in the LF block which is checking so I'm using a comparison operator to check if you have a double equals 2 that means your checking is something is equals to another so I'm checking is a equals to B we know that they are because they both have the same value so the code inside the LD block will will execute because that condition is true they both are equal to each other so let me run this excel and you will see that the code inside the LF block is the one that has been executed which is this print statement that says a and B are equal what are else statements else statements are used to execute a block of code when conditions evaluates only to force added some block of code here into this new cell to illustrate how the else statement works so I have two variables variable a has a value of 20 variable B has a value of 10 I've got an if statement to check if variable B is greater than a if it is the code inside the if block of statements which is a print statement will execute in this case B is less than 20 so that will evaluate to force so that code will not execute we move on to the L if code in the L if we checking is a is equals to B this will evaluate to false so that code block will not execute we move on to the else statement which is going to evaluate to true because a is greater than B so that code will execute so let me run the code and you will see is saying a is greater than B called that well that is the only condition that is true we also have what is called a nested-if statement which is basically an if statement embedded inside another if statement I have added a block of code into this cell to illustrate how the nested-if statement works so I've got a variable X which has a value of 51 and I've got my first if statement which is if X is greater than 10 that is going to evaluate to true so the statement which is the print statement above 10 is going to be printed and then we have the second if statement which is embedded inside the first one which is checking if X is greater than 20 that is going to evaluate to true so the print statement which says above 20 is going to be executed all right so we have two statements that evaluates to true so if I run that we should have two printouts the first one says above 10 which is for this one and second says above 20 which is for that so that's basically how the nested if statement works so in this video we've learned about Python conditional statements thanks for watching bye for now what are Python loops loops in Python is basically a sequence of code that you want to be repeated or you want to run continuously until certain conditions are met so if you have a block of code you want to execute several times based on certain conditions you can use a loop and that code will continue to run until setting conditions has been reached there are two basic types of loops in Python we have the while loop which are basically used to execute a set of code continuously until a condition evaluates to false so as long as the condition within the code is true that block of code will continue to execute the next type of loop is called a for loop which is basically used to iterate over a list of item so for loops are particularly useful when you're using a list a tuple or a dictionary it can even be used to look through a string so the for loop if you want to iterate and say print out certain elements or all the elements in a list you can use a for loop to iterate over that sequence I've created a new notebook inside the notebook cell here I've added some code to illustrate how the while loop works so with a while loop you have to have an initial starter point so I'm doing that with this variable called I and I've set the variable to a value of one so now that we have a starting point you can now start the while loop so to implement a while loop you type in the keyword while and then you specify the conditions you are trying to check for so I'm saying this variable highest longer this variable I is less than 7 I want this print function to keep printing the value of I so what this will do it will continue printing I until it reaches 7 so once it goes past 7 that condition becomes false and the loop will stop also when you have a while loop it is very very important to add an increment counter because the variable has a value of 1 so here you can see I have this counter here plus equals 2 which means it's going to be adding 1 to the value of that variable each time so the first loop will run it will print out the value of 1 and then this statement will add plus equals 2 means add 1 to the value of the variable I so it will keep adding 1 until he gets until we exceed that level so the moment it comes to 7 the loop will stop because it would have evaluated to false because I will no longer be less than seven so but it's very important you add this increment counter if not the loop will go on forever it will never be forced so the counter is very important so that at some point it evaluates to force all right so let me run this and then you can see what I mean you can see here it will print it prints up 206 it doesn't print 7 because that basically is where the condition becomes false a to keep printing as long as this condition is true so once it becomes greater than 7 it turns to false and then the loop stop but it's very important that you always add the increment to the original value which is 1 if not the loop will continue forever which is which means that this condition I will always be in less than 7 if you don't add this increment to be adding 1 each time the loop runs to the original value I've added some code here into this second cell to illustrate how to use the break statement with a loop so the break statement basically is used to stop a loop even if the wild condition is true so here we can see the counter I the variable is close to 1 and I'm setting the while loop to say while I is less than 7 I wanted to bring the value of high and you can see here the increment counter is very important so that the loop will eventually evaluates to false and it will stop running so you can see here I'm adding a break statement so I'll see if when I becomes equals to 4 I want there to be break all right so let's see how that works we'll run that and you can see here it stops at 4 even though the condition is still true because I at this stage is still less than 7 but we are breaking the loop using this break statement you can also have the continued statement which you can use to continue from when you stopped within the current iteration of that loop so the continued works slightly different from the way the break statement works so here we've got a variable I equals to zero I was saying that while I is less than seven here you can see we are adding the increment here because the initial value is zero so we are not increasing the value to 1 and here we're saying if I when I becomes 4 continue and then we're telling it to print I so you will see here in when I run this cell that the number four is going to be missing from the report from the result because we only need to continue when it gets to four so it was skipped four and then continue with the loop so if I click run you can see here he does one two three it skips four and then prints out the rest I've got some code in this cell here to illustrate how a for loop works so with a for loop you have to use that to iterate over a list so I've got a list here called fruits and it's got different elements in it so if I can use a for loop to iterate over this list of items and then print out each value so to implement a for loop you type in for X E is going to represent each item in this list called fruits so I'll say for X in fruits print X if I run the cell here you can see here is printing out all the items within that list you can also use a for loop to iterate into a string so you see here I've got a string called strawberry I can use a for loop to iterate over each character within this string called strawberry so if I run that you can see here is printing out all the letters that make up the word strawberry you can also have a nested for loop which is a loop inside another loop so here I have two lists the first is called a DJ and the second is called fruits they both have three items so here I'm implementing a for loop so I'm saying for X in the first list called a DJ X will represent each item and then the second loop also for y Y represent each item in the list called fruits so I'm using the print statement to print X we should print all the items in the list X and the items in the list called Y so if I run that to make more sense you can see here is saying red which is this value and then Apple for the other one and so on okay so that's basically how a nested for loop works it's a loop inside another loop in this video we learnt about Python loops thanks for watching bye for now hello and welcome to this video in this video you'll learn about Python functions you'll learn how to create a function and also how to call or activate a function what are functions in Python functions are pieces of code or code blocks that are used to do something basically they are a group of related statements that are used to perform a specific task functions are useful they help break your programs into smaller are modular chunks so that as your program grows larger and larger the functions makes the program more organized and easier to Aitch functions avoids repetition and makes it possible for you to reuse your code so once you've created a function you can reuse it as many times as you want once you've created a function the function does not do nothing until you activate or call the function so the process of activating a function is also referred to as executing or running a function and you do that by calling the function with its name so whatever name you've called your function if you want to activate or execute it you need to call it by its name when you create functions you can have them have parameters which are variables so you can create a function and then passing variables which are known as parameters and also when you are calling or executing the functions you have to call it and supply arguments the arguments are referred to as values functions can return data as a result there are several types of functions they are built-in functions and they also use a defined function an example of a built-in function is the print function which you can use to print stuff or data on the screen and then you have your own custom which our user created custom they also refer to as custom functions the syntax for creating a function is fairly straightforward you use the keyword def which means you're trying to define a function followed by the name of the function and then you have the parentheses and then the call on the color is very important because that creates an indentation for the function so anything underneath the indentation here which is created by this : anything here is called the function body so when you execute or call the function this is the part of the code that will execute I have created a new notebook and inside the notebook I've added a block of code here I'm creating a new function called sum so you create a function by using the keyword de F space you give the function and name and inside the parentheses you can pass in parameters if you want to parameters are like variables so you can see have passed in two parameters x and y you can also leave the parentheses blank without any parameters so after you define the function you add a colon the colon creates this indentation level here and then this is the code that will be executed when this particular function is called so when you create a function the function does nothing until you call or activate the function so here I'm calling the function which is called some and inside the parentheses I'm passing in two values the first value of before the variable X and the second value will be for the variable Y so when you pass in values inside when you're calling a function they are known as arguments so four and five here are called arguments Y x and y inside the parentheses are known as parameters so let me run this function I'll click on run and you can see here it has returned a value of nine because I've passed in two arguments four and five which will then execute all these function says it will print out the value of x plus y in the example function we created we use parameter and also arguments I just want to explain again the difference between the parameter and the argument the parameter is the variable that is defined inside the functions parentheses while the argument is the actual value you pass or give to the function when the function is called what is the default parameter value this is a value that a function uses when the function is called without passing any value to the function only parameters at the end of a parameter list can have a default value as values are assigned by the position in the second cell here I've created a variable called student underscore names and inside the parentheses I have specified a default parameter value all right so this is the value that the function is going to use when I if I call the function without passing it any value so the name inside the parentheses is names this is going to be the variable and the value is going to be a blue line so when I call the function this is what is going to happen is going to print this text hello plus whatever value that this variable names has so here I'm calling the function with and without arguments the first one here I'm calling the function without passing any value to it so if I call it now this should print the default parameter value which is blue Lima should say hello blue line here I'm calling it and impersonate a value of John so now the name variable will now have the value of John and this I'm calling here he and I'm giving it a different value so let me run that and then you can see you can see says hello blue line which is the default value because I call the function without giving it any value or argument I call the function again give it a value of John it says hello John called it again and give it a value of Jane and says hello Jane so it basically executes the code in the body of the function which is this print statement here so whatever value the variable names has it will say hello to the value of that names variable
Info
Channel: The Life Code
Views: 36,774
Rating: undefined out of 5
Keywords: Python, Learn Python, Jupyter Notebook, python tutorial, python tutorial for beginners, Jupyter Notebooks for beginners, Learn Jupyter Notebook, How to install Jupyter Notebook, How to run the Jupyter Notebook Server, Jupyter Components, Python Expressions, Python Statements, Python Variables, Python Data Types, Python Operators, Python Loops, Python Functions, Jupyter, Jupyter Notebooks, Python Jupyter, Data Science, Jupyter Install, Python Data Science, IPython, morioh
Id: maLy3WI7B34
Channel Id: undefined
Length: 157min 5sec (9425 seconds)
Published: Thu Dec 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.