Python Basics | Python Tutorial For Beginners | Learn Python Programming from Scratch | Edureka
- February 29, 2024
- Posted by: MainInstructor
- Category: Artificial Intelligence C Data Science Go Java Node Python Ruby
Video Title: Python Basics | Python Tutorial For Beginners | Learn Python Programming from Scratch | Edureka
Now before we get started please subscribe to our Channel and turn on notifications by clicking on the bell icon let’s go through what we will be covering in today’s session we will firstly go through a brief history of bites in and what it is following which we will see the different features that
Python provides us along with those who use Python in the industries once we are clear with these topics we shall dive straight into the Python basics where we shall cover the different data types such as numeric lists tuples and many more the operators in it and lead to
Understand how flow control works and how we can manipulate it using loops and conditions following which we will learn how to write functions and see some of the inbuilt functions at Python has later we will be ending our session with file handling where we learn how to read
And write data to and from a file so I hope all of you are clear with the agenda for today can I please get a confirmation message in the chat box you so now without any further ado let’s get started with the first topic of today’s session the first topic for today’s
Session is what is bison Python is a general-purpose programming language which can be used for almost anything may it be to develop web pages or for machine learning or any sort of simple application Python has you covered so you would wonder where did it all start
In the 1980s judo van Rossum wanted to make a language that was beautiful to look at and easy for everybody to read so as a hobby he started to make a language which would use indentations instead of braces because of which the code became distinguishable and all the
More readable he named it after the creator of his favorite show Monty Python and released it in 1989 Python has gained popularity recently with the rise of machine learning and artificial intelligence as Python makes code writing easy and efficient so formally saying Python is a high-level interpreted language which has easy syntax and
Dynamic semantics so what do these four key words mean well high-level means that Python derives components from the natural language that we humans used to communicate with each other this makes it easier for anybody to try and relate what exactly could be happening without the burden of going through tons of
Machine code interpreted means that the Python code is compiled line by line which makes debugging errors much more easier and efficient but this comes at a cost as Python is much more slower than other programming languages python has easy syntax because it makes use of indentations instead of braces to
Distinguish what block of code comes under which class or function this makes the code much more distributed and easy for anybody to read python has dynamic semantics meaning that you do not need to initialize anything before using it Python does all of that dynamically so I
Hope you have a clearer idea of what is Python let us go ahead and understand the different features that Python provides us so as you can see python has a variety of features that it provides us let us go ahead and understand each of these one by one the most well-known
Feature of Python is it simply ittan has made programming fun because it is simple it makes you think more for obtaining the solution of your problem rather than thinking for the syntax of your code the next important feature is that Python is an open source language which
Means that it is free for anybody to use you can also modify Python accordingly so that it better benefits your needs without any repercussions which brings us to our next feature portability Python supports portability which means that you can write your code and share it with your team members or anybody
That you want to and it would run the same way as it does for you this makes it really helpful when you are working on an application with a team of people our next feature are the embedding properties there may be chances that certain languages perform certain functions better than Python but that
Does not stop you as Python allows you to add the code of those particular languages within itself which makes python all the more powerful with that let us move over to the next feature interpretation Python is interpreted line by line which means that the management of memory and CPU is much
More efficient and easy a whole program may take up a lot of memory but Python would take away the block of code that has already been executed this frees up memory and makes the code run much more better now if you are wondering where the Python is the language to get
Started off with let me tell you that it is which brings us to the next feature library support Python has a huge library support which would help you to obtain solutions to your problems easier and much more efficiently you can get started off with data science or web
Development on the go with Python you may have also had questions like how to developers make applications that are so well related to a particular domain that is because of object-oriented concepts Python also supports oops meaning that you can model a real-world problem into your code and you can have security for
It such that certain features only access those particular data elements this can help you in replicating real-world problems so we have gone through the features that Python provides us now let us understand the companies who use Python in the industry there are thousands and thousands of companies who use Python for their daily
Business standards I have just listed a few of those so let us go ahead and understand how do these companies use Python we have companies like Google Dropbox BitTorrent Raspberry Pi National Security Agency NASA YouTube and Netflix so let us understand how do these companies actually use Python to provide
Their features Google uses Python to provide better search features to its users the Dropbox server and client applications have been coded using Python the National Security Agency uses Python for cybersecurity analysis and also for encryption and decryption purposes BitTorrent uses Python to share files between the users it had started
Out as a simple Python file and is now an application that millions of users use Raspberry Pi is a credit size computer which promotes Python as its educational language the scientists at NASA used Python to perform scientific calculations Netflix uses machine learning to understand and cluster certain groups of its users and
Recommend them TV shows to detain them for longer this machine learning is done using Python YouTube uses Python to provide better searches to its users so as you can see Python is a really important language and there are a huge number of companies who use it around
The world so now having understood what Python is what are its features and who are the companies who use it let us go ahead and get started off with our Python basics so to get started off with Python you would firstly need to install it onto your computer head over to
Python dot o– r– g– and download the latest installer that is available to you once the installer has been downloaded run it and make sure that you check this checkbox add python to path what this will do is read to make sure that python is installed globally throughout your system and you can
Access python from any place that you want to then go ahead and click on install now and you will see python being installed into your system once the installation is completed navigate and you will be able to find Pythian installed on your computer go ahead and open ID le which
Is the bundled development environment with python let us go ahead and write a first program with ideally do not worry if the font size of my ideally is huge I have done it so it is visible to you guys much more clearly it may be small for you so let us go
Ahead and write a first program that is to print hello users welcome to the basics tutorial and let me hit enter and as you can see I have obtained the output hello users welcome to the Python basics tutorial so it is that simple to write your first
Program in Python let us close this and move back to my presentation now for the rest of the tutorial I will not be using idle because there are chances that I may have errors and it becomes difficult to debug those errors so instead I will be downloading PyCharm which is the IDE
For writing Python files so head over to JetBrains dot-com slash buy Chomp slash download and you can download either the professional version or the community version for the purpose of the tutorial I will be downloading the community version because it is free but if you want you can even go ahead and download
The professional version for a certain amount of fee I already have pycharm installed in my computer so let us go ahead and see how to work with patch um and write a few programs with pycharm so this is the homepage of pycharm let us go ahead and create a new project
Let us go ahead and give a name to this project let me see it as demo and click on enter or click on the create button over here you so as you can see by Chum has loaded my project yep and show you the files that are in my
Project as you can see there is something called as the ve and B which is the virtual environment this basically takes care of all the installations of all the packages that you would need in your program so let us go ahead and create our first project
Over here let me right click on demo and go ahead on new’ and python file and the extension for a python file is always dot py let me just go ahead and name this as a demo one and hit enter let me just write a program over here to
Get a hang of it so it was hello users welcome to the Pythian basics tutorial let me go ahead and run this freeways so as you can see I have obtained the output hello users welcome to the Python basics tutorial so it’s that simple let’s go ahead and create another
Program and let’s say this will be used to add two numbers so ad enter and let me write this in the presentation mode so let’s see the first line is e is equal to int of input enter number e B is equal to end of input
Enter number B and let me just write print the addition of a and B is comma E+ so let me go ahead and run this program for you guys so as you can see I have two numbers that I have to add over here so let me
Just write five and five over here let me enter and as you can see the addition of a and B is a ten now what is the end over here what does this do well let me tell you how this actually works so this is basically a function so whatever is
Having parentheses after it so for example I have a and I have two parentheses after it this means that a is a function over here so this is just showing an error because I have a over here and this is a variable part variables are not functions so for
Example I have something like ad this is a function this says that there is unresolved reference meaning that there is no package that has the name ad so that’s a function basically and you can either give inputs to a function or you can just call the function accordingly
So now here input is a function and int is a function so just let me remove integer so that I can show you what exactly happens so input is used to take the users input and whatever is passed inside will be shown here at the output
So this let me give a space so that it’s much more clearer so let me run the program once again so I have five over here and five let me just hit enter and as you can see that the addition of a and B is 55 so let me tell you why
This happens basically the input function whatever input is taken from the user is taken as a string or it is taken as a character it is not taken as an integer or a whole number which is actually used for addition so if you add 5 and 5 it should be 10
But that is in a number of ways what if those 5 & 5 are characters so basically it will be 5 proceeding with 5 that’s the reason you have 55 here instead of 10 so how do you resolve this I just called the in function which is used to
Convert the string right these characters that I am passing are string characters so I am converting the string characters into the integer characters so let me just go ahead and do this and now if I run the program and give the same inputs so I give a 5 over here and
5 now what you can see that I have 10 so that is basically a simple program that can help you to get used to PI chomp what I am doing here is called as type conversion meaning that I am changing the data of one type to another data
Type so this is basically what happens over here let me just come out of the presentation mode now let us move ahead with the next part of our tutorial so I hope all of you are clear with this let me close the project and open up the
Project that I have ready for you guys so that it does not waste much time for us in typing let me go ahead PyCharm python v6 open so as you can see I have all the different topics that we will be covering the data types file handling flow control functions operators all of
This so let me just close this up and move back to my presentation now let us understand what are the different data types that we have in Python we basically have six data types what do you mean by a data type a data type is basically the type of data that you are
Trying to store in Python so there are six so we have numeric lists tuples dictionary sets and strings let us go ahead and understand each of these data types one by one so the first data type is the numeric data type so as the name suggests the numeric data type is used
To store the numeric values now you need to know the difference between a value and a variable so now let me help you understand this with an example remember that we had a is equal to 5 or a is equal to 10 something like that right now a is the variable which means
That it is the name and the value that I pass to it is the value for it so basically I am giving a name to the value so the name over here is a and is the variable and the value 10 is the value that I have given to the variable
The other thing that you have to remember are that numeric data types are not mutable what do you mean by mutation mutation is basically change meaning that the numeric data type cannot be changed what do you mean by this let me help you understand this with an example
So I have a first program over here now as you can see that I have a is equal to 10 and I have a is equal to 20 if I print the value of a and let me just run this as you can see I have obtained the
Output s 20 but what if I wanted to change e off as you can see I am getting an arrow over here which says that class integer does not define getitem meaning that I cannot change a particular value inside the 20 meaning that if I want to
Change the 0 of this to some other value that is not allowed in Python but if I wanted to change it into 21 this is allowed in Python so this is what it means by numbers are not mutable we have three datatypes in numeric data types these are the integers floats and
Complex water integers integers are basically integers whole numbers positive numbers negative numbers we have floating values which are basically the decimal numbers and we have complex numbers also in Python let us move ahead to the tutorial that I have prepared for you guys datatypes and let’s move over to numeric
Data types and let me move back to the presentation mode so as you can see I have integer data types I have floating data types and I have complex numbers so let me just print it out and let me comment what is not required for now let me run the program
So as you can see these are like simple operations that we are trying to perform here we have a plus B that is equal to 10 minus 10 which gives us the output 0 C minus D is 3 point 1 4 2 minus 0 point
1 4 2 which is 3 point 0 and 10 plus 3 J minus 6 J which gives us 10 minus 3 J so these are simple applications over here but the second one is where it is much more important for you to understand let me read on the program now as you
Can see we have e which is an integer and C which is a floating number then we have B which is an integer and F which is a floating number and then we have a simple operation of multiplication that is a into B but you would think that if
It is an integer and if you are working with the floating number shouldn’t it give us an error well that does not happen why is that this is something known as implicit type conversion if you remember the previous program that we were doing where we had end of input
That was converting the string into a integer number that’s the same thing that it happens but here we do not need to do it explicitly this is done internally by faith in itself so it converts the a which is an integer into a floating number so a here will be
10.000 up to the 16 digit part and then minus 3.14 – the same goes over here it will be minus 10 plus 0 G minus 68 so that is the reason we have the output as 6 point 8 5 8 0 0 up to 5 and then we
Have minus 10 minus 6 G and then the last one is a simple multiplication where we have minus 100 so I hope you’re clear with the numeric data types so let us go ahead and close this and understand what our type conversions as you may remember type conversions are
Basically used to convert a data type from one form to another so let me just go ahead and uncomment what is required for now because if I have the whole program running in a sequence it becomes really difficult for you guys to understand what’s happening let me go
Ahead and run this for you so I have a string which is 1 0 0 1 0 I am telling that I want to convert it into an integer and this number that I am wanting to convert into an integer is in the form of a binary number so that’s
The reason I get 18 because 1 0 0 1 0 in binary is 18 and then we have a floating number which is converting the string that is 1 0 0 1 0 is converted into a floating number so it is 1 0 0 1 0 point
0 0 0 up to how many other numbers let me go ahead and show you some of the more functions that are available to you which you can use for type conversions the type conversions that you follow are called as explicit type conversions and type conversions that Python does by
Itself are called as implicit type conversions let me go ahead and run this for you so I have a string which is having the value 4 over here and then I want to convert it into an integer which is done using the Ord function so this
Is now an integer now I want to convert 56 into a hexagonal number and 56 into an octagonal number so that is then using hex and awk functions so we have 0 X 3 8 & 0 7 0 which is a 56 in hexadecimal and octal let me move ahead
And show you some more and let me just comment up everything and uncomment what is not required let me run this I have a string called ed Eureka and I am converting it into a tuple set and a list that is what is being done here I
Can do this using the tupple function the set function of the list function you will understand more of these later in the tutorial but for now you can just understand that this is how you convert it into let me move ahead and run the program so as you can see I
Have a and B as one and two and I have a couple which has a comma one F comma 2 and G comma 3 if I want to make a complex number I can use the complex function and pass the values to it this
Will give us the output as 1 plus 2 G then I want to convert a number into a string that is done using the STR function so the number that you have here is basically a string and then you have the dict which is used to convert
It into a dictionary so I have a 1 F 2 G 3 where a is the key 1 is the value F is the key 2 is the value G is the key and 3 is the value these are just simple examples of how you can use type
Conversions now you may be thinking where exactly would you want to use type conversions this may be better understood if I give you a simple example think of a company who has the data of their employees in a tabular format and all of the data is stored in
A string now if you remember from the first part of the Python project that we did that if you do not convert a data it would be concatenated into a string right so you do not want that because it may give you wrong output that you would
Not want so instead of doing that you just type converted into an integer or a floating number and accordingly you can perform your own calculations so that is one simple example where you would actually use type conversions there are many which may depend on the application you are working on
So I hope all of you have understood type conversion let us move ahead with the next data type data lists what are lists lists are the same as arrays with one exception that they can have different data items inside them arrays would only have a particular data item
Within them so for example if an array had an integer it would only have integer values if it was a floating point it would only have floating values lists are not like that it can have integers floats complex numbers strings lists tuples dictionaries there can be so many other different data types that
A list can hold and lists are also mutable meaning that you can change particular items in the list now for any of you who do not know what arrays are arrays are basically used to construct data structures now what are data structures data structures are basically
The way in which you arrange your data for example at home you have a bookshelf where you want to arrange the books in a certain way that is comfortable for you that makes it much more easier for you to work with now that’s the same case
With data data also has to be stored in a particular manner so that it is much more helpful for you to work with that’s the reason arrays are used to make up stacks and queues and so many other data structures that you have this is where
Arrays are used let us go ahead and understand lists much more clearer with the operations that I already have prepared for you guys let me go back to the presentation mode so how do you initialize empty lists it is using square braces square braces are used to
Denote a list or you can do that using the list function so let me run the program and you can see the code over here so as you can see I have empty lists over here so that is a really simple for you guys to understand how do
You initialize a list you just add data in that particular way using the square braces you just have element comma element comma accordingly but if you are using the list function you have to make sure that you pass it as a single parameter because if you don’t this will
Throw an error to you so let me go ahead and run this program so as you can see this is the data that I have in my lists let me go ahead and comment all of this and we have accessing the elements of the list so how do you access the
Elements in your list that is basically done using indexes now it is really important for you to understand what indexes index is basically the address in which the data is stored this may be true for lists tuples and even for Strings so let me show you how the
Address is stored in Python so if I have the element 1 it is stored at the index 0 if I have the element 2 it is stored at the index 1 so the address always starts with 0 up till how many ever numbers you have so this will be 2
This will be three and this will be four so the address of element 1 is 0 address of element 2 is 1 and so on there is also something which is called as the negative indexing in Python which can help you to access data from the last or the bottom part of the
List so how is that it starts from minus 1 so this will be minus 2 sorry this will be minus 3 this will be minus a four and this will be -5 so I hope you’ve understood what index is let me go ahead and just take out all of this
Yes so now how do you access the elements of the list it is done using splicing so basically what this means is that you want to particularly print certain parts of the list or string or tuple there is something called as the starting index stopping index and the
Skip index here I have not given anything so Python assumes that I want to print everything so let me just print out the program for you yes so as you can see over here I am just saying that print off my list so these are the different methods of how you can access
The elements of history it’s done using splicing so splicing always has a starting index it has an ending index and it also has a skip index so over here I have not given the starting and the ending index what this means is that Python will automatically think that I
Want to print all of the data that is the reason I have all the data that is being printed over here if I do not pass this it will still give me the whole list that I have so let me just run this again as you can see it is printing the whole
List so if I want to access a particular element I have to pass the index value of it so if this was 0 this was 1 this was 2 and this was 3 right I am basically going to print ed Eureka and that is what is being printed over here
Now it is with the starting index and the ending index meaning that you have to start from the index 0 and go up to index 3 and you have to exclude index 4 so that is what happens over here so it is a 1 2 3 and a Eureka that means that
I start from index 0 go up till 3 and I skip 4 if I want to reverse it I do not give any starting or ending index I just do it from minus 1 so the list is being reversed over here so that’s what happens over here as you can see next is
Something called as the skip index right now I start from 0 go up till 5 then skip two elements meaning that I print 1 I skip one and I skip 2 and I print 3 I skip 3 I skip ed Eureka and I print Python so that is what happens over here
As you can see that is how you have obtained the output next is the third element and the second next the next is I can also access particular elements within the elements so basically what I am saying over here is that I want to
Print you how do I do that I know that Ed Eureka is at index 3 and I also know that you is at the index 2 so I just add that over here so I have 3 and 2 and that’s the reason I have you that is
Being printed over here so I hope you have understood what is indexing and how you can access the elements using splicing and indexing let us move ahead and add data into the list how do you do that you do that using the append function the extend function and the
Insert function so let me just go ahead and show this to you how is how it is being done now so the append function as the element at the end of the list the extend function also adds the element at the end of the list so what is the
Difference between them well the difference between them is that the append function adds it as a particular element it adds it as a single element the extend function does not work like that it adds all the elements one by one whereas the append function just adds it
As a single element that’s the reason if you go over here you can see that triple Phi and 1/2 which is being passed actually as a list is added as a list itself so I have 1 2 3 I’d eureka python and i have triple phi n 1 2 but whereas
In the extend function i have triple Phi N 1 2 independently and that’s the reason I have 7 as the length of the list the length of the list is basically to show how many elements are there in the list and then I have the insert function which takes the index at which
I want to insert the particular data as the reason over here if you can see I have one insert example and accordingly the data is not deleted when you use the insert function the next ways are to use the concatenation and multiplication but they do not affect the actual data of
The list as you can see over here I just have printing of my list but if I was not printing it it would actually change the data of it but since I am using it in the print function the data will not be changed so as you can see over here I
Have one accordingly and just for example and then multiplication is multiplying the list accordingly to the number you have told it to be multiplied with so the whole list will be multiplied two times and then just to show you that if I am printing all of
This it does not change the actual data I have printed my list and you can see that my list is unaffected so that is basically how you can add elements now let’s move ahead and see how we can delete elements from the lists let me go ahead and run the program
As you can see I have two lists and I have extended my list using triple Phi one – an example one way of deleting is by deleting it using the Dell keyboard I just say delete and pass the element that I want to delete and it will be
Deleted the next one is using the remove function so I just pass the element that has to be removed from the list and accordingly that will be removed so that’s the reason here as you can see triple five was deleted using the del keyword and example was removed using
The dot remove function the next is the pop function the pop function and the delete function are basically doing the same thing with one exception the delete keyword does not return anything whereas the pop function returns the value back to you so you can use it accordingly to
How you want so I am just saying that pop the element which is at index five that’s the reason the popped element over here is two L and the remaining list is four five 3.14 – fun and cool and then the last function is the clear function which returns an empty list so
I hope you understood what are the different ways that you can delete the data from your lists let’s move ahead to just see the different other functions that are there in Python if you remember the length function is used to return the length of the function and that is the reason we have
Obtained five over here the next is the index function which is used to return the index where this particular element exists and this element exists at 3 that’s a reason we have 3 at the output over here then we have the count which basically tells
That I want the count of Ed Eureka which is being repeated in this particular list so in our example it is repeated just once so that is the reason we will only get it as 1 over here so now we have the sorted and the sort function
The sorted has a return type whereas the sort function does not have a return type so if you want to use either the sort or the sorted function you need to make sure that the data that you have is of the same data type if I try to use
The sort and sorted function on these it would not work that’s the reason I have a new list over here so I am just printing the sorted value over here so that is 3 4 5 2 ln 45 and then i am going to sort 45 and then you can see
That it has not affected the actual list that’s the reason i have it over here so sorted does not change the actual value of the list it just prints it accordingly but if i use the sort function it would actually change the value of the list so if i have a sort
And it uses a keyword which is a reverse is equal to true if the reverse is equal to true it will sort it in the descending order if the reverse is equal to false it will sort it in the ascending order so that is what is happening here so this is in the
Descending order right now and then I just reverse it using the dot reverse function so the data will now be reversed which is basically now in the ascending order and then I have the dot copy function which is used to copy a list into another list so it is my list
Dot copy into the new list so if I have printed the new list you can see I have the data of my list so that basically wraps up list operations and I hope all of you are clear with it so let’s move ahead with the next data type
Let me just close this up so the next data type that we have are tuples water tuples tuples are basically the same as lists with one exception that they are not neutral meaning that you cannot change the data in tuples this makes tuples much more faster than
Lists so how are tuples written they are written using the parenthesis so let’s move ahead directly to our tutorial run this so as you can see I have either the parentheses or the tupple function and it is the same over here also if you want to initialize the data you will
Have to send it as a single variable in the tupple function where as you can use commas in the parentheses you can see here we have empty lists let me go ahead comment this out and let me uncomment all of this why would you use empty
Tuples it would be cases where you do not know what exactly data has to be sent into the tupple so what do you do over here you can just concatenate data into it so for example a multiple equal to my Apple plus 1 comma 2 , three we print my topple over here
Let me go ahead and run this so as you can see I have one two three in the topple this was because I did not know what do I need to add in my topple in the previous example but as soon as I kept doing some sort of operations I was
Able to understand what Delta I need to add and that’s the reason I concatenated it using the tupple but now if I try to change my tuples data as you can see that statement seems to have no effect meaning that the topple will not have any sort of changement or it cannot be
Mutated so that’s the reason you may want to have some sort of you know empty tuple which you may later be populating so that may be one reason where you want to use empty tuples where you do not know what data you need to have but slowly slowly you can populate it
Accordingly this is basically how you initialize your elements in the tupple let me go ahead and run this so as you can see I have one two three and couple and all of this is sent to it as a single element so that is what is happening over here now
There is one thing that you always need to remember when you want to have a tuple with a single element make sure that it is always with a comma at the end why is this important is because if I remove the comma and I show you the
Type that is my topple three it is now a spring beta so that is the reason a comma is needed so that you can have a tuple with a single element so I hope you have understood how do you initialize the data the accessing of elements is the same
Way as you do it with the lists let me go ahead and run this as you can see one two three Python and accordingly so the zeroth element of my topple is one over here and I want to print everything so Python Frederica is printed and then I have the third
Element which is a list over here and I want to print the element which is at index number one that is Python this is how I access the elements you can actually change the data in a couple if the data you were trying to change is mutable so here I have one two
Three Hindi and Python now you know that this is a list and a list is basically mutable right so I can change the data in this particular list but I cannot change the whole list why it’s because it is a part of the tupple so I’m just
Saying go to the list index and then change the zeroth element that is Hindi change it to English so if I print this I have a 1-2-3 English and Python over here so that is one way you can actually change the data of a couple and we have
Just a few more methods which are the count method and the index method which is the same as how it works in lists so the count of two is actually just one and the index of Indian python is three so I have one and three as the output so
That basically wraps up tuples let’s move ahead to the next theater type which are dictionaries so dictionaries are used to hold key value pairs and the immutable now you may be confused water key value pairs so let me help you understand all of this with a real world
Example okay think of your contacts application on the cell phone if you see it and go ahead to add a contact you will always see a few fields that are common all the time you have name you have phone number and all the other data that you want to add
Accordingly let us just understand how this works the data we have is a name which is the key it is always common for everybody and we have phone number which is again the key which is common for everybody but the value that you enter in those particular fields will be
Different accordingly because you have a name and the value you enter for that name you have a phone number you have a different phone number for that particular name so that’s how it works right so it is basically key and value so you have the name which is the key
And the value that you enter is the name of the person so that is basically what is a key value pair so for example over here I have a name that is my name that’s our cash and I have the horoscope sign of mine that is the Libra this is
One way how you can have a dictionary it is to store the horoscope sign of all the people you have named as Akash and sinus Libra where name is the key and Akash is the value sign is the key and Libra is the value so let’s move ahead
And go to the tutorial that I have ready for you how do you initialize an empty dictionary it is done using the flower braces or it is done using the dict method Vict let me run this and you will be able to see that there are MTC dictionaries over
Here let me go ahead and add back and remove braces to where we engineer it so how do you initialize the elements in the dictionary it is the key and the value so that is how you actually do it in dictionary so always a key value pair
Is taken because the dictionary is are basically key value pairs so let me go ahead and run this one is the key followed by a colon and then the value that that particular key has so I have one Python to Java one C++ and two Ruby that is how you initialize your
Dictionary let me go ahead and uncomment the next session so the next is to access the elements so to access the elements of the dictionary you do it using the keys so I have the first as the key and Python as the value second
As the key and Java as the value so I have my deck and then the key name which is first give me the value from this dictionary where the key value is first and I can do that even using the door gap method where I just pass the key
Value of that particular element so let me go ahead and run this so as you can see I have obtained the value pison because I said that I want the value in my dictionary and it has the key first same thing is done using the get method where I get the value for
Whichever I have the key as second so I hope that makes sense to you guys let me show you how you can change and add elements into your dictionary so this is the dictionary that we have over here and then I want to change the
Data that is in a second saying that I do not want Java I want this to be C++ so I just save my deck of a second and I want to change it with the value so I just pass the value to it so now if you
Can see here Java is now been changed with C++ right so now how do you add elements into the dictionary you do that by giving the key value pair so you just say that my deck and give the key and then you give the value so that is how I
Have obtained the output first Python second C++ and third as Ruby so that’s how easy it is to add your elements into the dictionary let me go ahead and show you how to delete elements now one way is to use the del keyword you can use it
Accordingly it works the same way every place here you would just have to give the key name so I have Merton dictionary which is my dictionary so the next way is the pop item function which will return the key value pair to you in the
Form of a tuple and how does this work the item which is in the last position will be given back to you so if you can see over here second and Java which was at the last position have been popped out as a key value pair in the form of a tuple
So as you can see here 2nd and Java have been returned back and they are in the form of a tuple with a key value over here so that’s how you use the pop item function and then you have the clear which is used to just basically empty
The dictionary I hope you’re clear with that let me comment all of this out and move over so we have a few functions that may be helpful to you when you start using dictionaries so they are the keys values items and the gate function you already
Know what the gate function does we have keys which basically returns all the keys for this particular dictionary we have the values which returns the values of the dictionary we have the items which returns the key/value pair in the topple forms so as you can see over here
These are the keys for second third these are the values Python Java and Ruby and then you have the dicta items which is the key value pair and you know how the gate function works you just pass the key and the value will be returned back to you so that basically
Wraps up dictionaries let’s move over to sets the next data type are sets if you know arithmetic you would know what sets are that is basically what we have in Python right now sets are basically unordered collection of unique elements and they are mutable so how do you write
Sets so sets are basically written in the flower braces but with a comma only you do not have a key value pair whenever you have a key value pair it becomes a dictionary whenever you just have elements it becomes Earth set so let’s move ahead and go to the tutorial
So let me move back to the presentation moon how do you initialize your set you do it using this way and if you can see the output it is just one two three four five but where as I have written one two three four five five five Y is five five
Five not repeated remember the definition always set is a collection of unique elements right so even if five is repeated even a thousand times it will still be taken it as one time so that is what is basically a set how you initialize your set let us move over to
How you add elements into your sets so adding the elements are done using the add method you can see I have a list one two three and I just want to add four over here so that’s the reason I obtain the output one two three and four so
That’s how easy it is to add elements into your sets so let’s move over to the other methods that we have now if you remember your arithmetic you will definitely remember what was Union intersection difference and symmetric difference right so what are basically all these methods the Union is basically
Adding the elements of both the sets intersection is to find out the common elements difference is to delete the common elements and have the remaining elements given as the output and symmetric difference is to take out both the common elements that are in the set symmetric difference is to take out all
The elements that are common in the set and give as output the remaining elements that are in both the sets that is basically what was Union intersection difference and symmetric difference so let me just go ahead and run this program for you so if you know Union it is going to add
Both the elements so it would be one two three four three four five six but it is unique right so I would just have three four repeated once so it would be one two three four five six the same can be done using the pipeline operator the
Next is intersection so three and four are common so that’s why three and four will be given as the output and it can be also done using the and operator then you have the difference which is to take out the common elements and then show the elements that are present in my set
Which is the first said that you give over here so three four are common and the remaining elements in set one are 1 & 2 so 1 & 2 is given as the output next you have the symmetric difference which is basically the same as the difference
Function but it would take the elements that are remaining in both the sets so 1 2 5 & 6 will be given as the output so I hope you’re clear with that and then we have the clear function which is used to basically give you back the empty set
Let’s move ahead to the operators that we have in sets let me go ahead and run this so we have three sets over here super set set one and set two the double equal to is just to compare in both the sets are equal if
Both the sets are equal it will be true but we have got false meaning that both the sets are not true the second one is to check if both the sets are not equal we know that both the sets are not equal that’s the reason we
Obtain our true next we have the sub set and the proper sub set now what does a sub set sub set is basically to show that all the elements of one set are present in the other set so set one’s elements are definitely present in the
Super set that is the reason this is a true and we also know what is a proper sub set so that is the reason we also obtain a true over here and then we have s1 and s2 we are just checking if s2 is a subset of s1 obviously it is not and
That’s the reason even if it is not a sub set it would definitely not be a proper subset so that brings us to the end of sets hope you’re clear with all of this let’s move ahead to the next data type that we have in Python so I
Hope all of you are clear with sets let us move ahead and go to the large data type which are strings so what are strings strings are basically a collection of characters if you have a b c capital a capital B capital C all these are characters right now you have
To remember that python is case-sensitive which means that capital a and small a are different from each other so strings are basically written using either the single or the double quotation marks and they are not mutable meaning that you cannot change particular data in the string so let’s
Move ahead and go to the tutorial that I have for you guys let me just uncomment what is needed so as you can see I have two strings over here that is my STR and – TR – which is welcome to the tutorial this is
My string so as you can seen that sort but that we have and next is a string splicing now strings pricing may be very much easier for you guys because you’ve now understood how we access particular data in lists tuples and all of those data types it’s the same with your
Strings also if you do not have any start of stop index it will print the entire string this is from 2 to 9 and a skipping 10 this is from 0 to 14 and skipping one element this is from 0 to 14 skipping two elements this one is to
Reverse the string and this is from the reverse order so let me go ahead and run the program and we have our string as welcome to the tutorial and as you can see we have welcome to the tutorial that is for the first one and next is from 2 to 9 which
Is I’ll come to and then we have 0 to 14 so that is welcome to them and if I am skipping 2 elements it will be this particular string over here next it is to reverse the string so as you can see this is in the reverse order and
Then we have to print a particular range in reverse order so this is the output that we have obtained so I hope you’re clear with how you access or how you splice a particular string there are many and many functions that we have for Strings I have just defined a few of
Those over here so the length of is Li which is to give the length of the string which is that is 23 then see how many times the element T has been repeated so it is 3 times then this dot lower is to convert the string into a
Lowercase and dot upper is used to convert it into an uppercase so as you can see this is the output that we have then the find function will basically return the index whenever this particular element has been obtained and if it is not obtained it just gives out
An arrow so you can see here L is obtained at the first time at index number 2 that is the reason this index will only be returned to us and this particular index for this element will not be returned the find function will return the index where it has occurred
It at the first time next is the partition function which is basically used to partition the string based on the input that you have given over here so I am saying that partition the my STR add two so welcome will become a one particular variable then we
Have two which would be the other variable and we have the tutorial which is the third variable and all of this is now into a tuple the same thing goes to split function where the data will be split based on the input that you have
Given over here so if I do it split and I have given a space over here so welcome to third tutorial and all of this will be converted into a list so you have to remember that the partition function converts it into a tuple and the split
Function converts it into a list then we have the DPS function so it replaces whatever was given in the previous string and with the new string that it has to be replaced with I want to change welcome with hello welcome so hello welcome to the tutorial let’s move ahead and understand what other
Different operators that we have in Python what is an operator an operator is basically a construct that you use to manipulate data let’s understand this by a real-world example so suppose there are two friends and they want to find out the exact amount of money that both
Of them have so what do you do you take the money from the first friend you take the money from the second friend and add all of that right for example let’s say the first friend has 50 then the second friend has 50 so in your mind you just
See that okay so 50 rupees plus 50 rupees becomes hundred rupees so that way of manipulating the data in your brain that is what you have done here and the operator that you use was the addition operator so that is basically what our operators they are basically constructs that are used to
Manipulate the data so they can be used to derive information or to manipulate to obtain a solution so as you can see we have seven operators over here they are the arithmetic assignment comparison logical bitwise identity and membership operators so let’s go ahead and see all
Of these operators so the first one is the arithmetic operator it’s as the name suggests they are used to perform the arithmetic operations so we have the addition subtraction multiplication division remainder and exponential operators let’s go ahead and see an example of these those Deeter types and
Move over to operators so we have the arithmetic operator let me go to the presentation mode so you can see I have a is equal to 10 and B is equal to 5 so I want to add I want to subtract it I want to multiply them using the star
Operator the division operator is the flow Division then we have the percentage which is 4 the remainder and 2 consec you if stars is basically for the exponential so let me run it so as you can see the addition is 15 subtraction is 5 obviously because 10 minus 5 is 5
The multiplication is 50 10 into 5 is 50 the division is – there are no remainders obviously because it is a multiple of 5 10 is a multiple of 5 and the exponential is 10 into 10 into 10 into 10 into 10 that is a 10 raised to
The power of 5 this is where we use the exponential part of operator let’s move ahead with the next operator which is the assignment operator you would definitely know what the assignment operators are it’s because you have been assigning values to particular variables so this is where the assignment
Operators are used now there are shortcut notations where you can add an assign subtract an assign multiply an assign and so on so you can understand this better if we have our project over here and we go to the assignment operators and let me go to the
Presentation mode I have a is equal to 5 and I am giving values to these particular add sub mul and so on so this is called as multiple variable assignment I’d we’ll get the value 0 subtract we’ll get the value 0 multiply we’ll get the value 0 division gets 1
Remainder gets 1 exponential gets 1 now if you were wondering why I have given division remainder and exponential it’s because I do not want error I do not want to divide anything with 0 because that would give me an error so let’s just go ahead and understand what this
Does let me write what would I actually write for this so ad is equal to ad plus e so instead of writing this big statement I can just say add plus equal to a which means that ad is equal to ad plus e the same goes for subtraction multiplication division remainder and
Exponential so I hope you understood that so let me just run the program for you to see the output so 5 plus 0 would give me 5 0 minus 5 would give me minus 5 then we have multiplication which zero into five which is zero and we have
The division which is one divided by five so that is zero point two then we have the remainder as one and the exponential will be one because anything into one is still one so we have finished the assignment operators next we have the comparison operators so as
The name suggests it is used to compare the values so if fi is equal to 5 it will return a true and if Phi is equal to 6 which will give us a false so these are the various operators we have the double equal to to compare if it is 2
Not equal to 2 compare if it is not true which means that if it is not equal then we have the less than or greater than and less than equal to and greater than equal to so let’s move on to our program and go back to the presentation mode
As you can see I have fire in ten so if I see a is equal to B which means Phi is equal to 10 this will be wrong that means I will get a false over here and then Phi is not equal to B which is true
That means five is not equal to 10 which is true that’s why I have a true over here then if a is greater than B so five is not a greater than ten so I get a false over here so a is less than B which is true that means five is less
Than ten that’s the reason I’ve got a true over here the same thing over here or two if it is greater than equal to it will be true or if it is less than equal to it will be true so you can see the output accordingly let’s move ahead to
The next set of operators which are the logical operators logical operators are basically used to obtain logic which means that if both the elements are true it will be true if either one of them is true it will give us a true or if not which means that give us the opposite of
It so let’s move ahead to the program over here and let me go back to my presentation mode yeah so I have 5 and 0 so I am saying that print of a and B which means that if both of them are true this will be given a true now you
Have to remember something if it is 0 that means it is always false if it is 1 and anything greater than 1 it will be true a and B will be 0 because this will give us a true only if both of them are
True and A or B which means that it is either 5 or 0 so this will also be your true because I am having either one of them to be true so not of a this will give me false because 5 over here is
Value of true so not of a so not of true will be false and not of false would be true let me run the program so you can see the output accordingly how we had discussed it so now that we have understood the logical operators let’s move ahead to
The next operators that are the bitwise operators between operators will be much more understandable if you know what the theory of bits is because they are basically used to manipulate the bits directly so we have the bitwise and or XOR ones complement and the left shift
And the right ship let’s move ahead to our demo it was the bitwise operators and let me go back to the presentation moon so let me just run the program for you so if you and five and six the number will be four if you are it it will be
Seven and then you have the XOR operation that gives us the value three so we have the nought of a which is the north of five will give us the value 6 so next we have the left shift and the right shift of kratom which is equivalent to multiplying with 2 so
Basically what this means is that you will be multiplying 5 into 2 6 times so whenever you have 5 into 2 6 times this will become equal to 320 so it will be 5 into 2 that will be 10 10 into 2 will be 20 and so on
That’s how the calculation works and then you have right shift which is basically the equivalent of dividing by 2 so we have the value as 0 let’s move ahead with the next operator this is the identity operator so identity operator is basically to check whether two elements are identical or not so let’s
Move her to our program that is the identity operators and move ahead to the presentation moon so we have a is equal to 1 2 3 and B is equal to 2 3 4 so is a equal to B this will be your false and a
Is not equal to B so a is not B so this will be true so outputs will be false and true because a is not equal to B and a is not B is actually true so I hope you’ve understood what are the identity operators also let’s move ahead to the
Last operator which are at the membership operators the membership operators are basically used to check whether a particular element exists in another element or not so we use the N and Norton operators so let me go ahead and open that up so we have a is equal
To 1 2 3 and I am asking print f2 is na and 2 not in him so print f2 na and 2 not in E so 2 is actually in a so I will get true and I will get a false over here so that’s what I have obtained so
That basically wraps up all the operators that we have in Python let’s move ahead to the next topic which is flow control so by now you would have already understood that the program runs in a sequential manner or the program’s compilation is done in a sequential
Manner that is line by line what if you want to break that way of compilation so that it can be according to your own advantage that is where you use the flow control so what is flow control flow control is basically altering the sequence of your code so how do you do
That that is done using either the loops or the conditional statements so the conditional statements in Python are the AFL’s and the loops are the for loop and the value so let’s go ahead and understand what our conditional statements conditional statements basically mean that if a particular
Condition is satisfied you execute a set of statements or you miss execute another set of statements so let’s say you are a user who are expected to enter a number and you can enter either a positive number and a negative number and you are expecting the output to say
Whether the number is a positive or a negative so I basically can add a condition saying that if the number is 0 or greater than 0 it is a positive number or else it is a negative number so this is basically a condition where I am giving a condition and asking that if
This condition satisfies you execute these statements else you execute these statements so this is where we use the FL statements let me move ahead and show you our demo for this let me close this up open up if else so as you can see over here let me run program
So as you can see I have a is equal to 10 and B is equal to 15 I’m just saying that if a is equal to B print that they are equal so now this is where you will understand what indentations are so in other programming languages we use
Braces to see which block of code comes under which part of if block or the for loop or something like that in Python it’s not in that way it is basically using indentations so how do you write the if statements or any other statements it is using the
Keyword so over here F is the keyword and then a is equal to B is the condition and now I want to say the set of statements that have to be written under this so I just do a colon and then in pycharm you do not need to worry
Because if you hit enter it will automatically intend it so as you can see this is no four spaces or one type space right so let me just count it for you one space 2 space 3 space and 4 space 4 spaces is how you can see that
This particular statement is under the if block or directly you can just give the tab and it will automatically take care of it and then you have the elsif which is to say the other if conditions so the same way with a colon and then
Print a is larger and then else which is if all the conditions that you have written are not working you just have to execute a certain amount of statements so that comes under the else block so as you can see a is not equal to B so this
Will be skipped then is a greater than B so 10 is greater than 15 which is false so this is also skipped now I go down and finally see that B is larger so that’s the output that I get over here B is larger I hope you have understood how
The if and else statements works these are really simple to understand but they can become much more complex according to your applications in the future so let me just show an example of nested if-else blocks on this so yeah I was seeing as an example you enter a number if it is
Greater than equal to zero so here I am checking if it is equal to zero I just say that the number is zero else it is a positive number so let me go ahead and show this to you so if I enter ten it is
A positive number if I enter a 0 it is 0 over here and if I give a negative number say for example minus five hit enter enter it is a negative number so I hope you’ve understood what are nested if-else blocks also that basically wraps up our FL statements
Let’s move ahead with loops loops are basically used to execute a certain set of statements for a different set of inputs for several times that is where you use loops for example if you have an addition statement and you want to keep adding accordingly but it has to be done
For 10 times 15 times 20 times you would not sit down and write every odd statement accordingly so this is where you use loops because loops are basically used for breaking down the redundancy and to make the code much more smaller so we have two loops in
Python that are the for loops and the while loops so the for loops will have your initialization and all your increment decrement operations that are being done exactly in the first statement so you do not need to explicitly do the condition updation whereas in the while loop you would need
To do the condition updation so that you can terminate the loop so the for loops are used whenever you know how many times you have to execute a certain set of statements whereas in the while loop you may not necessarily know and that’s the reason the user is given the option
To explicitly change the conditions inside so that he can terminate the loop so let’s go ahead and go to our program let’s go ahead with the for-loop first and let me open while loop also and so let us see how was simple for loop works let me just uncomment what is not
Required so as you can see that I have a basket of fruits which is a list of all the fruits that are apple orange pineapple and banana and I am saying that for the fruits in the basket of fruits just put in the fruit as the
Reason I have the output like this so as you can see how the for loop is written for the particular variable in the particular list with the : and with the indentations over here so I hope you understood how this works let me just give you another example so that you can
Understand how and why you should also use loops so let me just uncomment all of this yes so I have numbers one to five and I am saying that I want to add all the numbers in this particular list so if I would have to use explicit statements
Where I add each number it would become very much longer for me so instead of that I just say for I in the numbers sum of the elements is equal to plus equal to of I so if I will take the value 1 then I will take the value 2 which will
Become 3 then it will become 6 then it will become 10 and then 15 so let me go ahead and run the program so as you can see 15 is the output that I have obtained as you can see instead of 5 statements I just had to write 1
Statement and my work was done so next let me show you something called as the range function so range is basically used to give a particular set of variables so if I say range at 10 it would basically mean that the numbers from 0 to 9 so as you can see I have
Obtained the number 0 to 9 meaning go ahead and uncomment the next part of the range function and let me run the program so it is from range 2 to 7 so it will be from numbers 2 to 6 so I hope you understood that also and I have another range function
Here with the skip element so let me go ahead and run this so here I am saying that I want the elements from 1 to 20 but I want to skip the elements in the numbers of 2 as the reason I have 1 3 5 7 9 up to 19 so this
Is how the range functions work they may be used for your applications accordingly to how you wanted to work and then we have the last follow which is the 4 with the else loop so basically what this means is that if you have a for loop and that condition is true it
Will always execute the for loop once the for loop becomes false the else statement will be executed so let me just show it to you so I am saying that how many kicks are there print all the kicks so I have pineapple chocolate truffle and blueberry and then there are
No more cakes left to eat once the for loop is false the L statement will be executed so I hope that also clears up ways in which how you can use the for loops that basically wraps up for loops for us let me go ahead and exit the moon
So let’s go ahead and understand what our while loops just run the program for you so as you can see I have seconds equal to ten but here is where I am explicitly changing the condition because here if you see so as you can see over here that
This is the condition but there are no sort of you know alterations or changes to the conditions the conditions have to be changed by the user itself and that is what I have done here so I’m just printing the second and once the loop is done I just print the blast-off so as
You can see this is basically a countdown and you get up to one zero and then the blast-off so I hope you understood how the while loop works these are really simple examples keep practicing more and more to understand how these work so next we
Have the while and the else loop so it is basically the same concept of the for else loop where if the condition is true in the while loop you execute those treatments as you come out of the while loop and then perform the else loop condition so it’s basically saying hello
Hello hello three times and then asking why are you not replying next we have something called as the nested loop so you can have different sort of loops you can have for loop within a for loop you can have for loop within a while loop you can have while loop within a while
Loop you can have for loop and a while loop anything like that is possible so I am basically printing a pyramid over here so as you can see this is how it works you will understand more about nested loops if you keep working with them that basically wraps up our loop
Session let’s move ahead to the next topic for the tutorial so I hope you understood our flow control is and how you can have the conditional statements and the loops so let’s move out and understand what are functions in Python functions are basically blocks of code which perform a certain particular sort
Of application and they can be run whenever they are called so why functions are required because functions reduce the redundancy and they increase the readability and there is something called as pass by object if you are an old school program oh you would know that there is something
Called as pass by value and pass by reference well pison accordingly supports pass by object which it creates an object whenever a particular function is being called and then accordingly does the work so let’s go ahead with the tutorial so that you can understand all of this better so we
Have functions over here and I have a pass by so basically what is passed by object now as you can see I have defined a function over here which is defined fubar and I’m saying that bar is equal to the new value and print the bar and I
Have answer list which has an old value so I am just saying that foo of answer list so now I am passing the answer list which has the value old value inside it and then passing it over here so now if you can see the answer list will not be
Changed why is that it’s because this answer list which is being passed is actually a new list or it is basically a new object as you can see I have the answer list which has the old value and I pass that into the foo function and I
Will print it so what basically happens over here is now whenever this particular function is being called this answer list is now being created into a new object so this answer list is a new object and this answer list is another object now this answer list object is
Being sent to the foo function where it is being changed into the new value and if I print and now if I run the program for you so now if you can see the old answer list which was there is not being manipulated whereas the new object was created when
The foo function was called then that was sent and that value was being changed so now we have new value and the old value so that is basically what passed by object means he would understand it better if you keep going on programs and understand how each
Object is being handled by Python let’s go ahead and go to the functions which is our tutorial now if you can see over here I have two functions over here which is used to add and multiply so I basically give the parameters or I pass parameters to the two functions and see
That I want to add them or I want to multiply them so if you can see over here I’ve just added one statement which is add FICA merton multiply seven comma five add seven comma 13 and multiply five comer 20 now just imagine if this was not four lines but 40 lines you
Would need to have the sum of a and B sum of a and B product of x and y product of X in Y which becomes really really tedious for you but what you could do instead of that you can just call these particular functions so let me just run this for you
You have 5 plus 10 will be 15 then you have multiply that will be 7 82 5 will be 35 and then you have a 7 plus 13 will be 20 and you have a 5 into 20 will be hundred so as you can see this is how
The functions work and if you want to understand how functions are written it is done using the DEF keyword and then followed the name of the function and then the parameters and accordingly the colon and indentations so that is how you define functions and I hope you’ve understood what functions actually do in
Python so let’s just go ahead and learn a few more of the built in functions let me run the program I have a list 1 0 3 which we will be using later so next I am asking the absolute value of minus 7 so the absolute of minus 7 is actually 7
Now I have the alt function and the any function whenever I use The Awl function it will return true if all the values in it are true the any function will return a value true even if one of the values are true so all will give me a false
Because I have a 0 over here and any will give me true because I have at least one element that is true so as you can see these are pirates next line function is basically used to give the length so 3 over here then I have the
Minimum and the maximum function so the minimum function is used to give the minimum of the list that is 1 0 3 will be 0 over here and the maximum will be 3 so I get 0 and 3 over here next is some of the list so basically the sum value
Is used to add all the elements in the list and it’s just node for list you can even use it for tuples you can use it for sets all other sort of data types this is just an example for you to show the different types of built-in functions that Python already has for
You to use and I have the sum function over here which is 1 plus 0 plus 3 1 plus 0 is 1 and 1 plus 3 is equal to 4 that’s the reason I get a foo and then I have type which is used to give the type
Of the data that I have passed to it so if I am passing a list I will get the class as list so that basically wraps up the session for functions let’s just move ahead to the last topic of our day session file handling you would definitely know what is a file it
Is basically where you have data stored inside them so what is file handling well Python provides you libraries which you can use to handle files within Python itself so you can read and write data to and from a file according you to however you want to so what are the
Steps that you need to follow there are basically three steps you open the file you can perform your operations and you have to close your file closing your file is really important because what happens is whenever a file is being read or written to it is basically
Bought into the memory now if you do not close the file it will still remain in the memory and there are chances that the file gets corrupted so to avoid that damage please make sure that you close your files these are the different operations so for opening a file you use
The open command and then filename and the mode so mode may either be the read or the right or the append mode then to read the data you use the read function to write you use the right function and to close you have the file door close
Function so let’s move ahead to our tutorial and let me open up file handling so as you can see I have some data in this particular file that is this is my txt let me just close all of this Orla pieces remove all the data that this has
Yes let me just go ahead and see if this an open file store py let me go back to my presentation mode so now we have a file object so whenever you want to open a file you have to make sure that you open it into a file object
So now I am just using that so file object is equal to open and I am saying that I have to open my txt and let me just open it in the right mode and then I am just saying for text in the range of hundred file object or right this is
My text and then I close it so this is one part of where I am writing data into the file the next part is where I am reading the data from a file so I just have a count to see how many lines of
Data is there in the file so I have file equal to open my tht in the read mode then I have four lines in the file count is equal to count plus one so just print that our count is equal two lines are present count lines are present and then
I close the file so as you can see I opened a file I perform my operations and I close the file over here also I opened the file perform my operations and close the file whenever I have the right mode write mode is basically used
To write data into the file now if there was data that was previously present in the file that will be removed and rewritten or overwritten so that is where we used the write function we have the a function which is used to append data it will not delete the previous
Data that was available but just add data into it and then the read or read mode is used to basically read the data from the file so let me go ahead and run this for you so as you can see right now there are a hundred lines present let me run this
Again for you there are a hundred lines present and let me show you that there are hundred lines that are present right now so that’s simple so if you saw that previously ira i ran the program two times and it was still showing hundred now let’s see what happens
Now it should be 200 that means a hundred lines are added into the file now our gain hundred lines will be added that becomes 300 so basically that is how we have a file handling in Python you can accordingly keep changing and keep experimenting to know more about it
So that basically wraps up this session for python basics so let us just go ahead and find a summary of what we have studied we basically studied what python is its features and who are the companies who use python in the industries then we installed Python we looked at the different data types
Python has the operators that python has and then we understood waters flow control what are the functions and what is file handling that basically wraps up a session for Python basics I hope all of you have had a good time thank you happy learning you
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Got a question on the topic? Share it in the comment section below. Please drop a comment if you need the data-sets and codes discussed in this video. For Edureka Python Data Science Course curriculum, Visit our Website: http://bit.ly/2FBUtO7 Use Code "𝐘𝐎𝐔𝐓𝐔𝐁𝐄𝟐𝟎" to get Flat 20% off on this training.
Went through lots of classes from different tutors…this was best…i got hopes that I can learn this….thanks alot❤
I think python is difficult to learn before this video. Thank you sir for clear cut explanation 🙏
Yess
are you a jain
nice
Yes
Ok
wonderful, concise and clear
thnx…coz of you i got 49/50 in my practical exam
nice one
Love you gulsan dadda♥️♥️♥️♥️♥️♥️♥️♥️♥️
yaa plz go ahead
Yes
Yes
Thankyou for your effort❤️
Can get this slides, very useful
Edureka pls make video on guide to algorithms and flow charts for beginners
Yes
very useful
Its easy
Very nice tutorial. Thank you so much.
can u please give me the source code used in this tutorial
Awesome tutorial !
confirmed! Thanks
Yes sir
please provide the slides
👍🏻