hello Learners uh today I will discuss the basics of python uh in this lecture I will introduce python to you uh in last lecture uh we had introduced uh introduction to data science and I also discussed AI machine learning and data science and how they are interrelated and what are the similarities and uh differences between these uh important Technologies so I have already covered uh these uh Concepts introduction to data science as well as similarity and differences between AI machine learning and data science uh in today's lecture I will discuss uh the background of python and its basic components so python is developed by gudo Wan rosam uh he's a Dutch programmer and currently he's working as engineer in Microsoft uh previously he has also worked with uh Google so he actually introduced this uh Python language which is very popular nowadays the Python language is built around 19 rules from the Zen of python the Zen of python is actually a set of 19 guidelines for writing good code uh some of the guidelines are uh if imple such as if implementation is hard to explain it is bad idea so if uh code is hard to U explain so it means it's a bad idea if the implementation is easy to explain it may be a good idea so if you are explaining your code easily and uh it it is easily understandable so that is the good idea flat is better than uh nested it means uh uh suppose you are writing code in cc++ Java and there is option of nest if else condition Nest Loop conditions so better to write flight code so these uh guidelines uh was proposed uh uh in Zen of python and python is uh based on those guidelines the first release appeared in 1991 uh and currently we uh the third version uh is in the market in this uh slide I will discuss the features of u a python python is an interactive general purpose objectoriented and high level programming language you can actually sit at a python prompt and interact with the interpretor directly to write your programs so it's a very interactive programming it's interactive way of programming and obviously it supports objectoriented programming language so we are having different Paradigm of programming languages such as process oriented programming language object oriented programming language so uh we'll discuss whole concept of objectoriented programming language in separate weeks uh and python supports object oriented as well although you can write um in procedure oriented fashion but uh you can um write code in object oriented Paradigm as well and it's high L programming language English like language it support uh open source uh it means uh python is an uh example of you know floss free library and open source software in simple terms you can freely distribute copies of this software and you can read the software's source code so that is the concept of Open Source it is based on Simplicity and readability so that python code is very simple uh if you are writing a code in in Python so by looking on your code uh a person can easily understand your whole code it's portable it means it can run on any type of platform once you have written the code so it can be uh run any type of platforms huge community of developers and users so there are you know number of uh packages and Laboratories are coming into the market sorry so uh developers are continuously working to develop different uh Laboratories uh in Python so you will uh you will get a vast support of uh developer community in in python python works on different platforms as I told you uh it supports Windows based and you can work on you know Linux based platform so it supports all type of platforms python is wisely used in various type of applications whether you are developing web Bas web based application or uh you are developing uh you know data science based application or machine learning based applications even you can you know develop application for Windows based so using the python you can develop various type of applications V support of libraries and Frameworks there are so much libraries and Frameworks for different type of activities in in uh python let's say if you are interested in data science that is the part of the course actually we are uh we will use these uh Frameworks so for data science we are having numai panda scipi py to and others similarly if someone is working on machine learning so separate libraries and Frameworks are there tensor flow Cy learn P brain pyl and others so we will use uh both of these data science based uh libraries and framework and machine learning libraries as well because we will use as far as modeling of data science is concerned we will use these machine learning uh uh we'll use machine learning model and for that we need to have these lab design Frameworks such as tensor flow and pyic learn as far as artificial intelligence based application is concerned so one can use kage open CV n nltk and and nltk and others similarly if someone is interested in web development so several framework and libraries are there like Jango flask and so on for networking Network programming we are having uh several labr and Frameworks pulsor pi zmq and others so uh you can work on different type of applications and python has support for that you will find libraries and packages for that recently I was working for a problem based on cryptography so I was looking for a a labories for cryptographic based algorithm so I got that Library so if c community is actually supporting in different areas and different type of applications uh this is the official homepage of Python programming language that is ww. python.org there you you will find um uh python uh and you according to your um operating system you need to download it so uh and the extension of the file uh in which you are writing the program so if you are writing a program and if you want to save that program um under python so the extension would be uh do py so like for C we have extension do c for Java we have extension. Java similarly to uh have a file in Python so for that you need to include py now we'll see uh integrated development environment uh and editors so what is IDE and editors uh ID is actually a full-fed environment that provides all essential tools required for software development and as far as editor is concerned so code editor is or you could say text editor or code editor is a lightweight tool that allows you to write and edit the code with syntax highlighting and formatting features so these features are there so it code edited is a uh lightweight tool and how to select ID editor so depending on your experties uh as a beginner you can go for idle or online python editors which will be perfect for you and uh intermediat and advanced level of uh programmers can uh use Google collab Jupiter notebook and so on so as far as this uh course is concerned we will uh use Google collab for majority of the problems and for a starting level of problems for uh for simple problems we will be using ideally as well so the majority part will be uh the majority part of the problems will be solved under Google collab and what is your purpose as you know since our purpose is data science so we can go for uh Jupiter notebook or collab and if someone is developing uh a web- based application so they can go for pyam professional vs code and so on so uh these are certain ID and edit that uh need to be used for writing uh program in Python language now there is a very popular um ID that is integrated development and learning environment so as soon as you uh download python in your system andinstall it you will be automatically provided with ID right so it is suitable for simple projects as I told you so you can write simple programs or simple projects and how to download ideally so just go to the website uh let me show you uh where you can get that uh file so here is the python website here you can see there is a option downloads and you need to press this uh button for downloading python for Windows version so if I will press it here then automatically the download uh will be started and after the download of this python then you can double click it to uh install once it it will be inst installed you can get the ideally from here this this option and then just press it and you will get the this ID editor here you can um write anything and you here you can uh interact with the python it's it's a providing you a shell uh where you can write anything like let me write suppose I'm printing something print hello just I will write it here and it's not visible yeah let me press enter then it will be uh visible right so in this way you can interact with the python shell so uh we have seen uh how we can uh install uh python uh in our machine and then we'll look for another um um ID that is jupyter notebook it is a web- based interactive development environment uh it is easy to use open source software that allows you to create and share life code visualization and others so using jupyter notebook as well you you can write python programs so it provides you a proper uh manage management of different libraries of uh python so to install Jupiter you can directly uh install Anaconda so once you will an install Anaconda Jupiter will be uh installed automatically so this is the very first method to install Jupiter otherwise if you have some uh basic basic knowledge of command prompt so you can directly uh write this code uh let me show you how we can uh install jupyter notebook through command prompt so I will type here command and I will write pip install Jupiter so when I will press this option so Jupiter will be in inst since I have already installed uh Jupiter in this machine so I'm not going to install it again now to open the Jupiter envirment just write Jupiter notebook so once you will press Jupiter uh once you will press enter a web based uh Jupiter notebook will be open here and you can see it is being opened here and it will look like uh in this manner so here you can go to write code by using uh file option and then under new there are different option like console notebook terminal so I'm using a separate notebook here so once I will press separate notebook I will select the Python 3 uh and then I will come to this option so which is very similar uh Jupiter is actually backbone of Google collab as well so it is very similar to writing code in Google collab so you can interact with the uh python shell here like I'm pressing I is equal to 3 right there is a variable I3 and I can write print I and there is option of EX executing this code just press it and you will get the option uh you will get the result right three suppose I'm uh writing a is equal to 3 and b is = 4 and I can use a separate block to execute this code right I'm just writing s is equal to a + b and then print s so in a separate cell I can execute the code let me run this one since first I need to execute this one and then it need to be executed right so I'm writing the whole I have break the whole code in two different sales right so these are called sales so two different sale so I have initialized the value of a and b in this sale and summing those two variables A and B in second cell and printing the value right so in this way you can interact with the uh jupyter notebook very soon we will interact with the Google collab as well so I will show you how what are the different options uh under uh Jupiter notebook environment and how we can effectively use uh this ID for data science based problem development uh data science based solution development so this is the uh Jupiter notebook till now we have seen how we can install uh python how we can install uh jupyter notebook another um ID and editor that that is Google collab which is a free jupyter notebook environment that runs entirely in the cloud so uh it runs on cloud environment Google Cloud environment M so you need to have an account in Google and then you can use Google clab as you are using you know different product of Google like Google Drive and Google form similarly there is one more product Google collab that you can use after logging into the system uh there is no any requirement of installation and setup it allows you to work in a team uh even you know there there could be several team members and each one uh is coding in their environment and later on they can share the code support it supports many popular machine learning libraries all the libraries almost all the libraries are there uh whether you are working in data science uh or you are working on machine learning based problems or you are working uh on on AI based problems so almost all the libaries are there pre-installed so you need not to install any libraries so just log to the Google collab and you directly work on uh the Google coll environment so it's a it's a best option to use the uh python so if you want to work with uh uh jupyter notebook or Google collab so just I I have already uh told you how we can use how you can use uh um idle or jupyter notebook or even collab and I have already show shown you how you can write a statement um uh in ID or Jupiter notebook just you need to use print and then the string that will be printed here there are certain variables a equal to 50 Bal to 6 C is equal to a modo B so uh as soon as you write this one so uh result will be uh uh visible so python is an interpreted language so uh we'll discuss uh what is uh compiled language and interpreted language so interpreted language is a line by line compilation actually so uh python supports this uh uh type of uh compilation python expressions and statements can be run in any uh in an interactive programming environment called the shell so you are actually interacting with the shell each user is being provided with a separate shell so once you log to the Google clab or you are using um jupyter notebook so it is providing you a separate Shale uh there you will find the prompt I have already shown you and then you can write print python hello world and as soon as you press the enter button you will get the result you can use the calculator option to uh like 2 2 + 3 6 divided by 2 6 divided by 4 and so on um using the uh python shell I will try to show you how you can interact with the shell even if you are using ID you can write a program into a separate file just go to the new file from the file menu of ideally shell window you will get this uh uh uh you know option write your program and save your file using the uh py I have already told you the extension of the Python file iSpy use uh run module F5 from the Run menu so you will get uh so in a separate file you will uh write the whole code instead of writing in on uh python shell one by one you can write the whole program into a separate file so that is a beauty of ideally here I have uh mentioned here two problems two programs that you can write uh uh in uh python now let me come to the ideally then I will show you how you can write uh separate program in a separate file so I have already open this option so if you want to uh use different um if you want to use different operators like a + b suppose I'm having value as 4 + 5 so it will promptly it will give you a result similarly I can write 5 divided by 4 so I will get the 1.25 if I I want to have integer division then I will write five then Double SL 4 say will give me integer division similarly if if I want to find modulo of uh C8 modulo five so it will give you the result right so in this way you can uh uh use uh prompt off ideally and the another way to write programming ideally just open a new file like in this case and write the code here like in this case I am using a is equal to 10 then A and B are variables we'll discuss what are variables and what should be the data type and so on so I will uh discuss in in separate lecture so here A and B are integers so python is type free language you need not to mention um data type and then I'm writing here s isal to a + b and I'm this is actually sum uh I cannot write sum because it's a case sensitive language so I'm writing it myum okay and a plus b and then print print sum of two numbers right and then comma you can add different uh parameters by using comma and then my sum okay and then save it I'm just pressing contr s and then uh I will write test here since uh save as type is already mentioned here python files if somehow it is not being mentioned here then you can give the extension as test.py or any uh name that you prefer then save it so yes it has already saved and then if you want to run this one just run module there is option run module so as soon as I will press it here the result will be visible you know in ideally shell so uh it is visible in the Shell so in this way you can use Uh u a separate file to write the programs right then if you want to print something more then you can modify this code right and then you can write some more code okay let me come to this part so I have given you this two programs just uh try to write um python code for these two uh using ideally even you can use Google cab or um Jupiter notebook so any um editor can be used to write this program as far as program documentation is concerned uh you can include comment lines uh that actually provide documentation about your program so if you want to add command line command line is something uh you know if you are including that command line so that code would not be interpreted right so it would not be actually executed it would be um orally rejected so hash is used to comment a line and uh uh as I told you uh python is case sensitive it means capital A and small a both are two different variables and if you want to uh comment your single line then you can use hash if you want to comment multiple lines then you can use triple quotes So triple quot is is used uh to comment multiple lines in Python and then again indentation is essential uh if you want to create a blog suppose suppose you are writing a uh for Loop of or you are including if statement so to make uh your uh statement part of any uh condition or Loop then you have to use indentation and in that sense I will come to this indentation uh in uh later on lectures multiple statement can also be um included in a single line that will be separated with semicolon right so you can write a is equal to 5 and then semicolon and so on so in a single line multiple statements can be written keywords uh there are certain Reserve keywords that you cannot use uh there are about U I think 35 or 36 keywords are there uh that you can uh uh view by using this uh import keyword let me show you how we can uh you know use Python shell to show number of keywords so here is my uh python file I'm just writing here import import keyword s SK right so um uh I'm just trying to uh find out the length of the I mean number of keywords that are used here then I will use print K dot KW list uh sorry length ion length will give me total number of keywords and then again I save it and run module so here you will get so there are currently 35 keywords right so in this way uh keywords are 35 uh not 36 in this case similarly if you want to uh you know include some more uh code here like if you want to store uh length in a separate variable let's say uh temp is equal to k w KW list right so I can use it here directly without okay uh directly temp so I can use temp here just save it and then run it so in this way you can uh use uh python file now there are several Advanced uh python libraries right we have seen simple how to write simple programs in Python but as far as this uh course is concerned you need to have several Advanced libraries such as uh py learn and then numai pandas and py and so on on and similarly C bone mat matte plot Li and there are several other um python libraries especially for visualization so we need to use uh these labratories so in this uh lecture I will also introduce you to uh some popular Advanced Laboratories that we will use during the course the very first one is numai so numai stands for numerical python uh it is a labrary consisting of multi-dimensional array so you can create onedimensional twood dimensional three even you can create n dimensional arrays any collection of routines for processing those arrays such as sum maximum minimum so you can directly calculate using these routines if suppose you are having two numpy array A and B so you can directly uh um take product of these two using the routine so this is the best option I mean um in in case of C C++ Java you have to write the whole code if you want to uh multiply two uh matrices then you you need to include uh three Loops right to to calculate the product of two matrices uh in case of C C++ Java but here we have several uh flexibility uh we can directly calculate the product of two um nump array using numpy mathematical and logical operation on array can be performed so here you can see uh to use numpy array I need to import it first and then I I'm creating a variable of numpy array and here I'm populating the whole data and once you will print it you will get the uh this nump the next uh library that we'll be using is pandas panda is a python Library used for working with data set uh which is a very popular uh uh Advanced Library it has function for analyzing cleaning exploring and manipulation uh manipulating data so you will get different type of functions as far as far as P pandas are concerned pandas can clean M data set and make them readable and relevant we will be using uh pandas uh during the whole uh data science based uh project so here you can see if I need to use pandas I need to import Panda and then I'm declaring a variable of uh uh data frame that is DF and this data um has been created using the dictionary what is dictionary and list that I I will discuss in uh later on uh weeks so once you will pass it to data frame it will it will give you uh result in the form of uh uh row and column right so it's a very uh best way to read uh data set now the next uh uh Advanced library that we will be using cbon cbon is a python Library for making statistical Graphics so for visualization purpose actually we will use cbor it is built on top of mat plot lip and integrates closely with Panda's data structure here again I'm using uh pandas since uh I miss uh I need to read the data set first then that data set will be used uh for different visualization here I'm using a data set that is pima diabetes data set and uh that uh I'm after that I'm using uh corelation to uh create a correlation Matrix of different attributes of this data set and I have displayed a heat map that is depicting the correlation between different attributes or different features of data set actually so these are certain uh these are the features of this particular data set so we it it's a very it gives you a very Interactive way of displaying uh different type of graphs so cbon in that context cbon is very important Library the next one uh that that we'll be using uh in our course will be Cy learn escal learn uh cycl learn is the most useful and robust library for machine learning in Python it provides a selection of uh efficient tools for machine learning and statistical modeling including class classification negation clustering and so on so you will get different typee of functions and different Laboratories under psychic learn for classification and regression and clustering and so on sa L focuses on modeling the data some of the most popular groups of model Pro provided by skillin are as follows supervised learning so uh almost all the popular supervised learning algorithms like linear regression support Vector svm uh support Vector machine svm decision tree uh and others are the part of sa learn as far as unsupervised learning is concerned so uh it also has all the popular unsupervised learning algorithm from clustering factor analysis uh principal component analysis to unsupervised neural network and so on similarly uh as far as clustering is concerned this model is we are having separate feature uh for uh clustering as well here is a uh simple program uh that tiics how we can use um cyan so here I'm importing linear regression right I'm trying to use linear regression and I have created a Handler for that here in this case and xra and Y train are my training data set right X train uh and Y train X train is U um training data set of independent feature and Y train is uh uh training data set of dependent uh feature right I'm trying to fit uh my linear regression model and then after that I'm predicting the uh uh value of my uh testing data set so in this way it's very simple program later on we'll discuss the whole uh um full fled uh data science based problem uh utilizing these Advanced Library so uh in this lecture we have seen just to summarize it I'm just uh stopping here to summarize it we have seen uh what are the features of python how why it is very uh popular these days we have seen different um integrated uh development environment and editors such as as IDE uh then uh Google collab and jupyter notebook we have already seen how to run a python code utilizing idle or jupyter notebook then we have already seen uh we have seen introduction of advanced liabilities so these uh uh these have been discussed in this particular lecture we will meet uh again in next lecture thank you so much [Music]