Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

Complete Python Notes

Loading...

Python for website builder

Fahim A / Mumbai

8 years of teaching experience

Qualification: M.Sc (Integral Institute of Medical Sciences & Research (IIMSR), Lucknow - 2012)

Teaches: Biology, Botany, Zoology, Science, B.Sc Tuition, NEET

Contact this Tutor
  1. In this complete Python course with notes I'll teach you Python from the very beginning to very end So guys without wasting any time I'll switch to my browser And I'll search for " Python Install " And I've searched for it, as you can see a link has appeared to download Python from "python.org" And I'll download the Python by clicking on it I'll download the latest version which is v3.8.5 But it is possible that when you're watching this note, more latest versions have been released So there won't be any difference you can download the latest version Once we've downloaded the Python Installer we'll then execute it But because it is still downloading so I'll open a new tab and install another software And I'll search for "VScode install" And as soon as I searched for "VScode install" Look here's a link "Download Visual Studio Code for Mac, Linux or PC" It means that I can download VScode from it's official website "code.visualstudio.com" So download the VScode "Visual Studio Code" this page must open while downloading Right now I'm working on Windows so I'll download VScode for Windows And if you are using Windows 64-bit operating system so click on 64-bit or else 32-bit So how will you know that you're using 64-bit or 32-bit? Go to "This PC > Right Click > Properties" And when you'll visit the properties of your PC you'll get to know if you're using 64-bit or 32-bit And mine is "64-bit Operating System x64-based processor" So I'll download VScode for 64-bit So I'll click on " Download for Windows " And now as you can see it is downloading In most of the cases it'll automatically sense your operating system And it'll download VScode according to your operating system And now you've to accept this agreement and then click on "Next" Now pay attention as I've checked these boxes Add "Open with Code" action to windows explorer ' ' Add "Open with Code" to windows explorer directory context menu ' And ' Register code as an editor for supported file types ' When you'll do this so you'll gain some benefits which I'll tell you later But make sure to check these boxes I don't want some options to appear for me and not for you, so make sure to check these 4 boxes I cannot emphasize enough That's why I'm telling you again & again to check these boxes Then click on "Next" and then on "Install" And it'll install your Visual Studio Code And as you can see my "python-3.8.5.exe" is also downloading And as it'll download we'll execute this too But look my VScode & Python are installing right now Now by taking your time I want to tell you about Visual Studio Code and Python
  2. Because if we take some time and understand about them, so we'll get a good feeling Because learning Programming language just by installing the soft-wares is not good We've installed 2 soft-wares just like you install games Just like you install excel in your computer If you ever have installed any software in your computer or if you haven't So you can install that by following the steps I guided Now it is saying "Completing the Visual Studio Code setup wizard" So I'll uncheck the "Launch Visual Studio Code" because I don't want to open it right now Pay attention on the technique I'm going to use to open it But for now let the Python install We'll work when the download will finish So I'll just say 2 lines about VScode And I'll also talk about Python The Visual Studio Code is a IDE cum source code editor Which means you can edit your source code in it So look it is displaying if you write half name of a function so it'll complete that function I'll also tell you the advantages of this But for now just understand "It is going to make our life easier when we'll do Python programming" So for now what we were supposed to do in Notepad, we'll do that in VScode Visual Studio Code is just like an advance Notepad What is Visual Studio Code? It is like an advance Notepad But it is a type of Notepad which provides some extra features to make your programming easy So I've opened my Download tab in Chrome And I'll run this 3.8.5 What am I doing? I'm installing the " Python-3.8.5 " I'll emphasize enough on one thing that even you'll ask why? Make sure to check "add python-3.8.5 to path" And then you just have to click on " Install now " And after clicking on " Install now " you have to click on "Yes" And it'll be downloaded in your system And it already has told the path where it'll install So we don't have business with that we'll just wait for it to finish installing And it installs quite quickly I've SSD so it'll install faster And maybe it'll install slower in your system But I'll recommend you to wait a lil bit It has downloaded a little quickly because my system specs are... ...Not so good but average But sometime I saw people use computer of 2GB or 4GB RAM So my computer might work faster than them So I'll open the "Windows PowerShell" because it is my terminal You might be using Linux or Mac You can use any computer or any OS Just keep following You have to write "Python" And as you've written "Python" it is displaying "Python-3.8.5" So now just write " Exit() " and make sure to add parenthesis After writing this when you'll press Enter you'll be exited from Python
  3. Another thing that you can do to check Python Installation is, just write "Python --version" And it'll tell you the version of your Python My version is 3.8.5 It is displaying me the version And you can see the installation was successful We're all set to code As I'll write "pip" here, look it is displaying no error It means that Python & pip are both ready. What are they? I'll tell you You can also write "pip --version" and it'll display your pip version And it'll also tell you the installation path of pip According to me we're all set Now we'll open this folder Chapter 0 - Introduction And we'll open the notes which I've made just for you I've made these notes with a lot of efforts When I make notes I make them wonderful otherwise I don't But this time I've made quite wonderful notes I've only added information you need So first of all I wanna talk about people who haven't code in their lifetime and Python is their first language And we'll first enlighten ourselves with "What is programming" When I'm in conversation with you I'm using Hindi or English as a language to talk I'm speaking Hindi & sometimes English as well You may speak any language whether it is Punjabi, Marathi or Nepali To communicate with a fellow person you're using a language as a medium to communicate When you travel in a car you use road as a medium Which facilitate you in transportation So the medium between Me & this Computer.. If I have to command the Computer to do or don't do anything That medium is Python Which means Python is a way to give set of instructions to the computer Which will let the computer to understand what exactly am I tryna do Exactly which task I wanna perform That's about programming I've written here "Programming is a way to instruct the computer to perform various tasks" I want you to read the notes Once you watch this note & read the notes everything will be cleared And I've made the notes quite wonderful So in my opinion there's no excuse for you not learn the Python What is Python? Python is a simple & easy to understand language Mark the words "Easy to understand" Because this is the core reason for the popularity of Python Python is so easy that anyone can learn this It is possible that you haven't done programming and your maths is weak Even then you can learn the Python and take advantage of its power And you can use Python for your advantages Python works like Pseudo code Which means the readability of Python is quite good If you don't understand "Pseudo Code" then let me tell you Pseudo Code is a template of a code to command the computer what to do
  4. Which programmers translate in any language But if someone will take a look at the code of python, they can easily understand what that code is about Irrespective of whether he knows the programming or not They'll look on to the Python code And they'll say "Yes it is readable to me" The code in this line is about this and this code is about this These all things remain clear in Python Now I've told the features "Easy to understand" "Less development time" If you're creating a game in Python and on the other hand you're creating another game in C++ If you create that in C++ then it'll take some time for you to learn that But in Python you can build that very quickly It is a free hand open source. You have to pay nothing Python is free & this note too So there's no issue Now "Python is a high level language" Which means you don't have to perform memory management Just like you've to manage the memory in C and C++ Python is build for the people who just want to focus on their work And along with that Data Scientist & Machine learning enthusiast can take the advantages of Python Because it is the language in which you don't have to manage the memory and you don't have to be worried about the memory leakage So Python gives you the advantage of High Level Language if you're a beginner And while minding your own business... ...If you don't want to dive deep in this And if you don't want to do the hardcore or below level system programming then the Python is for you It is portable Portable means it is supported in Windows, Linux & Mac and if a code is written in Mac then it'll also work in Windows And along with that it is fun to work with And I would like to add a personal point, From Python you can do Data Science, Machine learning, Game Development & websites development In fact I've build my personal website in Python I've build this using Python Django frame work. This will be a source of motivation for you And look how cool is this, It has so many visitors and I never face problems in it So this is the motivation for you And we've done the installation And after writing "Installation" I've written "just install it like a game" Just like you install a game or a setup Which you download from the internet just like Chrome Browser of VScode We just have to install it just as usual, that's it. So I hope you've liked this introduction I won't waste plenty of time on the introduction And I'll now directly jump to the Chapter - 1 And in Chapter -1 1'll tel you how we can use Modules, Comments & pip Chapter I - Modules, Comments & Pip OK guys, welcome to chapter -1 in which we're going to learn about Modules, Comments & pip But we haven't learned how we will write our first program
  5. So first of all I'd like to tell you How you can create your first Python Program So if you've followed my steps while installing VScode So you either create a folder in VScode by searching on "Type here to search" Or let me tell you a shortcut Just do right click here And if you've done the installation correctly then this "Open with Code" will appear here So just click on it So when you'll click on that then this VScode.... Which you find weird if you're not familiar with it This will open in this folder Which you'll be able to see the content of this folder here But if you open the VScode from "type here to search" then no folder will be open already You've to open the folder manually by going to File> Open Folder I don't want you to make so much efforts. That's why I've told you about the shortcut Do Right Click > Open with Code and just open the folder And your folder will be opened Now by clicking here you can create a program So I'll make a program with a name "01 _ Hello.py" You can name it anything you like I'm naming it "01 " What will the advantage by naming it in this format? The benefit is when I'll give you the code you can easily understand that this is the first program of the first chapter So this will be the advantage of naming them in this format I'll number them by 1 2 3 4..... It is inside the "Chapter-I " folder and I'll definitely give you this code So you won't face any problem ever So I've made this Python file Now I'll click on the "Extensions" Can you see the Extensions? You have to click here Now what are the extensions in VScode? Just like the extensions of Chrome which increase the functionality of your browser Just like you've installed a software in your computer What does that software do? It provides some extra functions to your computer Just like you install the Apps on your phone which helps you to perform various functions Just like that we can install the Extensions in VScode So I'll click on it & write "Python" When I've searched for it look an extension appears from the Microsoft let's install it And as I clicked on it. it has been successfully installed So it is telling me that "You haven't selected the Python interpreter" "Kindly select the Python interpreter" So you either select the interpreter by clicking here or by clicking here where "Select Python interpreter" is written So when I clicked here it automatically sensed that my Python is installed here As you can see This setup may bother you sometimes So you don't have to worry if your Python interpreter in not being detected The reason for that is you haven't installed the Python correctly so please install it again Or else it always detect automatically in majority of cases You don't need to enter the interpreter path in majority of the cases Just check your Python Installation if you're facing this issue
  6. I'll click on "Python-3.8.5" and look here's my python version It is displaying 32-bit which means I'm using Python 32-bit And I'll dismiss this for now And they have mention this here And they've also mentioned here But what I told you was enough for now So I'll just click on these 2-pages Icon This is my explorer which means my files will appear here You might see a folder with name ".VScode" There are chances that you might see it but sometimes it gets hidden So mine is visible Do not panic there's no issue it just create its folder internally to work So what ".VScode" is? That's just a folder created by VScode to store its files So we don't have to be panic by that at all We've created a file with name "Ol_hello.py" And we're going to write code in it Without being tensed just write " print("hello world") " just like me Python doesn't contains semicolon(;) Now you can see as I'm scrolling the size of my font is changing And I've customized my VScode If I go to the setting And if I search for "Zoom" so look I've checked this "Zoom the font of the editor when using mouse wheel + holding Ctrl" For now just write "hello world" and click here To run this file you have to click here on your 'Run' button And look here "Run Python file in terminal" It'll run your file So look it produced my output for "hello world" So if I ever have to run my Python file I can do that just by clicking here directly By any chance if this doesn't work It'll work in 99% of the cases So the another way is just write "python 01 " and press the "Tab" key and it'll auto- complete the name Or you can also type the name manually "01 hello.py" And when you press the 'Enter' so look it has executed this file What does this file do? Just print "Hello world" , nothing more than that Now what we've learned till now? We've just learned about the Python that it is a programming language Which help us to communicate with the computer We've installed the Python & VScode and we've put our complete setup here to do the code Now what we'll do is.... Now we'll dive deep in to the code we've written & in to the Python What is the meaning of this & how can you write your own code? Now you'll say "I've been walking on your steps" you told me to write this I do so This code ran it is quite perfect So congratulations if you've written first code in your lifetime If this is the first line of code of your life I want you to write congratulations in the description Write Congratulations for yourself It'll make me happy when I'll see your comment Let's move forward And see what have I written "Let's write our very first Python program" which we already have written That file can consist of any name Just keep the file name such as it won't crash with the built-in module
  7. Don't name the file "ABC" or "Flask" We'll have a look on built-in modules For now you can name it "hello.py" or you can also name it what I've named Now look here, "Print" is a function What are functions? We'll discuss this later For now just take this line as a black box which prints "hello world" We'll learn how is this functioning We executed this file & "Hello world" has been printed on screen Now we'll talk about 'Modules' What is Module? Module is a file containing code written by somebody else Which means I can download this file from internet & install in my computer Program written by someone else Or I can use set of programs written by someone else How cool is this, that I can use it in my program Which means I can import some modules Let me give you some examples of Modules For eg. You do "import os". OS is a built-in module I don't have to install it It is a built-in module It was written by someone else but I get this along with Python But if I write "import flask" Let me save & run it And look when I command "import os" so it didn't give any error And now if I write "import flask" Now when I ran this file by writing "import flask" so look it is displaying "module not found error" You haven't installed the module And now if I write "tensorflow" here Now you'll ask what am I writing? What 'tensorflow' is These are the name of some modules about which we'll talk And now if I run this so it is displaying "No module name 'tensorflow' " It is saying " I don't know what 'tensorflow' is " What have you given? I don't know any module with name 'tensorflow' So that's why we have to install the modules externally in our computers This was the built-in module that's why it worked Now let's have a look on "What is built-in modules" And what are external modules I've written in notes for you Now let's first talk about 'pip' I've talked about the modules that if I have to use someone else's code in my program Let me give you an example. Just like I'm using 'os' I didn't write those functions but I can still use them Same as that I can also download more external modules & use their functionality 'os' module provides functionality to list all the files & folders of your directory And It also gives a lot of functionality But we'll not talk about them right now We'll head forward For now just understand that modules extends the functionality of your programs What is pip? 'pip' is a package manager of Python And you get pip bu-default when you download the Python And you can install packages with the help of pip Do you remember that I wrote "import flask" here Like this And I got the error "You haven't downloaded the flask but you're trying to use it" Do you know what that error occurred? It is because I didn't installed the flask in my computer I can install flask in my computer by writing... "pip install flask"
  8. I repeat "pip install flask" "pip install flask" means Download the flask from internet... ...And install it in my computer So it'll do all the work automatically As I'll press 'Enter' So look it started downloading 'Flask' And it has installed the flask for me So this is how I can install modules For now I'll remove 'Flask' because I'm not gonna use it 'Flask' is used to build websites I'm not building any website So I'll now step back... And I'll talk about the types of modules So I've talked about the pip That if I ever have to download & install any module so I can use pip There are two types of modules in Python Built-in Modules & External Modules Built-in modules are the modules which you can use.... Without downloading or installing them Because they are pre-installed with the installation of Python So you get them when you install Python But you've to install the external value with the help of pip You need to make some efforts they are absolutely free But you need to make efforts to install external modules You have to write "pip install" followed by the name of module And then you are able to use them Just as we saw the example of 'Flask'. I had to install the 'Flask' by writing "pip install flask" Now I've written some examples of built-in modules Like os and abc And some examples of external modules are 'tensorflow' 'flask' If you want to install 'tensorflow" or 'flask' so you can do that with "pip install " Now let's search for... built-in modules like 'os' & 'abc' So I've searched for "built-in modules in python" And a page "Python module index" has opened from the Python's official documentation In which I get all the names of built-in modules Which I can use So this was the story of modules In future we'll install, use & learn how to take advantages from them So let's move forward & see how we can use Python as a calculator We can use Python as a calculator Open your terminal, You can do that by Right Click> Windows PowerShell And write "Python" here When you'll write "Python" here look "Python-3.8.5" has appeared here Your repel will be launched here And repel means... If you search for "R-E-P-L" on internet Read-Evaluate-Print-Loop It is written REPL means Read-Evaluate-Print-Loop Now what does Read-Evaluate-Print-Loop means? Read-Evaluate-Print-Loop means what it shows Read the code, Evaluate the code, Print the code and start the loop Let me explain you in brief I've opened repl of Python You'll see this interface when you'll write "Python" in terminal And if you write (6 + 5 ) here so you'll get 11 What did it do? It read the ( 6 + 5 )
  9. It evaluates the ( 6 + 5 ) And then it printed value & returned to the loop for the next value I've written ( 3 + 9 ) It'll print 12 And now if I handover a bigger value so it'll definitely print the value quickly because it is a computer So no surprise is there But we can add any valid Python code in Repl and it'll execute that line-by-line Just like if I add "Print Hello World" which I wrote in VScode If I write "Hello World" in the same format as VScode so it'll print "Hello World" Now you'll ask why don't we use Repl and Why do we write python file? So we write Python file because as time goes on, our code will be so big... That we wouldn't we able to manage that in Repl And the second thing is when I'll close the terminal the sequence of codes from the Repl will be lost And it'll become inconvenient for me to keep that code And here it is saved in a file & I can open & run it whenever I want So it is quite convenient for me to use file But if I have to do something quickly and if I want to see how this thing works in Python So I use Repl as well So what is the use of Repl? "You open the terminal, wrote Python, executed 2-3 lines of code then closed it" This is the role of Repl To exit from Repl Write "exit()" & don't forget to add parenthesis because it is a function To call the function we use Open & Close parenthesis() When you'll press 'Enter' after writing "exit()" You'll be exited from your Repl You'll be back to your terminal So we've learned what Repl is... And this is how you can use Python as a calculator This was about Repl. Now what are Comments in Python? So guys we'll now have a look on "What are comments in Python" In Python 'Comment' is a text which you want to write but you don't want to execute I repeat "You want to write that text it in your program but you don't want to execute" Let me give you an example Let's suppose I want to mention "I created this file" So I'll write "Harry" in "Author" And let's suppose I want to write some more things here "Licensed to: ABC Company" So if I write this in my program.... And I definitely want to write this so that whoever gets this file must be enlighten to this If I run this program right now so it'll ask "What's this?" "What have you written?" So a problem will be created here Now if I don't want these 2 lines to be executed..... So I'll add a pound(#) symbol Symbol(#) means 'Single Line Comments' And look when I added pound(#) symbol, VScode has turned it Green This means "This line won't be executed now" My Python interpreter will ignore this line And when I'll run this file so look my "Hello World" has successfully ran And I'll run it again... Now I can successfully run this program But if I don't comment this out So it'll think "Author: Harry" is a valid Python code And it'll try to execute "Author: Harry"
  10. And it'll fail while trying to execute that code And because it'll fail, so it won't be able to execute "Author: Harry" "Licensed to: ABC Company" is the second comment I can write comment in this manner too... "Importing the OS module" Sometimes you may want to write comment after the line of code So what it'll do? It'll read this code till here and when it'll get the pound(#)symbol, it'll ignore the line So this also is a valid Python code. You can do commenting like this Now we have two types of comments as I've written in notes 1- Single Line Comments 2- Multiple line comments You can write Multiple Line comments with Triple single quotes("') I have written the single line comment just now with the help of pound(#) symbol And if you want to comment this out with Multiple Line Comments So its style will be this.... So at first I've done the Single Line Comment with the help of pound(#) symbol Now I'll use triple single quote("') for the opening And triple single quote("') for the closing What I've written in between Triple Single Quote won't be executed Triple Single Quote will work as a Multiple Line Comments And I can write many other thing here I can write "Thanks for reading" or anything I want And when I'll run this... This will be ignored as it is a comment So comment means you can ignore the text whatever you want You can add as many comments in a single program You can also add Single-Line Comments & Multi-Line Comments in a single program together So look I've used Single-Line Comment and here I've used Multi-Line Comments So I can use combination of Sing-Line & Multi-Line comments I hope you've liked this chapter This is the end of this chapter A very short chapter in which we wrote our first Python Program And if this is the first program of your life so comment down below. I wanna know it too I feel more joyous than you, when I see the comments that someone has written their first program with me I want you all to comment And along with that we'll move to the chapter-I Practice Set Where I've short listed some questions for you So let's do some practice of Chapter-I Chapter I - Practice Set Guys it's time to solve the Practice Set So let's do this And I'll solve the practice set for chapter-I which I've created As you can see I've opened the "chapter-I " folder And this is the Practice Set I've created for you make sure to download it I've created this for you Now let's have a look on the first question Write a program to print "Twinkle twinkle little star" poem
  11. So I'll search for "Twinkle twinkle little star" I'll also write "poem" here So I'll open this website "Twinkle, twinkle, little star," "How I wonder what you are!" "Up above the world so high, Like a diamond in the sky." So we've copied the "Twinkle, twinkle, little star," poem "Program no. 2" "Sol for prob no. #1" And we'll name it "twinkle.py" And what I'll do here is.... I'll simply write "print" And along with that I'll paste "Twinkle, twinkle, little star," But.... Pay attention when there is more than 1 line in a string It'll print whatever written when I'll add the double quotes(" ") But if I run this now... So look an error occurred here The reason for the error is... You can't write this string in the double quotes(" ") like this Whenever you have a string which is occupying more than 1 line You have to write the string as you write... ...comments with triple single-quote('") So if I print this poem by adding triple single-quote so look this poem has been printed And if I want my poem to print in this format So I can do that... and now I'll remove the extra lines So that my poem will print all together without these tabs So my poem has been printed So if I ask you "What was the take away from this question? " So the take away was.... You can write a paragraph which occupies more than 1 line in single-quotes(' ') You may confuse that "Single-quote was used for comments?" It was used as comment when it was alone But if this is followed by "print" so it has become a string literal But when it is alone so it'll be classified as a comment So if I write.... "This problem is a solution of... ...Problem 1 of.... ...CodeWithHarry Practice Set" So this is the solution of problem-I of CodeWithHarry Practice Set I've pressed " Ctrl+ S" and now if I run this so the output will be the same Because I've added this as a comment So I can write "This is also a comment just like the above line" This is the multi-line comment I can span this in multiple lines And the one below is the single-line comment Which means there will only be a single comment in a single line I hope you've got the solution for problem-I and you've also got the point I was talking about And what I want to clarify by solution of problem-I Let's talk about problem-2. It is quite simple problem And I want you to solve this on your own
  12. "Use REPL and print the table of 5 using it" And now if you want to print... ...table of 5 using REPL So you can run REPL just by writing "python" And if you don't know what REPL is.... So I've told you in the last note and you must know it Look I've written here REPL = Read, Evaluate, Print, Loop And if you write something in it then at first it'll be evaluated & then it'll be printed So now if I add 5* 1 So the answer is 5. Now you'll ask why have I added * in place of product sign Why I haven't used "x" I used (+) for the sum, (-) for the difference (l) for division But why use (*) for multiply So this is the rule of computer & Python programming That if you want the product of number so you must use (*) as a product sign This is rule followed by many programming language And in most programming language ( * ) is used as a multiply operation So I've done 5* 1 And now I'll do 5*2 And then 5*3 And in the same way 5*4, 5*5, 5*6. Oh I accidentally added (%) I mistakenly pressed the 'Shift' key So I'll write 5*5 and then 5*6 And then 5* 7 And in the same way I'll write the whole table 5*8, 5*9.... . ...And along with 5* 10 1'll finish the table I mistakenly added (%) sign here so please excuse me for that Don't use this So you've printed the table of 5. 5, 10, 15, 20, 25, 30, 35, 40, 45 & 50 So many congratulations to you Now I've given the solution for question 1 & 2 Let's move to the third one "Install an external module & use it to perform an operation of your interest" This is the very subjective question You can do anything. Possibilities are endless I'll show you something very interesting I'll go to the internet & search for a module "Playsound" You may not know about this module But this module help you to play sound So I'll open the terminal & install the "playsound" with 'pip install playsound' So my "Playsound" has been downloaded Now I'll see how I can use this They have mentioned "Just give the path of any .mp3 file" And.... These signs were from REPL so I've removed them I've saved it So look I've added "from playsound import playsound" And now I've add the .mp3's path So let me search for a .mp3 file on my computer and I'll add it's location here So for convenience I've moved this mp3 file here I'll copy this path and here's file with name "play.mp3" And I'll complete its path by adding another back-slash(/) So I've added the complete path for mp3 So whenever you're giving the path in windows... I'm telling you something very important I want to tell you something that you've to use double back-slash(\\) here Now many of you might think "Why are we using these double back-slash(\\)" What's the meaning of using double back-slash(\\) ? When I add a character after a single back-slash( \ ) so that character is classified as escape sequence
  13. I'll tell you more about this later but for now just remember that you've to add path in this manner Look when I'll run this program... [MUSICS PLAYS] Play.mp3 file..... [MUSIC CONTINUES] Play.mp3 file started playing So what I've done is... I picked a module And used it in 2 lines. Have you seen the power of modules? I didn't know how to play .mp3 file in Python But even then I was able to do this Do you know why? Because I was getting help from the 'playsound' module And this is quite awesome man So question #3 has been solved Now let's move to the question #4 "Write a Python program to print the contents of a director using OS module" "Search online for the function that does that" They are trying to say "there's a module with name OS..." Using this OS module what we have to do is.... We have to print the content of a directory Which means we'll be given the directory and we have to print its content So how I can print the content of directory? Let me check... I'll search... "content of a directory" So someone has asked about this on Stack Overflow And someone has replied that "os.listdir function can do this for you" By the way I already knew that but for your information I searched this Now if I open... "04_pr_04" And here I'll write "listdir.py" So I'll write "import os" here And then I'll write " print(os.listdir( ) ) " And I also have to add opening & closing parenthesis as you can see they have mentioned here So when I'll run it... All files that were in that folder has been listed here Now " How is it working? " " What is square bracket? " we'll learn this later But for now we have had a look on the powers of modules That " We can do things which we haven't learned yet with the help of modules" So if you want to learn how to run code in python Even that would be very beneficial for you That you took the code from this website and your code has become very powerful Doing all these stuff is a skill And we learned this in this chapter So last question: "Label the program written in problem 4 with comments" It's super simple. So I'll label it here We've to label it in this manner 1..... I personally prefer the single-Line Comments that is because I can write... "Author: Harry" "Location: Mars" And in date I'll add.... 23/09/2022 So I've added the date And when I'll press the ( Ctrl + / ) I repeat ( Ctrl + / )
  14. So I can do Commenting & Uncommenting Because this is the built-in feature of VScode so I find it quite convenient As you can see how I'm doing... ...Commenting & Uncommenting with ( Ctrl + / ) So if you want to comment any line just press ( Ctrl + / ) I hope you found this practice set helpful And now this line won't be executed Because it is a comment Let's run this Now look I tried to run this program and it is working as earlier With this I've completed the chapter-I Now I want you people to download these codes & notes I've given everything You can find this on the website everything is ready You'll get the chapter-I notes & practice set And I'll also give you this "Play.mp3" You can add any music or song you want here And this is quite amazing. You can build a music player with the help of Python There are a lot of thing we've to learn So let's move to the Chapter-2 And let's explore things Alright guys welcome to chapter-2 And in chapter-2 we have Variables & Data Types Chapter 2 - Variables & Data Types "What are Variables & Data Types" I first want to explain you this So what I've done is... I've opened this folder in my VScode In which I've kept 2 PDFs First one is the chapter's PDF And the second one is Practice set's Now I first want to tell you what are Variables & Data Types Let's keep aside the Data Types & talk about Variables "Variable is a name given to a memory location in a program" Isn't this statement sounds scary? Let me make it easy Whenever you write "a = 30" in a python program So a variable is created Which means " a " works as a container which contains " 30 " Let me create a program and show it to you And I'll create a program with name "01 _ variable.py" In this program I'll write ( a = "harry" ) And let me select my Python Interpreter Whenever you open a new folder in VScode So it ask you "Which Interpreter you wanna use? " Only if you have multiple interpreter That's why that pop-up appeared To fix that Click here and then select the Python interpreter and it'll be gone When I write ( a = "harry" ) Now " a " contains " harry " "Harry" is a name When I write " b= 345 " So " b " contains "345" What is " b " ? " b " is a number If I write " c = 45.32 " So " c " contains "45.32" Which again is a number but a different kind of number Which means this number contains decimal So this is a different kind of number Now a question may pop in your mind " That how Python will know that it has to store a number? " You have to store string or what, in Python... Like "Harry" is a string And this is an integer This is a floating point number
  15. Whenever you write (a = "harry" ) in any programming language So a becomes a container which contains this It can be a number or a name or anything it'll be stored in " a " Now pay attention on my words If I write ( a = "harry" ) So Python automatically identifies it as string literal because of double quotes(" ") Literal means it is a string by-default "harry" is a by-default string because it is written in double-quotes(" ") 345 is written without double-quotes(" ") it means it is an integer And I haven't written something like .0 That's why it is an integer by-default "45.32" is a float by-default So we've created 3 different kind of variables Now what is Data Type? Data Type is it's 'type' Just like a is an string type variable " b " is an integer type container for eg. if you go to your kitchen then you'll find containers You mom has put pulses & rice in containers Salt & pepper in different containers Water will be stored in bottles It is not like you've put pulses in water bottle Yes you can store pulses in water bottle but you don't usually do that Different kind of containers have different roles Same as that Python Programming Language contains Data Types Data Types means the type of a container For eg. It is an String, It is an Integer It is a Float Now back to the notes Now if you read " A variable is the name given to a memory location in a program" It means when we write "a = "harry" " or " b = 345 " So it stored in your memory and... And you can access in the name of " b " So we have given a name to that memory And that name is " b " Hence the definition I've written a = "harry" "b = 345" & "c = 45.32" I've taken different variables here It's not mandatory for me to take the same example every-time What is variable? They are containers to store value. What are keywords? Reserved words in Python, for eg. There are some reserved words in Python Let me give you the example For eg. There's a word named "Deaf" in Python which.... . ...You'll know why it is used only when you'll use it What is Class? Class is a different kind of Keyword Which is being used for oriented programming in Python And like this there are many keywords in Python that are reserved And when you'll search for "Reserved keywords in Python" So you'll get a lot of results If I get a result from "python.org"... So I'll open that because I'll get the updated list there If I open this.... And if I select my Python version ( 3.8 ) So look... "Keyword testing for Python keyword" So look they have mentioned here how you can test the Keywords But I want the list of keywords... So it is here These are keywords which you get in Python Programming Language "Import" is a keyword which we use.
  16. "In" is a key word & "Is" as well which means they are the reserved keywords in Python You cannot make variables using their names And if you can make it... so it's not recommended If you create a variable with their names... So it might break the program That program may not function properly and that's why we avoid them So I'll move back to the notes Now let's talk about 'Datatypes' As I've told you "The type of the container is referred as Datatype" We have a lot of Datatypes in Python But primarily we'll talk about only 5 as a beginner 'Integer'...... 'Floating Point Numbers'.... ....'Strings'...'Booleans' & 'None' Let me explain one-by-one 'Integer' means 1...2...4...8... -1...-8...-9... These are all 'Integers' same as Maths We're talking about the same 'Integers' What are 'Floating Point Numbers' ? It means the numbers which contains decimal(.) 3.8...9.2...8.8...7.9...8.24...9.81...2.88 These all are 'Floating Point Numbers' What are strings? 'Strings' are collection of characters enclosed in Single Quote(' ') or Double-Quote(" ") And if I want string in Python so Double-Quote(" ") is not necessary I can also use Single Quote(' ') This also is a 'String' So whether I can add Single Quote(' ') or Double-Quote(" ") There's another way to write a 'String' in Python that you add that string in a triple Single Quote( But we read triple Single Quote( ) is use for comments "If something is enclosed in triple Single Quote( ) so it'll be referred as a comment" But if you write "a = '"harry""' so this will be a string And triple Single Quote( ) is used when you want to include Single & Double-Quote as a part of string in your string Let me give you an example. Let's suppose if you've written "harry" in this form... In double Quote(" ") We cannot use Double-Quote(" ") in this with that ease But if you want to use Double-Quote(" ") as long as you want So just enclose this in triple Single Quote("' "') And when you'll do it, this will be your valid 'String' So we've learned 3 methods to write 'Strings' Single Quote(' '), Double-Quote(" ") & triple Single Quote( Let's print them. I'll first print (a) And then print( b ) & in last print ( c ) I'll print ( c ) and then I'll show you Look "Harry, 345 & 45.32" has been printed here Now if I enclose this in Double-Quote(" ") so what will happen? Even then the output will be the same And what if I enclose this in triple Single Quote( )? Even then the output will be the same So we've learned three methods To write a 'String' And now I want to tell you, When I'm enclosing it is Double-Quote(" ") So I cannot add a new line But when I'm enclosing in triple Single Quote( ) So I can easily include a new line here "Is a good boy" And now if I run this, so look "Harry is a good boy" has appeared So writing 'String' become easy when I enclose the string in triple Single Quote("' "') We'll use triple Single Quote( ) in our programs but for now let me make it normal
  17. Like this.... You can use either method as & when required I've told you when to use which method Back to the notes We learned about 'Strings' Now let's talk about 'Booleans' 'Booleans' means either 'True' or 'False' If I've made a talk, Either it is true or false nothing in between There's nothing like "Half wrong & half right" Either it is all true or it is all false So 'Boolean' is the same in Python Programming Language Either it is true or false 3 > 5 It is false It cannot be true Anything can either be true or false So if we ever want to deal in 2 values then we can use 'Boolean' Now let me show you a Boolean variable Let me create ( d ) And we can write like this And I've written " True " here so when I'll print ( d ) so look... It'll print "True" And if I change this to "False" So look "False" will be printed So look "False" is printed here And this is what "Boolean" variables are Now what is "None" ? If you ever want to display "Nothing" in Python Let's suppose if I want to choose "None" from "True" , "False" & "None" Which is neither True nor False which means it is unverified I'm giving a use case "None" can be use anywhere "None" is used to display... ..."Nothing" "Nothing" is being called "None" in Python If you ever want to display "Nothing" So it is "none" When the function returns "nothing" so it displays that as "None" So "None" has been made a literal which denotes "nothing" If you ever want to display "nothing" so you can denote it as "None" Let's move forward Python is a fantastic language that automatically identifies the type of data for us If you made " a = 71" then it'll automatically identifies that " A " is of class 'Int' If you've made " b = 88.44 " so it'll automatically identify its type and stamp it as Float It is a Floating Point Number and I have to store it as a Float Similarly when I'll write ( name = "harry" ) So it'll identifies it as a String type variable Let me tell you how you can check the type of a variable Let me first add a comment here "printing the variable" And... I've written "Printing the variables" and now I'll write... "Printing the type of variables" And "print-ing.... "printing" Now let me tell you about "type" function
  18. If you write something like this here " print(type(a)) " So "type" is a built-in function which will return the type of the given value ( a ) is an integer... Sorry ( a ) is a string So it'll return me as a class "str" And in Python everything is an object of classes Now you'll be confused "What is class " "What is object" For now I'll ask you to ignore the word "Class" We'll learn about this later Ignore it just for now So look class "str" means it is an object of 'String' type Now what does Object means? It is a variable of "str" type just understand this for now We'll deep dive into Classes & objects later Now if I run the same thing for ( b ) So it won't be "Str" but "Int" because ( b ) is an integer Let me run it Look it is displaying Class "Int" "Int" for Integer Then we also have a "float" class Look what's the value in ( c ) ? It's 45.32 And what is 45.32 ? It is a 'Float' by-default Now if I do the same with ( d ) And run this program So you'll see it's type is 'None' ( d ) is 'None' type So let me comment out the (d ) so (d ) will become "True" So it'll be a variable of type 'boolean' So look it is printing Class 'bool' now When it was of type 'None' so it was printing type 'None' So I can use 'type' function in Python I can just simply print the type of any variable So I hope this is crystal clear to you And you understood what I told As I told you Python automatically identifies the type of variable For eg. '71' is an 'Integer', 88.44 is a 'Floating Point Numbers' And "Harry" is a 'String' So it detects automatically
  19. Actually it doesn't identify but there are some rules, following which interpreter work behind the scenes You don't have to be tensed about that Just understand that if you write " a= 71 " in Python so there's no need for you to tell it is an 'Integer' It's the responsibility of Python to identify its type Now something very important Can you select any name for variable? For eg. I chose ( a ) here I wrote ( a = "harry" ) Can I write ( la ) ? I'll.... Look it turned red.... VScode told this before me Python extension has told first that "there's something wrong here... ...First fix it" Let's suppose I run this without fixing it So it is saying... "Invalid Syntax" What is it saying? "Invalid Syntax" It is saying "you've made a mistake" So you'll say you didn't make a mistake you just gave it a name But tell me something I wanna ask you all a question. Answer this question in comments Have you ever heard a name of human starting with number? Have you ever heard a name of human with "2788Ravi" "2722shankar" Have you heard of it? Or is there someone who's name is "2288" "2288 son, Come here have some lunch... " How will it sound? Quite weird It may not sound weird to someone but... But there's an in-general rule for naming humans in our society And there's this rule That no one's name will start with number Have you ever seen a man with name ( @ ) in it No one... So same like that there are some rules to name variables in Python Programming Language
  20. There are some rules for naming And let me tell you those rules I've written here the rules for naming A variable name can contain Alphabets, Digits & Underscores(_) OK it can contain Alphabets, Digits & Underscores(_) But a variable name can only starts with an Alphabet or an Underscore(_) Which means when you're starting a variable name So you can either start with an Alphabet or an Underscore(_) You cannot start it with a number or @ So you can name it (_a) and it'll work If I replace it (_) so it'll work So let me replace it (_) I've to do it here too Or else it'll show error So if I run this so my program is working. I'll remove this (_) else it'll create unexpected confusion But.... You understood the rules for making variables We only have looked at 2 rules till now let's move to the 3rd one A variable name can start with a digit Sorry "Cannot start with digit" I'm sorry I mentioned "can" But a variable name cannot start with a digit It cannot start with a digit we just tried that with ( la ) and it was throwing a syntax error No white space is allowed to use inside a variable name You cannot add a space in a variable name for eg. You can name it "a@122" Number can be in middle but not in starting So "a@122" is a valid variable name But you cannot add a space. It'll be wrong It is also marked as red and if I'll run it so look it'll throw Syntax error
  21. Look.... So these are rules to create variables in Python programming These rules are quite similar in other programming language for eg. if you use C Now I've marked something with Red "Also applies to other identifiers" What is identifier? Identifier is a name of class, function or variable..... I'll tell you later about Class & Function so leave this topic for later I just told you that Identifier is either a class, function or variable name We're only familiar with Variable name right now I don't want you to be confused by telling you more about Class & Function Now what we'll do is... We'll look for some examples with the name of Variables "harry" "one8" "seven seven" these all are valid variable names And I want to point out one more thing here Let's suppose..... Let me invoke the Python Interpreter quickly If I want to explain you something very quickly in this course so I'll just write "python" and I'll press the 'Enter' key And I'll explain you that here So if I write " a = 34 " And " A = 67 " And if I command it to print(a) So It'll return 34 And if I command it to print(A) so it'll return 67 What does it mean? It means the variable names are case sensitive Which means if you've made a variable with uppercase & second with the lowercase So they'll be considered as 2 different variables They won't be considered same variables Let me exit this because I just wanted to tell you this And I haven't added this in notes But I think I should have added so I'll add if I got time
  22. And I'll update the notes But I think that's fine, I told you this through note Now let's talk about 'Operators in Python' Give a look at examples and try those on your own It'll all be cleared to you to choose variable If I talk about operators so let's talk about some common operators in Python There are 4 types of common operators in Python Arithmetic operators... Assignment operators... ...Comparison operators & Logical Operators So I'll quickly create a file here because it's an important topic I'll create a file with name... ..."02_operators.py" • " a = 34 " & " b = 45 " And I'll write . Or let me make it simple let's change them to 3 & 4 I'll write this... If I write "The value of 3+4 is " And then if I write "3+4" like this... So if I write something like this.... So the value of "3+4" will be printed This whole text that I've selected is a string By the way I can print as many things as I want by adding comma(,) in print function So I've added a comma(,) here So the output will be "The value of 3+4 is 7" What's the reason behind this output? Reason is, because it was printed as it is... And this was first calculated & then printed As you all know that this "3+4" will printed after evaluation because it is not enclosed with double-quotes( So it is not a 'String' and it is an 'Expression' and 'Expression' gets evaluated And "3+4" will result in 7 "The value of 3+4 is 7" will be the output So this was the Arithmetic Operator
  23. Let me write here BTW I'll provide all the Programs, PDF, ZIP file & Practice Sets. You'll get them all Don't be tensed about it Be with me in this course & enjoy And you don't even need to write these notes these all are for you I'll provide you and your job is to print them Enjoy this course & I hope this course will become very enjoyable for you We were talking about the Arithmetic Operators and let me tell you about more Arithmetic Operators And if I print(3-4) so "-1 " should be printed And if I multiply a couple of numbers so I want it to print 12 And if I want to divide them.. And if I write (3/4) so the answer will be 0.75 So 0.75 will be printed So these were the Arithmetic Operators "3+4=7" "3-4=-1 " "3*4=12" & "3/4=0.75" You may have notices that I've used star(*) operator In most of the programming language like Python, star(*) is used for the multiplication Other programming language also follow the same rule In most of the programming languages But we're concerned for Python right now In Python star(*) means multiplication So there's nothing to be tensed about Whenever you see a star(*) it means the multiplication I hope you've understood "3*4" means 3 multiply by 4 We've done all the operations and we've printed the answers So now have a look at 'Assignment Operators' What are 'Assignment Operators' ? We already have used 'Assignment Operators' Operators..... We already have use 'Assignment Operators' They are like.... When I'll write " a = 34 " So ' a ' will contain " 34 "
  24. And now if I want to add 2 in ' a ' So I can use ( += ) operator and it'll change ' a ' to 36 This line of code will change ' a ' to 36 Now if I print(a) So look the output will be 36 Why 36? It is because I've added 2 in it Let me show you I've added 2 in ' a ' It was 34 earlier and I've added 2 in it so it has become 36 If I had added 12, it would have been 46. What does (+=) do? It change the number by adding the given value So it is the shortcut for addition If I write " a = 34 " and then I write ( -= ) So the output will be 22 because ( 34 - 12 = 22 ) So it's just the shortcut method and a gift from Python Programming In Python Programming you can use ( -= ) Similarly you can use ( *= ) it'll multiply the original number with 12 And you can also use ( /= ) It'll print whatever the result will be, after dividing original number with 12 Now if I print this so the value of ( a ) will be quite weird The value of ( a ) will be.... [34 - 12 (12)/12 ] = 22 And I got 22 Now why I got "22.0" ? Because when I divided it with 12 so I got the floating point value And in Python Programming whenever you divide 22 with 2 Or 44 divided by 2 So always got a Floating point Number Let me show you if I write "Python" and if I divide 33 with 3 Which is divisible so I'll get 11.0 which is a floating Point Number
  25. These are the things you've to note for Python If you use a different Programming language or you've plan to learn different language in future So these were the assignment operators Now what does Comparison Operators do? They compare the two entities and tell us if this is true or false For eg. If I write comparison operator here And if I write b = 4>7 And I'll also add brackets b = (4>7) If ( 4>7 ) is true so... ...I'll get "True" printed Or if it is false so I'll get "False" printed So look I got the "False" printed because it was false But if I change this to ( 14>7 ) So I'll got "True" because it is true Comparison Operators returns 'Boolean' And if I add ( >= ) so it means either ( > ) or ( So it also is 'True' ( 14 >= 7 ) will be true Because one out of 2 is 'True' which is (14 > 7) But if I change this to (
  26. And I use the same key to uncomment ( Ctrl + / ) I use these keys for commenting & uncommenting the lines I hope this was helpful ( 14 != 7 ) will print 'True' And I've told you about the mostly used Comparison Operators here Now what are Logical Operators? Logical Operators contains 'And' There are more but these are the most commonly use 'Or' & 'Not Now these Logical Operators operates on Booleans Let me tell you I'll write here... "Logical Operators" Let's suppose we've 2 Boolean variables I'll make a "booll" and I'll make it 'true' And I'll create a "b0012" and I'll make it 'False' If I print it... And if I write "The value of booll and b0012 is" , And if I add a bracket.... And in that bracket I'll write ( booll and b0012 ) So look 'False' is being printed Now how is it calculated? Similarly I can do this for 'Or' And I can do the same for not But 'Not' is used for a single variable So here you can use 'Not' And when you'll run "Not b0012" so its opposite will be printed Which 'True' will be printed So I'll write ( not booll ) here "The value of not b0012 is" And here I'll change it to 'or'
  27. Now how they works, let me tell you If you are not familiar with Boolean algebra So it's the topic of Boolean algebra But let me give you a small hint 'And' return 'True' only when both these 2 are true And it'll return false in all the other cases Here, one is true and another one is false so it is returning false And..... If either of two is true so it'll return 'True' You can add any value, If either of two is true so it'll return 'True' else it'll return 'False' What does 'Not' function do? It reverses the output If the output is true so it'll return 'False' And vice versa You may find this complex So you can skip it safely But you must be aware about the Logical Operators There's something named 'And' & 'Or' I'll suggest you to practice this & you can also rewind the note if you didn't understand quite well But for now you can skip it because I'll repeat this one more time when I'll explain (If/Else) function And you'll get to know it again 'And' is called 'Or' in Hindi And 'Or' is called 'Ya' in Hindi Either this or this If one of either 2 is true so it'll return 'True' 'And' means I'm referring that 'booll' & 'b0012' both must be true Or the output will be false in rest of the cases As you can see here the output is 'False' Here, one from these 2 was true so the output is 'True' 'b0012' was false so the output was reversed and it became 'True' So this is how this program is functioning I hope this thing is cleared to you I hope you understood Logical Operators
  28. Now we'll talk about Type Casting & Type Functioning "What is Type Casting & Type Functioning? we use it? ' And why So pay attention on my words I already have told you that the variables are like containers When we created our first file, we learned that if we are creating an Integer... So we write " a = 123 " or " b = 345 " and it automatically gets detected as an Integer But when I write " b = 345 " So I also want to make it as a 'Floating Point Number' Which means I want to store it as "345.0" and as a 'Float Number' So am I unable to do this? This is what we do with Type Casting And Type Casting was made to do this To explain you Type Casting I'll create a new program And I'll name it "03 _ typecasting.py" To explain you Type Casting I'll print... "a = 34343" If you think this is an 'Integer'. So you're wrong It is not an 'Integer' but a 'String' in Double-Quote( Yes, the number in this Double-Quote(" ") is a valid 'Integer' But isn't 'a' a 'String'? Yes it is It is not an 'Integer' you can print its type if you want So you can firstly print a's type And you'll get to know that it is a 'String' Class = 'Str' Hence confirmed Suppose you don't do this... And you mistakenly prints any number in ' a ' It can either be 45, 345 or 5 And you expect it to return the output 3539 because the sum of 3534 & 5 is 3539 It'll be your wrong perception if you expect this Because if you try to add an 'Int' in an 'Str'
  29. So it'll ask you why you're trying to add an 'Int' in an 'Str'. What's wrong with you? This is what your Python Interpreter is asking you So you'll say "what should I do, I want 3539" What should I do for that? So your Python interpreter will suggest you to do Type casting Which you should change change a's type from 'int' to 'str'