Python and Jupyter Notebooks Tutorial for Beginners

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 jupyter notebook we'll then learn how to run the duplicate notebook server we'll learn about some common jupiter commands we'll learn about the components that make up the jupiter notebook we'll learn about exploring the notebook dashboard we'll explore the user interface within the jupyter notebook we'll create notebooks we'll look at python expressions python statements we'll take a look at variables and how to create variables in python we'll 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 will learn about python operators we'll learn about conditional statements we'll learn about loops we'll 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 it also allows users to share the code the jupiter is a loose acronym which means julia python and r 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 slash r 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 max i'm just going to 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 going to click on the 64-bit graphical installer so you can see here is downloading on the bottom left hand corner of my screen i'll 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 the recommended one or you can use 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'll 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 going to give it a few minutes to run through the installation once the installation is completed you will get this that says 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 going to uncheck that if you want to learn more on anaconda you could leave that checked i'm going to 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 jupyter notebook using pip 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 pip on a mac you you will have to type in pip 3 which means that you are referring to pip version 3 and not version 2.7 so you do pick 3 on a mac space install dash dash upgrade pip and that will break peep if you're on a windows based computer you don't need to type in pip3 just type in pip install dash dash upgrade pip and that will upgrade to the most recent version of pip and then if you want to install the jupyter notebook using the python package manager you type in pip3 if you're on a mac install and then jupyter if you're running a windows based computer you type in pip space install jupyter 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 the 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 via the anaconda way because if you install anaconda 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 installed the anaconda navigator anaconda powershell prompt anaconda prompt the jupiter notebook which is what we are really interested in here and then we've got this reset spider setting 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're 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 jupyter space notebook and that will start the jupyter server the other way to start the jupyter 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 jupyter notebook you can run it from there as well once the jupyter notebook server is started it opens up the jupyter notebook in your default web browser and it does that on localhost and the port it uses is double 808 let's launch the jupiter notebook from the all programs menu on our windows based computer so if you click on all programs go to start our programs and there should be the anaconda 3 folder so if you just expand it and inside there you see the jupyter 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 jupyter 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 jupyter 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 jupyter 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 it's going to be the root directory and can also be the home directory if you are on a mac or a linux based computer you can also specify the directory that you want the notebook to start from and you do that by using by starting the jupyter notebook server from the command prompt while the jupyter notebook is running inside the console area here so if you look at look at the terminal interface here the command line 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 under the users directory and then under the profile administrator all right and then it tells you where the jupyter notebook is running at in the web browser which is localhost colon double eight double eight to shut down or exit the jupiter notebook server you just do ctrl c on your keyboard and that should shut down the jupiter notebook server once you shut down the jupyter notebook server you will not be able to access the jupyter notebook on the web browser you can see here because i've shut the server down you can see here it's not able to contact the server i have shown you how to start the jupyter notebook 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 888 i'm now going to show you how to start the jupiter notebook from the command line which is the command prompt on the windows based computer but the process is the same on the terminal notice that when you start the jupyter notebook from the anaconda folder within the all programs menu it will start that from the root directory of your profile where the jupiter notebook was installed when you're starting it 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 jupyter 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 i'll wait for it to launch so you can see it 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 do cls to clear the screen so now i have navigated to this folder here called project that's where i want to start the jupyter notebook so i just type in jupiter space notebook and press enter and it will start the jupyter notebook you can see it's 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 and you can see here it tells me where the jupiter been searched 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 jupyter notebook server from that directory in this video i showed you a couple of ways of starting the jupyter notebook one from the command line where you could specify a directory for the jupyter notebook to be served from and i also showed you how to start it from the anaconda folder within the all 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 the jupiter notebook from the root directory of your profile and when the jupiter notebook opens up it opens up in your default web browser on localhost colon 8888 the port number double it double it 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 sub commands 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 jupyter commands so this is a table here and we have some useful and commonly used jupyter command first one here in the table is the command to start the jupyter notebook you just type in jupyter 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 jupyter 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 jupyter space dash dash config dash dir if you want to see the location of the data directory you type in jupyter space dash dash data dash dir if you want to see the location of the runtime directory you type in jupyter space dash dash runtime dash dir if you want to show all the jupiter directories and the search path you type in jupiter space dash dash path if you want to print out the directories and search path in a json format you type in jupyter space dash 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 that should open up this console this terminal 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 here it says base that is the base directory that's where the jupyter notebook application will start from so if i want to start the jupyter notebook application and i do not want the web interface to show this is the command i will type or type in jupyter space notebook and there you do a space dash dash no dash browser what that means it will start the jupyter notebook but it will not show me the browser interface so i press enter and that should start the jupyter 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 ctrl c and that will stop the server so let's stop the server now that we have issued this command so i just do ctrl c and that will stop the server okay so you can see i've done the control c it has shut down the server all right 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 i want some information i just type in jupiter space dash dash help if you don't want to type in help you can type in dash h that will also do the same thing and press enter and you can see here it gives you some information about the jupiter notebooks it tells you usage here jupiter interactive computing and gives you some optional arguments so very useful information and to clear the screen again type in cls so that i can type in more command the next command i'm going to type in is to show the location of the configuration directory so i'm just typing jupyter space and it would be dash dash config dash dir i press enter and that shows me my configuration directory the next command i want to show the location of the data directory so type in jupiter space dash dash data dash 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 i'll type in jupyter space dash dash run time dash d i o press enter and that gives me the location of the runtime directory if i want to show all the jupyter directories and the search path i type in jupiter space and i'll type in dash dash path with an s and press enter and that will show me all the path okay it shows me the location of all the jupiter directories and their search path so 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 dash dash 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 tasks or workloads between the providers of a resource or a service which are usually called servers and their 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 jupyter notebook that could be your web browser because the jupyter 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 it 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 author notebook documents the second jupyter notebook component is called the kernels the kernels basically are separate processes started by the notebook web application and it usually runs in the user's code and it runs in a given language the default language is python but it 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 compute 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 it 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 3 folder which is this folder here and in there there is an icon here for jupyter notebook if i click to run this icon it will start up the jupyter notebook server from the root directory where it was installed if i don't want to start it from the directory where 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 click on the icon for jupyter notebook and it will launch this jupyter notebook interface you see it launches the web browser and it also launches this here so from here you can see where the jupyter notebook is running at it tells you seven the notebook from this local directory which is c 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 c slash user slash administrator and it will list what it's got in that directory which 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 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 sub directories in the notebook list you can navigate your file system so if you want to see any of these here just there you can see they are all clickable links to their respective directories okay if you want to see what's running in the dashboard you click on running and it shows you whatever 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 it tells you here when the these sub directories were last modified this little name arrow here basically is used to sort the list the directory subdirectories 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 arrow has gone up and it's flipped it and sorted it from z to a so i'm gonna 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 click logout and that has successfully logged me out of the dashboard okay and then if i want to quit this server i just type in this command here ctrl c and that will quit the jupyter 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 author your notebook documents interactively the notebook user interface has three main areas we have the 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 going to 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 if you want to edit you've got the view you've got insert it allows you to insert cells above or cells below this here is called a cell okay 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 widget you can download the widget and so on and then you've got the help menu okay so that this bar this area here is known as the menu bar and then we've got here this line here is called the notebook toolbar area okay 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 it tells you that is a save and checkpoint 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 selector cell down this enables you to run the cell this interrupts the kernel this one restarts the kernel with the dialog and this basically restarts the kernel the notebook has mode indicators mode 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 it's got a blue strip around the cell so if you click here if i click on this now if it'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've 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 i bought 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 mouse 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 new notebook i just want to point out a few things a notebook will have the file extension dot i p y n b 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 that runs 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 jupyter notebook server i'm going to start it from a specified directory i've got a directory on my desktop called my notebooks it's 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 all right and i'll just clear the screen so now i'm in the directory to start the jupyter notebook server i just type in jupyter space notebook and that will start the jupyter notebook server in that directory i have specified all right so it's trying to launch the jupyter notebook so this is the dashboard and you can see the dashboard here this is the root directory of the this directory on my desktop here that's what the jupyter notebook dashboard is pointing to it's empty at the moment because the there is no notebook list there's nothing in that directory so to create a new notebook there is a new option that says new you click on this new button at the top here and all these are called kernels so whatever kernels you see here depends on what's installed on the server all right 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 a cell and if you see here the default cell is a code all right and if i click on the drop down you can see the other type there's a markdown and there's a raw nb 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 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 and 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 unchecked 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 ipynb it has saved it 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 this 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 write 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 via 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 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 ad 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 and these are just a few list items of software that were created using python there are so many others but these are just some few that you may have come across so that is it for this video on what is python thanks for watching bye for now hello and welcome in this video i will introduce you to high and low level programming languages what are high-level programming languages these are languages that only humans can understand so computers can't understand them unless they are compiled 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-plus plus 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 faster it 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 lot here they are further away from the hardware 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 here is saying it needs to be converted into machine code using a compiler or an interpreter key 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 that's easy to read they are like basic english while low-level languages are far from human languages so only machines know what they are talking about you need a translator like a compiler an interpreter to convert a high-level language into machine language you know translator is needed for low-level languages because the machine hardware knows what they're talking about programs written in level languages are slow in execution because obviously they have to compile or interpret them while programs developed in low-level languages are much faster in execution because there's 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 um what is you 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 all right examples of languages that are compiled that means languages you have to compile before the code is executed includes 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 write so let's say inside the source file you have this you've got x equals seven y equals eight and then the sum is equals 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 and one so the compiler compiles it into a machine code and then it executes the code it then passes 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 a 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 bunch of code inside your 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 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 old code into a machine code before it executes in case of a interpreter it does it line by line and then eventually it will produce the results this is a brief table that illustrates some key differences between compilers and interpreters the compilers basically will transform the entire source code while interpreter will transform line by line of the source code the compilers will generate a machine code first before it execute the interpreter does not generate any machine code the because the 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 compiled languages because it's 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 three four plus five and the string hello text are referred to as strings in python an expression can contain operators like the plus operator it can also contain upper hands for example in the example 4 plus 5 4 is the upper and also 5 is an upper and 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 saying python expression so you can see i've got the blue strip which means i'm in the command mode inside this 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 and enter so i click run and that gives me the output of seven let me enter another expression i'll do seven 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 i'll say hello well to run this cell i click on run cell and it gives me the output hello world in these example expressions here the three here is known as an upper and the plus is known as an operator the four is also called an upper hand all right and here also in the second cell we've got the seven as an upper hand the asterix represents multiplication in python which is known as an operator the two 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 a 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 that new here i'll click on the drop down and click python 3. python 3 contains the python interpreter that will interpret the code we write into a machine readable format that the computer can understand so i'll click python 3 and i will just double 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 um 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 going to be a simple expression i'm going to say 9 times 9 and i'm going to run the cell by clicking on the run button and that gives me 81. so this is known as a single line statement because this statement or 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 4 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 so 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 0 to 12. all right so when you specify a range the first number is usually is zero okay hence it has not printed at 13 because 0 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 four is going to be used to loop through a range of 13 numbers a sequence so the i 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 we're basically using this for loop to loop through this range and we're going to print out each value of this i so i here contains all the values so what it's going to do is 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 either represent it 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 that new i'll click python3 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 alt 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 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 if 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 comment so to do that you do three 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 this quotes so we have three double quotes before and three double quotes online 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 world so if i run this cell by clicking on the run button you can see here it's 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 certain 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 decimals 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 force value is also known as the bool 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 a name and i'm going to call it python data types so we're going to 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 if i click on this run command you see here it has returned that this type of data is an integer so an integer is a whole number it can also include negative numbers so if i type in i do a type and inside that type function if i pass in 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 type and inside this function let's do 28.5 run this cell you can see it has returned a float you can also have a negative float value as well so if i do type and in between i do negative 1.0 and do a run it also returns a float next let's try and get a string data type so we do a type remember with a string you always have to enclose the values in quotes so i'm just going to say hello and i'll do a run you can see here it does return 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 bull 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'll do a type and say 7 is less than 6 it will also return a bold 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 very important concept in python so when you have to store data in variables it's 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 sdr 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 casting 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 in int and inside that in function i'm going to pass in a value that is a floating point so i'll do 2.8 and i run this cell you can see here it has returned 2 which is a whole number and an integer so it's 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 float function i'm going to pass in a whole number which is an integer so let's pass in 40 and then i'll run that you can see here it's converted it to 40.0 which is now a floating point number next let's convert an integer into a string so to do that we're 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 the value of 3 now if i run this it will convert this into a string data type 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 alpha numeric characters and the underscore character so it can contain from characters a to z numeric from 0 to 9 and the underscore 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 keywords there are certain keywords that are reserved for the python programming language which you cannot use as variable names on the screen here i've got a list of some reserved words in python they are called keywords so these are keywords that the programming language actually uses so you when you create a variable you cannot use any of these words listed in this table let's create some variables so the first thing i need to do is create a new notebook so i'll click on the drop down and click python 3 and we'll give the notebook a name and i'm going to call it python variables and i'll 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 i've called 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 quote 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 this 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 so for example i want to call the variable i change the name from blue line to jack and if i try 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 going to 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 is stored 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 i've spelt the world wrong so if i want to fix that all i need to do is call the variable by its name which is greetings and i'm going to fix that by changing that so i'll 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 here 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 so 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 underscore here and click run and you can see it gives me the value that is stored in that variable container with some programming languages you have to specify the data type 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 one container each item in a 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 the list by the index position so the first item is always index zero the second item in the 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'll come here to new python3 and i'm going to double click and give it a name i'm going to call it python list and now click rename so you can see here we have a new notebook called python list so let's go ahead and create some list in this cell i've created a new list called animals and i've assigned some values or elements to the list if i want to access any item or element from the list i will have to do that using their index number so the first item on the list will always have an index of zero the second will have an index of one 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 item is going to be zero so if i run this cell you can see here is printed at dog as 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 i'm 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 it's 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 pass in the index if i click run you can see here it has returned cherry if you don't want the quotes and close just do a print statement and wrap it around the 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 pass in the index of what i want to change which is 0 0 is apple and then assign a new value which is orange so if i run that that will change that if i now call the name of the list i 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 method 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 if 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 other list so in this list here called mixed underscore 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 here called fruit 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 that integer is 1 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 index 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 a fruits remove and pass in the value of the item you want to remove you can also use the delete key you do dl 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 and run the cell you can see apple is no longer listed another thing you can do is loop 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 want it to print x so it will print all the items so 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 list so if you want to find out how many items are in the list this is the function there's a functions called len so because i want to print it out i'm wrapping it inside this print function and inside the length function you pass in the name of the list so if i run this now it gives me eight it tells me that that list called animals has eight items in it another thing you can do is clear or empty a list and to do that there is a special function called clair so this is a list i want to empty called fruit so you do first or clear you add 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 learned 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 to to assign values to the tuple which are placed inside parentheses to access the individual items in a tuple you do that by the index so the very first item will have an index of zero second item will have an index of one and so on also one very important distinction between a two pool and the list is that a tuple cannot be changed once you have created it 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 to to assign values to the tuples 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 good 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 add my square bracket and i'm 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 tuple negative index basically will access the item from the end of the list so here i'm 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 here it's giving 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 what i'm saying is that i want to print from index two to five so what that 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 5 so it will give me the index number 2 which is giraffe and index number 3 which is good index number 4 leopard but it will not give me index number five which is lion so if i run that you can see here it's giving me giraffe good and leopard you can also use negative indexing on a range once you create a tuple you cannot change it what 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 zero which is this bear if i try to replace that with kangaroo i will get an error so if i run that you can see here 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 looping 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 length 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 and i'm assigning it three values one two three the third tuple is called letters underscore numbers and the values for this i am joining using the plus operator to add the tuple code letters to the tuposed code numbers so let me run this cell so now if i reference this tuple called letters underscore numbers if i run that you can see it gives me abc123 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 learned about python tupos hello and welcome to this video what is a python dictionary a python dictionary is a collection which is unordered 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 the data inside the 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 the 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 your values in curly brackets that's the opening curly brackets and this here is the 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 colon so you can see here these are all keys and these are the corresponding values so i'm going to run the cell when i try to run this cell i encounter an error that's because he's telling me here the key that's called croatia it tells me where i've made the error i've left out the closing quotes 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 or referring to the values or referring to both in this example here i am accessing the item in a dictionary via the key so you can see that's the name of the dictionary in square bracket i'm passing in the value of the key which is italy so 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 the 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 this cell it will return cairo so if i run that you can see it has returned 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 if i run the dictionary and just pass in the key united states you should change it you should see the change we've just made which is atlanta it should now show atlanta as 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 underscore cities 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 the 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 that's 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've 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 del the name of the dictionary and you pass in 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 method this will remove the last inserted item all right i've commented that both because i don't want that to run i only want to run the pop method so let me run that and that will i've 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 loop through the dictionary keys to do that you use the for loop which you use 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 x and that will return only the values 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 the 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 the value x represents the key and y represents the values so if i run this cell you can see he has printed out the keys and the corresponding values if 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 length function if i run the cell you can see it's returned six tells me the length of my dictionary is six which means i have six keys and the 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 the name of the dictionary is family and you can see it 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 so if i run the cell you can see is 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 clair method so i'm calling the clair method on the dictionary called family if i run that that should clear it so if i now call the dictionary it 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 learned about python dictionaries thanks for watching bye for now hello and welcome to this video what are 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 these 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 to if you want to compare if two values are strictly equals to each other you use the double equals to sign if you want to check if one value is not equals to another you use this if a value is greater than you use that if your value is less than if the value is greater than or equals to the 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 so they 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've given a value of 7 and variable y i'm giving a value of five so i'm using the print function to print the value of x plus y so this here is the addition operator all right 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 asterisk 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 equals to 12 y is equal to four 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 um seven by five basically five can go into seven once remainder two so the modulus operator will return the remainder which is two so let me run the cell and you can see the output you can see here the first value here 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 three and for the modulus operator modulus will always return the remainder so five can go into seven one remain one time remember two so it returns the remainder which is two 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 used that in the previous example for the 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 i've given it a value of london using the equals two which is the assignment operator so here i'm telling the print function to print the value of city here i've got two values two variables x equals to seven and then x equals to plus equals two when you have a plus equals so you're basically saying add this 3 to the value of x so when you print x x will now print 10 because x is 7 and we're saying we're calling the value we're calling x here and we're adding plus equals to means add three and then using the equals to to assign the three to the seven making it ten so the same process with the minus if you do a negative equals two that means you're taking three away from the value of x same thing with the multiplication what what that is saying is that you are multiplying three by seven with the division the same thing you are multiple you are dividing three the value of three here slash equals to mean divide equals two are dividing that by three that will return two same example with the modulus here we've got the variable x equals to seven then x equals to the percent equal so which is modulus equals to three what that means is that for the modulus operator you're going to divide three by seven and return whatever is left so this here print x will return one because three can go into seven two times it will have one 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 we're printing x here which is the value of city and you can see here it prints london and then the next one here we have the variable x and we're 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 to it will subtract three from that that will return four and then here we are multiplying three by seven give us 21 and here for the division we divide in three by six gives us two and here for the modulus three goes into seven two times remainder one so the modulus will return one 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 to 7 variable y equals to 3. i'm using the print function to check the comparison when you have a double equals to it means you are comparing so you're saying print x is equals to a single equals two is used to assign a value where you have a double equals to is used to compare a value so know the difference here x equals to 7 is a single equals 2 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 force because 7 is not equals to 3. if we look in this example x equals 7 y equals to 3 print x when you have the question mark it means print x is not equals to y this will return true because x which is 7 is not equals 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 force because seven is not less than three again the same thing we're checking x is less is greater than or equals to y this will return true because 7 is greater or equals to 3. in this example same thing check if x is less than or equals to y this will return force because 7 is neither less than or equals 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 a 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 okay so here i've got 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 condition where you have an or 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 3 is one condition and then x is less than 10 is another condition the and here means that both conditions must be true for the outcome to be true with the all 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 3 that will reach that returns true okay but seven is not less than four you can see here it 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're saying 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 not 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 learned 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 conditions 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 and they will only run or execute the code inside the if block only when the condition 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 the 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 the 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 it 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. so 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 l if block which is checking so i'm using a comparison operator to check if you have a double equals to that means you're 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 l a block will will execute because that condition is true they both are equals to each other so let me run this cell and you will see that the code inside the l if 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 evaluate 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're checking is a is equals to b this will evaluate to force 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 see is saying a is greater than b because that will 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 checking 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 evaluate to true so if i run that we should have two printouts the first one says above 10 which is for this one and the 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 certain 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 loop 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 i as long as 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 seven so once it goes past seven 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 one so here you can see i have this counter here plus equals to which is means it's going to be adding one to the value of that variable each time so the first loop will run it will print out the value of one and then this statement will add plus equals to means add one to the value of the variable i so it will keep adding one until it gets until we exceed that level so the moment it comes to seven the loop will stop because it would have evaluated to force 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 to six it doesn't print seven because that basically is where the condition becomes four so you to keep printing as long as this condition is true so once it becomes greater than seven it turns to force and then the loop stops but it's very important that you always add the increment to the original value which is one if not the loop will continue forever which is which means that this condition i will always be less than seven if you don't add this increment to be adding one 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 while condition is true so here we can see the counter i the variable i 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 i and you can see here the increment counter is very important so that the loop will eventually evaluate to force and it will stop running so you can see here i'm adding a break statement so i see if when i becomes equals to 4 i want there to be a break all right so let's see how that works we'll run that and you can see here it stops at four even though the condition is still true because i at this stage is still less than seven but we are breaking the loop using this break statement you can also have the continue statement which you can use to continue from where 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 the 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 initial value is zero so we are not increasing the value to one and here we're saying if i when i becomes four 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 we telling it to continue when it gets to four so it will skip four and then continue with the loop so if i click run you can see here it 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 the for loop works so with the 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 four x here is going to represent each item in this list called fruits so i say for x in fruits print x if i run the cell here you can see here it's 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 adj 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 adjx will represent each item and then the second loop i will say for y y represent each item in the list called fruits so i'm using the print statement to print x which would 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 is a loop inside another loop in this video we learned about python loops thanks for watching bye for now hello and welcome to this video in this video you will learn about python functions you 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 and modular chunks so that as your program grows larger and larger the functions makes the programs more organized and easier to manage 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 user 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 are user created custom they're also referred 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 column is very important because that creates an indentation for the function so anything underneath the indentation here which is created by this column 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 def space you give the function a name and inside the parentheses you can pass in parameters if you want to parameters are like variables so you can see here passed in two parameters x and y you can also leave the parenthesis blank without any parameters so after you define the function you add the colon the column 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 sum and inside the parenthesis and passing in two values the first value will be for 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 4 and 5 here are called arguments y x and y inside the parentheses are known as parameters so let me run this function i click run and you can see here it has returned a value of 9 because i've passed in 2 arguments 4 and 5 which will then execute what this function says it will print out the value of x plus y in the example function we created we use parameter and also argument i just want to explain again the difference between the parameter and the argument the parameter is the variable that is defined inside the function's 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 the 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 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 line it should say hello blue line here i'm calling it and i'm passing it a value of john so now the name variable will now have the value of john and this i'm calling here again and giving it a different value so let me run that and then you can see you can see it 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 call it again and give it a value of jane and it says hello gen so it basically execute 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: TechCode
Views: 86
Rating: undefined out of 5
Keywords: python and jupyter notebooks tutorial for beginners, python and jupyter notebooks for beginners, python and jupyter notebooks, learn python with jupyter notebook from scratch, python, jupyter notebook, python tutorial, techcode, morioh, code geek, jupyter notebook tutorial, jupyter notebook python, jupyter notebook tutorial for beginners, python jupyter notebook tutorial, python jupyter notebook course, learn jupyter notebook, learn python jupyter notebook, python for beginners
Id: nAuAeUyVGoc
Channel Id: undefined
Length: 157min 5sec (9425 seconds)
Published: Sun Nov 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.