Thursday, 29 October 2020

Python Data Types - Numeric with Integers and Float.

Python Data Types

Hi and welcome at RajCoding specialize in computer programming, we publish Post weekly so you can master indispensable skills for free.

python data types



Alright In this post we understand the concept of numeric data types in Python or Integers and Floats. Let's get started when programming in Python if we say that a variable in python has a numeric type  value that numbers can be integers or floating points also called floats for instance integers are positive or negative whole numbers without a decimal point.

Now let's create x1 and bind it to the value of five, now x1 is an integer a specific function in Python can prove this is correct it is called type within the brackets we must put the name of the variable whose value type we want to verify.So in this case I will type x1 okay and then Shift + Enter and the result we get is int which indicates the value is an integer{int}.

python data types


The type of function can also be applied directly to a value instead of a variable for instance if I write type open parentheses minus six close parentheses Python will correctly point out that minus six is an integer good now let's assign the value of four point seven five to a new variable X two I would like to check its type hints.

I will use the type function again this is a float great floating points or as you'll more frequently hear floats are real numbers hints they have a decimal point four point seven five is such a number therefore Python reads it as a float let's look at two other built-in functions int transforms the variable into an integer that's why 4.75 turns into four float instead we'll add a decimal point to the integer value.

python data types

And we'll turn it into a float not all variables should be assumed as numeric value, basically all variables are not similar to float lets take an example of such type of values that is the boolean type in Python which means a true or false value corresponding to the machines logic of understanding ones and zeros on or off right or wrong true or false, which is either true or false.

Let's provide an example with a new variable X 3 which is equal to true right the output of the type function is bool which simply means X 3 is a boolean an important detail you should remember is you have to type true or false with capital letters otherwise Python won't recognize your variable as a boolean and will display an error message.

Wrapping in BooLean;

So to wrap it up the two boolean values a variable can have are true or false and they must be written with capital letters strings are text values composed of a sequence of characters let's see how we can create a string in practice if we ask the machine to display the name George this way we'll obtain an error message.

Why because Python assumes George is the name of a variable to which we have assigned no value Try a  magic trick that will correct the mistake or just type single quotation marks around the name George first and now let's type double quotation marks around it you see the output values of these two inputs are the same this is how Python displays text results if you don't use the Print command should you use print the output will be shown with no quotes.

You'll be able to see plain text if we assign this value to a new variable let's say x4 we can obtain its output as we did with the integers and floats
in addition you would like to ask the machine to print out a statement that says Y dollars where Y is a number the proper way to combine the value of y and the string dollars is to use a plus sign as shown here let's execute this cell to check if we are missing something we did not follow the rules of programming or coding in Python.

python data types
Data Types

We can convert Y into a string string STR is the built-in function we need analogically to integers and floats string will convert our number into text and that will unlock our result to summarize what we said so far Python can automatically guess the type of data you are entering it is within its capabilities to know for sure whether you have assigned an integer a float a boolean or a string you need not declare the types of variables explicitly as you must do in some other programming languages.

Python always knows the type of variable what will happen if you type something like I'm fine you'll need the apostrophe in the English syntax not for the Python ik 1 observe if you execute the command like this you will make a mistake to avoid that in such situations you can distinguish between the two symbols put the text within double quotes and leave the apostrophe which technically coincides with the single quote between I and M.

Now you are fine an alternative way to do that would be to leave the quotes on the sides and place a backslash before the apostrophe within the phrase and will still obtain the same correct result this backslash is called an escape character as it changes the interpretation of characters immediately after it and what if we wanted to State press Enter where we put enter within inverted commas same logic the outer symbols must differ from the inner ones put single quotes on the sides and you obtained the desired result finally let's go through a few ways of stating values say you wish to print red car on the same line.

If I write it like this two words next to each other separated by a blank space I'll see them attached one trick would be to put a blank space before the second ' of the first word let's see nice that looks like the desired result another technique would be to sort of add one of the strings to the other by typing in a plus sign between the two just as we did with the tin dollar example a minute ago.

Okay as your intuition probably tells you if you print this combination instead you'll obtain the same outcome but it won't have the quotes on the two sides and here's a new trick I'll type print read and then I'll put a comma which is called a trailing comma and Python will print the next word car on the same line separating the two words with a blank space Shift + Enter.


Python Data Types


Great let's print the number 3 next to the number 5 boom fantastic here it is what will happen if I don't use the print command and just list a few integers floats and strings separating them with commas
 Python will execute the command as expected but will place the values within parentheses strictly amazing thanks for Reading if you found this Post interesting and want to gain an edge in your career make sure to comment and subscribe and don't forget to check out some of our other Post for another quick win in the data science skills department or in any Programming Languages.

Thank you.
 

Thursday, 13 August 2020

Learn Python Episode #6: Choosing an IDE under Python;

Alright, Guys welcome to this Python series , today we talk about Choosing an IDE.So lets know how to be an efficient at programming with Python?The question can be posed for any programming language really, and so the answer is usually going to be same.



I mean feel free if you want to, to open up notepad on Windows or you know some basic text editor and write a script and go over to the terminal and command prompt and run it, however that's not efficient for a variety of reasons. So, what we're going to be using is an IDE, which stands for integrated development environment, and we're going to be using Jetbrains, PyCharm. Now, PyCharm is free for, I spelled that wrong just go to Google, search PyCharm, and click on the link there which is from jet brains.com, and you can download it.

Now when you get to the download screen you're going to get a professional or community version, choose the community version that is free, it's completely fully featured as far as i can tell, and that's the one that we're going to be using in this Post. Now alternatively I mean you can go have a look at other IDEs for Python, but I find that this one it just works really well,it's simple, and it does everything that we need it to do, and it also has some advanced features which we may look at some point in the future.

Download;
So, go ahead download the installer for your platform, it does require Java as well, so you can just open up Google and type download Java, and it's going to take a java.com/download if you click that link, just click download the appropriate version for your system, and once you have that installed then you can install PyCharm. So, this is going to be the first screen that you see every time you start up PyCharm. We're going to create a new project, it's going to be pure Python, now there's also other options here if you want to start a Django project, etc., but we're just going to start a Python project here and we're going to choose version 3.5.1 which is also going to tell the IDE here where to find the binary files to run Python.

Project Making;
Now, we're also going to name the project here, so first program, and this is going to be the name of our project. It's going to create a folder called first program and this is how we're going to identify it within here.So, along the left-hand side here this is the project view so let's go ahead and right click and create a new file.We're just going to choose a Python file and i'm going to name it main, which is going to name it main.py, and here we can start typing our script. So, again i'm just going to use the hello world example, and that's all it's going to be. I'm going to save it, keyboard shortcuts are going to take you a long way if you're going to become a programmer, so I expect you know some already, if you don't on Windows Linux control + S saves the file and on OS 10 its command + S so you don't have to always go through the menus and stuff, but let's have a look through the menus. If you want to create a new project, a new file, or directory you can open one etcetera.

you can actually access the settings by going to default settings for this project, and a bunch of different options down here that we don't really need. If you go to edit you're going to see you can undo and it's also going to show you the corresponding keyboard shortcuts for each one of these options, so this is command + Z and that's going to undo whatever action I previously did, this is also going to be useful if you're going to become a professional programmer. Same is true for copy, paste, find. We're going to be discussing find at some point, I mean it's a pretty powerful command you can find not only in the current file but your entire project if you want to look for instances of variable or string or something you can actually search through the entire root directory of this project if you want. If you go to view and go tool windows here is what we're looking at here project if we select that it's going to, it should hide that, yeah, so it hid the project sidebar, so we're going to leave that open.If you have version control setup this will not be disabled and you can use that to perform first control actions.Now open Python Console and here we run the actual Python Code.

If we wanted to say 5+5 you know and it's going to return that so this is the interpreter itself, however if we want to actually open terminal we can open a terminal here and here we can just type python3, main.py and it's going to run what we have up in this file right here. Now additionally we have a run right here. We can set up run, a run configuration here, to actually every time we hit the run it's going to automatically run our project so let's go ahead and hit the plus sign, choose python, and it's gonna be called a Python run,script is going to be python3 or the script is going to be the the actual python script that we want run so it's going to be main.py, script parameters this is if we're passing in any arguments or anything we're not going to it's already found the Python interpreter.

This is going to be interpreter options we're not going to be using any, and that's all that we need to do. So, let's go ahead and click apply and then run, and it's going to run the script, output that, and then it says it finished with exit code zero which is completely normal. So, every time you want to run if you have this little section opened here just hit that play button, the Run button there, it's going to run the code in real time. So, make changes, hit ctrl + S,and then run the code right there, this is the most efficient way to run a program in an IDE, you know, you don't have to switch back and forth between windows and stuff. So, this is the primary reason that we're going to be using this IDE for the sake of this course.

Again, feel free to have a look at some others but I recommend if you're a complete novice to any of this just follow along exactly with what I'm doing and you shouldn't have a problem. However, if you do there's a discussion section to the right of this Post, use it, let me know if you have any trouble,and I'll try to clear it up. So, with all that said we are finally ready to actually get in to the language itself.

watch my other post on Python, just go to rajcoding homepage and in courses section select label Python or if you just, want to Subscribe to my, newsletter so that you don't Miss my future tutorial Post just go down of this blog and subscribe with email to get all News and as always let, me know in comment below, when you thought of this Post i'm Ankit, from RajCoding, and i'll see you in the next Post?
Thank you and Take Care.

Wednesday, 12 August 2020

Learn Python Episode #5: Interpreted vs Compiled Programming Languages.

Interpreted Language and Compiled Programming Language:



So, the interpreter, and this is going to be a short Post. I think, but we're basically going to talk about the difference between an interpreted programming language and compiled programming language, and this might be a little adept for the novice programmer but just stick with us again if you have any questions or not sure if you completely understand it, there's a discussion section to the right of this Post, yes should be right to the right of this Post, so use that and I will try and clear up any confusion.
The First Question comes in mind that,what is this Interpreted or Compiled language?
Lets get started;
So, first, with a compiled programming language you write your code and you save it into this file,and you can't run that file yet.

Let's say you're writing C++ code, so you write a function, you write a script that will do something. If you try and open that file with the .cpp extension, which is for C++ files, it is just going to open that in a text editor or code editor because that's not an executable file. What you need to do with a compiled programming language is once you save your file you need to compile it into a language that the computer can read, so binary ones and zeros, and by compiling this file into an executable file, then you can double click it and it will run.

So, if you're on Windows building executable files for windows they will have a .exe extension. If you're on Linux I don't believe they have an extension. So, the difference here is with Python when you write a script you can instantaneously run that script without having to compile it into binary and because we can do that what's actually happening is when you run the Python command you're not running the file standalone. So, when you compile a programming file into a binary file you can just type the name of that file in the terminal or command prompt and hit enter and it will run that program as a standalone program because the computer already knows how to run it, but when you run Python scripts you're going to run it with the Python command and then the name of the file, and what basically happens is you're running the program Python which is interpreting your code and running that.

So, what happens is it does compile into binary but it does what's called just-in-time compilation, and what that does is every time you run its going to parse all the code and it's going to convert it into a temporary file and then run that temporary file. So, let me break out of this, there.

So, how you would run a script and we're going to talk about that later but basically how to enter the interpreter on its own you just type python3 to use the three version of Python you can see the version we are using Python 3.5.1. So, basically in the interpreter you can run real time code, so if I were to type "print helloworld" it's going to instantaneously run that line of code. If I run "4 + 6" it's going to return 10 because that's the sum of four and six, and so the interpreter is great to use if you want to test something really quick, if you want to debug a few lines of code, or if you just want to see if something would actually work.

So, we're going to be starting out using the interpreter but as things get a little more complex we're going to get into writing scripts and executing those scripts. So, now we need to learn how to run a Python script.

So, let's go ahead and create a Python script and learn how to run it. So, i'm going to be doing this in terminal completely we will discuss other options later, what I need to do first is change directory into "pycharm projects" and there's nothing really in here so i'm going to create a file using the nano text editor, you guys don't have to follow along, however if you want to that's great too.I'm just going to call it test.py. Now all Python scripts need to have the .py extension. So, what we're going to do is just a simple, simple script it's going to print "hello world" So, I'm going to control + O to save, and control + C to exit, control + X to exit. Alright, now if we just type "test.py" you'll see BASH doesn't know what to do with this command because test.py is not an installed program. So what we need to do is run "python3 test.py" and it will return the result of anything in that script. So, that's how to run python scripts, in the next Post what we're going to be doing is setting up an actual work environment using an IDE, and get you guys all ready to start with the basics.  

Learn Python Episode #2: MacOs,Linux and Windows 10 Installation

Installation in MacOS & Linux;



So, the first thing that we need to do to get into programming in Python is installing it. So, let's go ahead and discuss about the three different ways that you're going to be installing it. First, we're going to cover Mac because that's what i'm using and so it's easiest to show you how to do it. So, what you're going to do is open up terminal which I've moved into that folder and put right here.

Now, if you haven't installed Home brew, what you're going to do is runa Ruby command that's going to download and set it up. So, basically what Home brew is, is a package manager that you can use to install a lot of packages. So,if you're used to Linux basically on Linux if you want to install a package you don't need to go all around the internet and search for packages on websites and then download from shady sources and get viruses, that's just a bad construct of computer operating systems, but unfortunately that's how Windows works and so i'm going to show you guys the right way to install in Windows as well. Using Linux or OS 10 you're going to be installing through terminal. So, first setup Home brew, this is how you do it, come to brew.sh and it's going to give you this line of code here. You just paste this in terminal, run it, it's going to install brew.

Once you've got brew installed what you're going to do is run"brew install python" Now that's how easy it is. OS 10 does ship with a version of Python but the the version included in OS 10 is 2.7 series and I think it's actually an old really something that's like to 2.7.5 or something like that so it's pretty old. At least I think it was that.

We can actually run "--python version" here, so okay so the version that OS 10 El Capitán ships with is 2.7.10. When you run brew install Python it's going to install python 3, that's the command that we're going to have to be using because there's already a Python version installed, so we're going to be using Python 3 and you can check the version we've got 3.5.1 that's the version that home brew is going to install for you. Now similarly if you're on Linux what you would do there's a few different ways because there's a few different package managers. So if you're on Arch Linux I don't think you're gonna need help setting it up, and actually a lot of Linux distributions have Python/Python 3 pre-installed, so you can just run "python --version" and "python3 --version" and see what version you have installed,you might need to upgrade, it it might be fine. If you have 3.4 you can follow along with this course I don't think there's that many differences between the two versions and there's definitely not code-breaking differences, so that shouldn't be a problem. However, if you do notice that you're having a problem you could upgrade the version of Python either through the repository or otherwise.

If you're on Ubuntu you're gonna be using the apt-get command, so you'd run "sudo apt-get install python 3" That's going to install Python 3 for you. If you're on Fedora I believe it used to be yum, I think it's dnf now. Yeah, so let's just review exactly what commands you're going to be using, I think it's like dnf install. So, you can still use yum I guess, okay so you can use yum to install. So, what you're gonna do is we're gonna run "sudo yum install" and then I believe the package is just called python 3, Python 4 is going to be pretty amazing but right now we're using Python 3. So,there we go. Now if you're on Arch and I said I don't think you need any help getting it setup but just for you know if you are new to Arch you'd run"sudo pacman -S python 3" but again python 3 should be pre-installed, so you shouldn't even need to do any of this but if you do that's gonna do it.

Now on Windows you do need to go download a file from the internet and run it,the difference between what I said before what I'm saying now is this is not a shady location. So, what you're going to do is go to python.org, go to the download sections, and if you just hover over this it's actually going to show you a drop-down and you can choose what platform you're on. So you would choose windows and they actually have a 3.6 which we're not going to we're not going to be using because this is in alpha. So, click latest python 3 release python 3.5.1, it's going to take you to this page and basically give you a change log and what not. If you go down here make sure you get the version that's compatible with your system. If you have a computer that is not obsolete it should be running a 64-bit operating system which means it has a 64-bit processor. S,o you would download this one right here, Windows x86 64 executable and what that's going to download is an .exe file which you can use to install the program.

If you're running a 32-bit system you're going to download this one just the x86, and yeah just install it. Now, there is one note on the installation, when you run the installation there's going to be a certain step where you have some check boxes and one of them is going to say add python to the path variable, make sure that's checked because if it's not checked if you try to run Python in the command line you won't be able to because it won't know where to find this mysterious Python command. So, by checking that box basically it tells windows where the Python binary file is located, so you want to make sure Windows is aware of where that file is.

And that's all there is to installing it. To confirm that you've got it installed open up a command prompt to terminal and just type Python3 and it should drop you down into the interpreter, which we're going to be discussing in the next Post.

Installation in Window 10;



Alright guys, so, we've already learned about installing and using Python within Mac OS and Linux. Those two operating systems actually have a very similar process that's because they're both derived from the UNIX operating system, where Windows is not. So, Windows is a little bit different, so I'm going to walk you guys through this right now. You need to go to python.org, once you get to python.org you need to hover over downloads here, and then find Windows here. It should also be defaulted to Windows if you're on Windows. So, we're going to be choosing which version we're going to be using and we are always going to be using Python 3 not 2, so ignore Python 2. Click Python 3.6.1 and it's going to download the installer for you. Now, when this is done downloading we can install it. So just launch the program, and let me just uninstall this first so that I can reinstall it. While this is uninstalling we're going to be talking about the environment variables and why you need them, and when I installed Python on Windows a while back there was a problem with the path, or maybe not the path but specifically the Python installer package which we're going to be discussing. And if you guys do have the problem that I had it's going to be terrible, but there's an easy workaround for it. Alright, so, let's close that and then run the Python 3.6 installer. Now there's one very important thing that we need to do and that is you need to check add Python 3.6 to path, and then click install now. Now while that's doing that, I'm going to search for control panel here, and in the control panel let's go into system. If you don't see this view right-click up here and select small icons. This should work on Windows 7 8, or 10, and everybody should be on one of those operating systems anyway because, Vista might not be end of life yet. Vista it was either April or May that that was happening and it's April now. So, anyway, if you're on Windows 7, 8, or 10 go to system and on the left-hand side click advanced system settings. It's going to pop this up right here. Specifically, if you are not on the Advanced tab to begin with, if you're someone over here, go to the Advanced tab, and now here at the bottom you're going to see an environment variables button. Click that and it's going to bring up the environment variables configuration screen. Now the specific one that we're interested in is the path variable. These are system variables and these are user variables, I'm going to double click on this path variable and as you can see we've got python 3.6 3.2 added to the path which means every time I run a program that resides in one of these paths, Windows is going to know where to look for it because it's going to check all these paths first, and then all these paths in that one. And then if it doesn't find it then it's going to say, okay, well, I don't really know what you're looking for, and that's why we add paths to the path variable. So, that has been added, if I open up a command prompt here you will see that if I run Python it's going to successfully find it and run the program. Now that is because I have it installed to that path. Up here you can see users, my user, app data, local, etc., and as you can see right here that is the path that was added. So, every time I run Python this is one of the first paths it checks, and it goes well, do I have a Python.exe file, and it does. Now you can also run all of the programs from the scripts directory including pip, and so that's what we're going to talk about right now. Let me exit out of here. So, pip basically for example if you wanted to build a web scraper or a web crawler and if you just wanted to have a program that would download certain pages, what you would have to do is build scraper. And in PHP, for example, you have access to curl, it's shipped with curl. There is no default requests library for Python, so you'll have to install one. And usually you are going to be using some type of framework or library within Python just because it doesn't make sense to continue rewriting things that other people already have. So, you're going to be doing a lot of this, so I recommend getting used to it. We're going to go ahead and install a package that we're going to be using for web scraping and that is called requests. So what you need to do is type pip install, and then the name of the package you want to install. Now this is the problem I was getting before so I guess a re installation did not fix the problem, and I have no idea what the problem is I've been reading this stack overflow thread and so far I haven't discovered what the problem is, but there are a few workarounds. So number one probably the one we're going to go with is since you can run Python from the command line because that's been added to the path you can actually work around this by typing python -m pip install requests, and I've already got it installed so it's just going to say requirement already satisfied, but it should install for you guys. Anytime you see me in this course type pip install anything, all you Windows guys remember use python -m pip install and then whatever you're going to install. So that is how you install things with pip, and now once we've got this installed if I were to jump back into Python you can just import the library that you just created, and now you have access to that class. And that is how to get set up with this stuff on Windows. I hope you guys enjoy this course, I'm definitely going to. 

Tuesday, 11 August 2020

Introduction to Python.


source:python.org

Hello everyone and welcome to the Python course that we're going to be doing. Now, this course is going to be aimed at somebody who may not have basic knowledge about what a programming language is, but this would be your first programming language, and this is a great programming language to start with.

It does have some limitations and sometimes this is not the right tool for the job, but a lot of times this offers people who have no experience programming a really great way of understanding,what a programming language is and how to use one.

So, the main differences between Python and other languages like C++, or C, or Java, is that Python is built around two main focal points which I believe are code readability and simplicity. So, we're going to jump into the language here in a few Posts, but we need to do a few things first. First, we need to discuss what Python is,and then we need to get it installed, and then we can start discussing you know what's an interpreter, how do you run a Python script, and then get into the language itself. Now the language is different but it's easy, and once we get past an understanding of how the programming language works, and the syntax, and all the different stuff you can do with it, we're going to move on to actually programming real applications, and showing you guys different practical applications of the Python programming language.

So, for instance, we're going to be building a website, we're going to be building a web scraper, and a graphical utility...we're actually going to be building multiple graphical tools because there are a few different graphical, or GUI, GUI, whatever you want to call it, there's a few different frameworks for Python that we could use.So we're going to explore three of them. So, right off the bat here's a fun fact,if you didn't know Python is actually named after Monty Python, who's made some great films. So, if you haven't seen Search for the Holy Grail or The Life of Brian, go do it. They're great movies, which is completely beside the point.So, Python is actually a pretty old programming language. It was first introduced in 1991 which makes it 25 years old. There's two current versions.Now this may be confusing as well. So there's a Python 2 series, and there's a Python 3 series. Python 2 is currently at 2.7.11, and the 3 series is at 3.5.1.

Now we're going to be using Python 3 in this course, however Python 2 shouldn't be much different. If afterwards you want to explore using Python 2 that's completely acceptable. So, now as I said Python is based around simplicity and readability, and this means that when you look at Python code it's all indentation based. So if you looked at another code like Java, you'd see a lot of curly braces, and brackets, and a lot of things that are just there to confuse the novice programmer. Python is based on indentation, so you don't need to wrap blocks of code in curly braces, and you guys will see what I mean coming up in the in the next few Posts. So, that's all we're going to talk about today.

I hope you guys enjoy this course and find it useful. There's a comment section to the right for each posts if you guys ever  feel that you're not too sure on something that I explained, or maybe you had some input in addition to what I explained, feel free to use that. So, yeah,let's get started!

 Hello everybody and welcome to this online Python programming course. Now before we begin with the actual coding,let us talk about a few things, such as for who is this course, and what we will be doing in this course.

First of all, what we are going to learn in this course is Python 3. Now let's get that out of the way, right away. The reason why we are using Python 3 is because it is 2019 today, and basically next year Python 2 will be going out of date. Basically, it will not be in usage any more. Therefore, what we want to do is we want to learn Python 3 programming,which is similar to Python 2. If you had an experience before with Python 2,the syntax is rather similar. Except in some functions and some different things that we're going to cover of course, but most of the time it is rather similar. We are going to use Python 3, as I said, because that is something that is going to be used next year. Basically, every Python 2 platform will have to update itself to Python 3, and therefore we are going to download Python 3.

But, more about that in the next lecture. First of all, let us talk about for who is this course. Well, for example, if you are a student and you want to learn some Python programming, this will be a perfect course for you. Because we're going to cover everything from the very beginnings of Python programming, to some more advanced stuff later on. Now nothing really too advanced because this course is mostly aimed towards beginners. We are going to cover everything from the basics in great detail, so you can understand Python programming at a whole other level. Now of course even if you want to make this your career and become a Python developer, or basically a web developer with Python, you can take this course and you will learn a lot from it. Now we know that there are a lot of subjects covering Python, such as web developing,scripting, networking in Python, writing simple programs, writing something that will automate different tasks, and so on and so on. We will cover all of these things. But, first of all, we will be downloading Python 3 for our Windows 10 machine, and also for Ubuntu and Mac OS.

Now I will show you how to download for the Ubuntu and Mac OS, or I will show you the commands that you will use to download, but we will be mostly coding in the Windows 10 environment. As you can see, right here I have our virtual machine, Ubuntu virtual machine, which we are going to probably use later on for something. Such as, for example, networking where we are going to need two machines to communicate with one another. But, as I said before, we are mostly going to use the Windows 10 environment. Now in the process of installation of Python 3, I will show you on all three platforms how you can download Python, and how you can start it up. So that will be about it for this introductory video, nothing really more to say right here.

Let us get right into programming. And in the next lecture I will explain a little bit about Python,what that is, and we're going to also download Python 3 for our Windows 10 environment. Hope you enjoyed this first lecture, and I hope I see you in the next tutorial.

If you just, want to subscribe to my, newsletter so that you don't Miss my future tutorial Post just go down of this blog and subscribe with email to get all News and as always let, me know in comment below, when you thought of this Post i'm Ankit, from RajCoding, and i'll see you in the next Post? Bye! 

Thursday, 6 August 2020

Python Complete Tutorial #3 ,Start with Terminal

Hey Guys, welcome to the another post of Python Complete Tutorial, So lets get started.

Terminal

So on Mac and Linux, this will be called the terminal. On Windows this is called the CMD which means Command or Command line. See unit two, search for CMD. Once you install Python, what you can simply do is type Python on the command line and press enter. It opens the Python interpreter. I can write Python code right here and it will work. This is valid Python code. It comes with a help function. If I type help followed by braces, it will launch help for me. If I type in keywords, right, so there are certain things called keywords in programming. Let me just zoom into it, yeah. So I can exit from Python. Look at the definition. Let's get started. I will show to you this is how you can open the Python interpreter, you just need to go on the particular page and type Python and it will open it up. Let's come to Pycharm for a minute. In Pycharm, the way it works is that of course, I already have this, but in case you would not have this. So let's just remove it all together. What you need to do is you need to create a new project and then you need to give it ard thing. Even if I write code I can bet my life on it that three days later I will forgotten about 80% of it. name. The name could be test and you do a create. We do open it in the current window. Once it's in the current window, what I can do is that I can go to new and then I can select Python file. I can give it a name. Automatically creates a test as pv extension by itself and it stores it. Even if you go into a system and you'll see that it has been created and you can start writing your Python code over here. Now programming has something called comments. A lot of time what happens is that you will write a piece of code but you will forget what it does. It's not something that only you go through. It's a standard.

Source: Python



I would know what it does, but if it's more than 100 lines I would have to read through it. Now what developers do for this situation is that they add comments. Comments are nothing but simple English explanations for what you have done so that you don't need to remind yourself again and again of what this particular thing does. It just helps to keep at rack of, it's like notes. It's like small notes and the programming languages basically ignore them. Now there are two ways to write comments. This is a new Python file for the class. Now that's it. This is not valid Python code. This is not code, this is English. This is one way to write it. Other way to write it is using three single quotes and you write it like this. This is a new Python file for the class. These are the two ways you can do it. The purpose is basically to just remind yourselves or to other developers. So this is one thing that a lot of people when they're starting off, your code will be viewed by other developers at some point. You will start sharing your code, either within a company or otherwise. So when they look at your code they should be able to understand from your  comments what it does. Not just the whole file, not  like a description that this file says something to the database, but like what each and every step is along the way. So like, for every 10, 20 lines of code, probably one comment should be there. That's like a best practice. So next is indentation. You need to think about this in the way that Python follows indentation like comment system on social network websites.

So if you've ever seen Reddit, let me just open it up actually, okay. So if you look at Reddit, if you go to the comment section, you will see that there's a nesting. You can know that okay, A hah is being responded to by Retarded Clown Face or this guy's being replied to by this but this guy's being replied to by this. This guy's being replied to by this guy, so on and so forth. It's a nesting. You can see that there is a division. You can see that this comment is a reply to this comment. This is something that we see everywhere. We see this on Facebook, we see this on Instagram, everywhere. Now, this is how Python sort of declares blocks of code. So in case you're not familiar with what blocks or closures are, it's okay. You're going to come across it when we go further in Python but just remember that indentation is a very important concept in Python and this is how closures or blocks of code are defined. So how does Python code execution happen? You write code and it is saved with a .py extension, like I just showed it to you.

The code is converted into Byte code for machine to understand. That's done by the Python compiler or the interpreter. You don't need to worry about this step. It happens automatically as you run the file. It gets executed. Just need to care about step one, two and three are taken care of by automatically. It's not something that you have to do much about. Let's created a first "Hello World" program in Python. So how do you write hello world, how do we greet the world? Well, this is how we do it, as simple as this. Print, open braces, then a string. This is a string. You can't write this, this will not work, okay. If you see, this is already showing an error and of course this is where Python is smart. Python is smart. If you notice, it is underlined this file. It has underlined the folder containing it. This is telling you, before you even run it, that this is not going to work. So anytime you're printing string, a string being anything which is like a message, right, it needs be in strings. Use the print statement, use the brace opening and the brace closing like this. If you miss the brace it won't work, you have to include it. Then let's run it. So the way to run it is you right click and then you click on run hello, where is it referenced to the name of the file. This is where it will run.

This terminal is already present. Hello world is printed two times. odd happens. This gets printed on two different lines. Why is that? We just wrote a single line. So this is where this comes in, \n. This is what it's called is break line character. It will break the line. If you're typing in a Word doc and you press enter it goes to the next line. It's a new line character. If I type it two times, we should expect two spaces. If you notice it is gone two spaces deep. If you do it another time, let's suppose you do it four times and you save and we run. It goes even further. The reason why it is not dividing in the same end is because there's a space character here. If I do it like then, then it'll start on the same line. Now see, it adjusted. So this is how you do it. So it could be single code to double codes, doesn't matter, but I would suggest following one of them. This is the output you will get after running the file. Next is variables, variables are pretty much like mathematics variables over here. You take a particular name that you want to give it. So you want to set A as 10,you want to set B as codes.

This is an integer in Python. This is a string. Notice that now we're using single string as compared to double quote. You can do print AB, A,B and notice the comma. So ever here for example, I could have done this and this would have worked. So print can separate multiple strings or things that you want to print via comma. So you see both of them get printed. Now let's come here and let's print this. The 10 and codes both get printed. Of course they're coming with these braces. So in case you want to just print it, print them individually, that's a separate thing. I mean, you will have to separate it.

But in case you just want to see the values on your terminal this is the way to do it. Now, another example over here is this one. So what this will do is that it will move in order. It will assign X to 10,y to 20, and z to 30. Let's try it out. Okay, now of course this is very convenient way of doing it. Now the alternate way of doing it, of course you can always do it like this as well. That it increases the vertical length of your file. I don't find it to be neat and you will see expedience of level of doing this way. It's just more convenient. It just comes in a single line, that's it. It's just a matter of convenience. Otherwise, this is also correct and this is also correct. Correctness is there, it's just that line number nine is better than doing it in three lines. This is more concise.

Identification of words.

Now, a word about identifiers. This is a line identifiers. When you hear the word identifier, A and B are identifiers. They're identifying a particular variable name for you. Now there are certain rules around it. It is used to identify to variable function, class, or any other object right. It starts with a letter A to Z or A to Z capital or small or an underscore and followed by digits, zero to nine. So you can't start a variable with a digit like this. It shows an error. What you can do it you can do this. Or you can do this. This works, but doing this won't work. So this, this, _B, __b, and all of this, they are valid identifiers. But you can't start it with anything else apart from letter A to Z, capital or small, underscore. You can't start with the digits. Python doesn't allow special symbols, like add, dollar, percentage, star, braces, exclamation mark with an identifier. Now there are certain naming conventions in Python. There is something called class in Python, it's a concept. Maybe some of you are familiar from other program languages. It starts with an upper case letter and all other identifiers start with a lowercase. So only the class name starts with an uppercase. Now there are certain other rules as well. They are related to classes. I think it would be better if we covered them then. All of these things like to identify this as private, strongly private, two trailing underscores. Now all of these are some concepts that we'll learn later. Let's leave them for that. But for now you just need to know that okay, this is how you name a variable in Python or an identifier. Now how are variables stored? There are reserved memory locations. What happens is that in the computer's memory, which is the RAM right, it creates a space and stores that variable in the memory and it reserves some bytes for it, that's it. That's all that's happening. It's just remembering them, storing them. So it's not that while I am writing it is doing that, it is when I'm running the file. So it is not going to do that right now as soon as I create it. So don't think that if you create too many variables your typing speed will slow down or your laptop will start hanging up. No, I mean it might do that, but when you're running the file and it might be for different reasons that just you know, simply having too many variables. So but just notice that this is just an instruction. This is just nothing but instructions. When you run it that's when it really does something on the computer. Right now you're just typing it like a Notepad document and you're pressing control S. But when I run it and by run I mean I go ahead and do this, that's when it goes to memory and it does all of these things. Yeah, so we have already covered this right, where we run it and the values get printed. Now let's look at some standard datatypes available in Python. Even before that, let's try to understand what is meant by datatype. Now, a datatype is basically a way to say that something is an integer, something is a string, something like what kind of data it is, whether it is a numeral or it is a string or it is a Boolean or something else or something else.

Datatype: Mutable and Immutable.

So Python has two kinds of different datatypes, or any program language for that. One is immutable and the other one is mutable. So the word mutable and immutable comes from, you need to think of mutation. The one that you might have studied in biology. Mutation fundamentally means change. So mutable datatype would say that it can be changed, that the data can be changed.
Immutable is that it cannot be changed. So lists, dictionaries, or sets, these are something that you're going to study. They can be changed, but immutable datatypes, numbers, strings, or tuples, they cannot be changed. Now one source of confusion that you might have is you might be thinking so, if I do a=121 like this and then I do a = 121,or let's suppose right, I do this and then I do a = 3, then this should not happen. Because a is an integer and you're changing it. I'm first setting it to a random value 121, and then I'm setting it to three. But that is not what it means. What it means is that, see this is just an identifier. This is not the data. The data is on the right side of this.

So when it says that it is immutable, what it means to say is that whatever you do, you cannot turn 121 into three. Which if you think about it makes sense, right? So this is the level of depth by the way, that happened in programming. Something as obvious that one is not equal to two or 121 is not equal to three, cannot be three. It is just that. But this is a different thing in the world and this is a different thing in the world. There is no way that it can convert this into this. Like you cannot convert gold into silver. Gold is immutable. Gold is immutable, where you cannot turn it into silver. You cannot turn it into any other element. But then there are certain things in the world which are mutable, that you can take them and turn them from one thing to another thing. So for example, you can take a seed and turn it into a tree. That's mutation. But if you're trying to mutate gold into a tree or gold into silver, it will not happen. It will remain gold, even if you mix impurities in it.



It will be impure gold, but it will still be gold. So you need to think of it like that. It's a very basic concept but it's something which is there across programming, that the entity cannot change. Now let's talk about the immutable datatypes, numbers, string and tuples. No Python supports three different kinds of numeric values, integers, which are signs. So you can add a plus or a minus in front of that. There are floats, which are real numbers, decimals. Then there are complex numbers. When it comes to representing numbers, you can represent them in three different ways, binary, octal or hexadecimal. However, please note that you typically will not be using these representations. Typically, you will be using numbers like you use them normally. So to define an integer you set base of 10, to define a float base of10.65 and for complex numbers. In case you remember this or you're familiar with this, this is 10+6j. This is the imaginary value and will operate like this. Let's quickly have a look. We have the same file here, let's run it, and it outputs like 10+6j. If I do 10=5+4j and I print D-C, let's see what do I get.

So if you see, it does done the subtraction, 5-10 is minus five, 4-X is minus two and a get a result. Next is strings, a continuous set of characters represented within any quotation is called a string. So whether it's singular or double quotes. Now, Python does not support a character type. This is basically coming from other languages which have something called its char, as a character. Python doesn't have that. Python just has continuous strings. In case you're not familiar with character it is okay. But character datatype is no different to character in the generic way of alphabets. It is referring to it in the programming context, where there is something called a character, it's char, datatype, in Java, C++, so on and so forth. Python doesn't have it. Python just has strings. It cannot differentiate between single and double quotes or does not differentiate between single and double quotes. As you've already tried it, this works for us right. We have already done the print statements using strings. Next is tuple, so tuple is a fixed list. It comes within parentheses. For example, even this right now, the way it is printing, it's a tuple. If you look at this, this is a tuple. I can do this, now notice this. I can print this and this will run. Now I can also do the following with a tuple, I can print and individual element. I can print the zero index. These are zero index, meaning or let me change it, so let's suppose these are fours, right. Start off saying that this is the first and the second and the third. It works with a zero index. It says this is a zero, this is the first and this is the second. Now I can do this as well. So this is me reading an individual element of the tuple, four, five, six. However, notice if I try to do this. Python has already highlighted this. It has a problem with it. It you hover over it, it's just saying that tuples don't support item assignment, which is basically meaning that hey, you can't do this, you cannot change it. I cannot change this, let me run it. It was throwing an error. It's throwing an error tuple object does not support item assignment. So I'm trying to change this datatype. It's like I'm trying to change gold into silver and saying sorry, can't do that, that's not possible. You cannot modify this. Now let's look at the mutable datatypes. The first one is a list. So we just saw a tuple, it seemed like a list of items right but it was called a tuple.

But Python also has something called a list. Now, lists can contain various elements and number of elements if you want to create an empty list, this is how you create one. Square bracket, open and close, this is an empty list with zero things in it. This is a list with one, two, three, and four things in it. Now if you notice, all of these are different types of data. This is a decimal, this is an integer and this is a string. You can print the list and pretty much make a tuple you can assess any element within it. Let's run this. What you can also do is that you can update it. So we can say A is equal to changed first, second element. So because this is, again, this is zero indexed again, by the way. Like tuple was zero indexed, this is also zero indexed. Zero index being that this is referred to as a zero. It doesn't count it as one. So that is generally how things work in programming. Almost all programming languages have it this way. So if you see, I change this second element. So the same thing was throwing an error in the tuple, but in a list it is doing in this certain way. It is allowing me to modify it. Now a list can contain other lists as well. So you know, you can also do this. And you can also do, you know, four and then third element and it can also contain tuples. It can also contain a tuple inside it. This is a particularly complicated example of, not complicated, but something that you would normally encounter, but I'm just trying to showcase it to make a point. That a list can be of anything. So think about the English wordlist, it can be of anything. What I've done here is that I've said that zero element, which is this, this is a list, give me the second one. So it gives me four. If I say one and then Irun it, it'll give me two. I can run it on the first one as well. Yeah, it will give me four. If I need to access the tuple, think about which element it is, zero, one, two, three, right. I want to print five, then I'll do this. B3 to, I'm just counting. I'm counting zero, one, two, three. Okay, I got the tuple till this point. After that, I want to access five. It is zero, one, two, I go to two. Now slight differences, lists are putting square brackets, tuples are within parentheses. Lists are mutable, tuples are immutable. Tuples are faster than lists, letting that owing to the immutable nature of it, but that's not the real reason why you will use a tuple. You will use a tuple if you want to have a fixed value. So if let's suppose, you are making a simple calculator, you know which can do scientific calculations. Let's suppose by using the value of pi and scientific constants that can calculate the area of a circle or a sphere or a cone or whatever. It needs to use 3.14, the value of pi, and other constants and you need to maintain that and need to ensure that it is not modified accidentally by you or your programming. That is when you will use a tuple. Or you would use a tuple if you had to maintain a list of countries because you don't want the list of countries to get changed. You don't want, accidentally, when you're coding, you end up changing an element within that list because you know, it will cause a lot of problems. So basically, to understand why you need to also think about and understand why immutable datatypes are needed because if you look at lists and tuples, the only difference really here is-- So by the way, I can do this with a tuple as well. I can do the very same thing. I can simply do this, see, and I can run it. It will work as it is. It just did, I just printed the element, right? Now, the only difference is that lists are slower, but more importantly, lists are mutable. So mostly you will find yourself believing that (speech unclear) dealing with lists rather than tuples. Tuples are needed for very specific scenarios. So don't get confused by why do I have two, can I use either one of them. Focus on lists for now. Tuples will naturally come to you when you are presented with a scenario. The tuples are more in the niche, where they are part of a particular case. Next are dictionaries. So dictionaries, as the name suggests, it is like you would go through a dictionary right. What is the meaning of the word naive, what is the meaning of the word precarious, what is the meaning of the word apple, so on and so forth. Against every word you will have a meaning. So the word is like a key and the explanation is like a value. This is a key, age is a key, this is the value. This is the key, this is a value. If you look at is, this is very readable. They're separated by colons, okay, and the need to use this is that it makes your data very readable. Key value pairs is something that comes naturally. So if you look at a fill form, any sign up form that you have every filled, it asks for an email and a password. Imagine that being stored here. So in the sense, let's open this up, so this is being handled like this. Now, suppose you can also argue that hey, you know I can also store it like this, why shouldn't I store it like this? I'm gonna store it like this and instead of, you know, doing, oh by the way, so what you would have done over here is you would have used square brackets and then you would have typed the key. Let's run this once. Right, same output. So you can argue, hey, why wouldn't I use a list or a tuple, why would I use this? So one primary reason why you would not do this is because this is way more readable. Imagine how other lines of code, imagine this was declared on line one and you're using this on line 100, you don't know what is zero. You have to constantly refer to what is being stored at zero.

If you just, want to subscribe to my, newsletter so that you don't Miss my future tutorial Post just go down of this blog and subscribe with email to get all News and as always let, me know in comment below, when you thought of this Post I'm Ankit, from RajCoding, and i'll see you in the next Post? Bye! 


Python Complete Tutorial #1 [installation].


Installation of Python.

Welcome, everyone to this course in Python programming. My name is Ankit and in this tutorial we are going to focus on each and every important concept of Python. So without wasting any time, let us move forward and have a look at the agenda for today. So this is what we'll be discussing.

Today, we'll begin by understand what is Python, how it works, how we can install Python. Then we'll understand what are the sequences and file operations in Python. Next up, we are going to focus on functions and Oops concepts. After that, we'll be working with modules and how we can handle exceptions in Python. Then you will be introduced to a couple of very important libraries called NumPhy and Pandas. After that, you'll understand how you can perform data visualization using Mat-lab. Then you will understand how you can perform data manipulation using all the three libraries that I've just mentioned. After that, you are going to develop really cool applications, one is Web Map using  Folium, another is motion detector using Open CV. I hope you guys found the agenda very interesting.

Python Installation
Source: Python.org

And I  will be the instructor for this particular session Introduction to Python. So the question is which programming language should you start with? I mean, of course, you have already started with one as part of this course, but in my opinion, it has to be Python. Simply because it is very, very simple and easy to learn. In a few moments when we start looking at Python code, you will notice how it looks like English. It doesn't even look like code. Many people hear the word code, they start thinking of ones and zeros or they start thinking about oh it's going to be like a puzzle that you have to solve.

Nothing of that sort, really. It's just a set of detailed instructions. Like if you can write instructions about how to send a email also about how to send a post mail, if you can write very, very detailed instructions about how to send a post mail, you can probably code. It's like that. Next is that it is free and open source. So in the sense that you don't have to pay anybody money for using Python. Now, one question might be that, hey, what's new about that? I don't need to pay anybody to speak English, and English is a language. But the thing is that English, Spanish, French, these languages, there is no creator of these languages. They're commonly developed.
 
So nobody really owns English as a language. Nobody has the right to English. Whereas, if you look at programming languages, they're created by a small set of people. 10, 15, 50, 100 people. 100 people is not a big group of people, it's relatively small as compared to people who developed English. People who developed English words will be the authors, the writers, and the regular folks as well. So that number would be millions of people who developed the language. So open source is a concept in software programming. I strongly suggest that you go on YouTube and search for open source. We'll come across some very neat documentaries, I suggest you have a look at them. But comparing this with sort of what is paid for, Mat-lab has a version which is paid for, which has some extra functionality which you need to pay for. But Python is free, completely. A lot of Python libraries are available for free. There is a language called Wolfram, W-O-L-F, like a wolf, R-A-M, which is very expensive. You need to buy a license, you can't just use it, it's not allowed. It's like Windows, you need to pay a license fee to use it.

Now it's a high-level language, so believe it or not, but the first three lines over here are actually valid Python code. Forget the fourth one. Some of you might be able to understand that, but the first three lines are valid, valid Python code. That's why Python. You don't have to deal with the right side. Don't think about this, this is you'll never, almost never going to look at this and be supposed to figure out, oh what does this mean. You're only supposed to look at stuff like this and say okay, what does this mean. Then it's Portable, portable being that you can use it on multiple devices whether that's a Window's device, or a Linux device. Python is very compatible that way. It will learn different devices. It's supports different programming paradigms. So paradigm is just a fancy word for styles. If you are a beginning with programming, don't bother with it unless and until you have, you know 600 to 1,000 hours of programming under you. Don't bother with it at all. This is not relevant for you. However, if you have some experience with programming and you know what a programming paradigm is, just know that Python supports multiple and for those of you don't know about it, don't worry about it. You will get there eventually.

I'm not saying it's not important, it is important, it's just that right now it's like running. Like right now, if writing a line of code is the starting point, it's like stumbling or crawling, thinking about paradigms and styles of programming is kind of like running. So I would not recommend thinking about it too much. Next is Python is extensible in the sense that you can invoke C and C++ libraries from Python. So you can sort of call code of other languages using Python. That way it is very extensible, increases the usability of it. Makes it work with other systems. So Python's also used widely by a lot of companies.

Giants.

Let us look at a few of the giants. So this would include YouTube, Google, Dropbox, Raspberry Pi, Bit Torrent, NASA, Netflix, NSA, and I mean, it's like amazing, right. I mean, you look at how varied and wide different these companies are. They are internet companies to you know, national space agencies, to national security agencies. Really though breadth and the depth of it. It's being used by all of them in some way or the other.

So it's not that you shouldn't say that hey Google is built on Python. No, Google uses 10 languages. It's a huge company, right. Same for Dropbox. Oh by the way, the creator of Python works for Dropbox. He actually does work for Dropbox and he has it in his contract that he will devote a certain percentage of his time, like it's about 30 or 40% of his time, for developing Python. So that is something that he got as a part of his job contract. Of course he's a very celebrated person that way. Not regular people or I guess you as well, can really negotiate something like that. But yeah, he did because he's the creator of Python. But yeah, the point is that best of the places in Silicon Valley and government agencies, they are using Python. Now the best part, yes, this is my favorite part, because Python really works for most of the thing out there like you want to develop a website, you can use Python. You want to do data analysis, you want to do data science, you can use Python. You want to do automation testing, you can use Python. You want to do collect data from the internet, which is web scraping, that is extract data from the websites, you can use Python. Now one cautious thing, you don't need to do all of the things to say that you are a Python, a starter Python developer. Like for example, I've never done this one, testing. I've not never really done scraping. I know how it is done, but the point to note is that there are very slight differences between these. It is then that you have to learn an entirely new thing then you are doing this versus this. You have to learn the concepts related to it, but that's more like business logic rather than programming logic is completely changed.

Alright, the golden question on a lot of people's mind, are there Python jobs in the industry?

So this is a job trend from Indeed.com. Don't focus on the small percentages, I know they're small, but they are of the total number of jobs, okay. They're not just, it says.85%, but it's of probably 10 million or 15 million job postings. So you can notice how the trend is good for Python. It's going a little sideways, but then it keeps doing that, but if you compare it to PHP or C++, definitely a huge difference. Then of course, the popularity. This is even more relevant, how much is the community developing? This indicates Google Trends would indicate both searches using the word Python either by experience or by new people, all by industry.

So even if I have to hire Python developers I might go to Google and say hire Python developers and then it will show up here. So this is an overall accumulation. This is a summation of how popular Python is compared to other languages. Like these indexes, 99,66, so on and so forth, these are indicative about that. So let's look at how to install Python. We have sort of understood till this point what is Python, why it is used, what is programming, why it is used. Let's look at how to get started. Now, get started, the first thing is to of course, buy the card, or get the Python. You go to Python.org, you go to the downloads tab and you download the latest version of Python. 3.6, 3.x is the latest version. 2.X is also out there. It's being used by a lot of projects, even my projects these days use 2.X,because they have like one, 12 to 15 months old now, the kind of projects that I'm working on, so I mean, it isn't that you do 2.X. It isn't that for a big(speech unclear) in Python specifically, you would find a massive amount of difference between a 2.X and 3.X. I mean, it's like you know, having a car and then it's sports version of that car or the plus version or the luxury version of a car.

The differences are minor for the regular user, but if you are a Python user, then of course you might find significant differences. But don't be confused by it. It's not that companies tell developers who you know, know Python 2.7 and don't know the latest version. The job market doesn't work like that. They will go for Python. They will ask you if you know Python and then the version difference doesn't really make too much of a difference. You open the link and click on run. Click on install now. This is very important. In case you have already installed Python and you forgot or you unchecked the checkbox for some reason, please go back, uninstall Python, and reinstall it, and make sure that you selected the checkbox. Nothing will work if you don't do this. So please, follow the steps. And that's it, you're done. As easy as that you have Python on your system now. There's a Python GUI developer for you. Now next is Python IDE. The one question is what is an IDE?

what is IDE ,Python Installation

What does IDE mean? and Why do we use IDE?

So here we go, IDE is an integrated development environment. It is used as a code editor, including a series of parallel components in it and attachments. So fancy words aside, if you can ask me, hey, can I write code or can I write Python in a notepad or a Word doc? My answer to that question would be yes you can. Now if you ask me should I write code in Notepad? My answer to that would be no, please don't, never. So you get the difference, you can do it but you should definitely not do it. So it's not that your code wouldn't run or something of that sort, it's just that IDE are tools which are meant for doing this. They are specialized development environments for you to code in.
IDE, Python Installation
IDE

It helps you in certain ways. That makes sense, right, because programming can be very difficult without them. So definitely please choose an IDE and stick to it. One thing that you noticed, there are line numbers. These are very, very useful by the way. As you will experience, if you're talking to another developer, the best way to talk to them is line number three then edit on this particular line. Can you start reading from this line to this line, that's how I deal with a number of situations. I will talk about a certain line number.

Now a Golden question comes in mind that
Is Python easy to learn?

Answer is yes, It is easy to Learn. The syntax of python is very easy compared from other language and codes of python is easily readable. It has several kinds Infact lots of applications. This is used for  building rapid application development, data science, developing web applications and many more.

So I hope you guys enjoyed this post, read next tutorial post.
I am damn sure from now you can easily do a coding and create your own software. Bye!




Python Complete Tutorial #4;What is VARIABLES and how it Works.

 Hey everyone, my name is Ankit. And i'm the founder of this Blog RajCoding, and this is the new series of python Tutorial for absolute beginners.

Source:python.org

 What are variables?

So this series is gonna be good for complete beginners, who have never done any programming before as Well as someone who's done some programming before whether it's python or any other language but Wants to learn more about python. So in this Post i'm going to go through a number of different things First of all what is python and what can you, do with it and then i'm gonna explain how To install python on your computer and then set up a development environment. We're gonna use something called jupyter notebook throughout, this series and then i'm gonna explain how but You can use any text editor like VS Code, Notepad  etc because they are available at public licence.

Print

Okay lets get start with Print function, To use the print function And what are variables and how to use them and by the end of this Blog if you have two variables Storing different things, you'll be able to swap the content within those two variables with Each other, and i'm gonna put on an outline of this Post in the comment section below So you, don't have to watch the whole thing if you, don't want to. Oh and before we get started if you? Want to make sure that you don't, miss my future tutorial Post sign up to my, newsletter which is available in the description? Below so just quickly, what is python and what can? You, do with it it's one of the most popular programming languages out there and it's used at smaller companies as well as larger companies including google and many Universities use python as the introductory programming language in their computer science courses and one advantage of python Is that it's fairly easy to learn because it has fairly simple syntax It's used for many different applications Including websites back-end code which is the code that runs on your server as Opposed to the code that runs on your device whether it's a phone or a Laptop and it's also popular for their analysis and scientific research purposes, okay?

So let's now go ahead and install python on your computer usually When people develop a program using python or any other language for that matter they usually Use something called ide which stands for integrated development environment. It's an environment that includes Everything you need pretty much to develop a program. It has a nice text editor in which you can Write your code and then the ability to run your program as, well as something called a debugger Which allows you to quickly get rid of all the bugs in your program and if you, want to use an IDE to follow My series i personally recommend park charms community edition so in this series instead of using a traditional IDE i decided to use something called jupyter notebook So jupyter notebook is an environment for writing and testing your program quickly and It's actually, popular with the scientific community and for data analysis purposes but I've decided to use jupiter notebook throughout This series because it's very simple and easy to install Jupyter notebook through something called anaconda and it's fairly easy to use as Well.

How do i define a variable? And what is variable python example?
So here's the way, jupyter notebook, works there are two components to jupyter notebook First of all when you launch jupyter notebook on your computer you might see a command line interface like this This, represents the jupyter notebook server You can, think of it sort of like the core of jupyter notebook and you don't have to worry that much about how it works exactly But just remember that if you close this window. Maybe accidentally jupyter notebook might stop working so just be careful about that Now, when you launch jupyter on your computer you might? also See a browser window or tab showing up whether it's Chrome, Firefox, Safari, or anything else and It'll probably be at the url Localhost call eight eight eight eight or something like that and it'll be connected to the jupyter notebook server this Browser window or tab is basically the user interface for jupyter notebook and you can write and execute your code Here but it's actually executed on the jupyter notebook server, again. You don't have to worry that much about, how It works exactly but this is just an overview Now to install python and jupyter notebook we're, going to use something called anaconda Anaconda is something called a package manager which allows you to install many programs at once This, particular package manager' anaconda is actually used for installing math and science libraries but You, don't have to worry, about that the only thing you need to know Is that when you install anaconda it comes with python and jupyter notebook so you Don't have to install python or jupyter notebook separately on your computer.

Installation through Anaconda.org

Let's now install python and jupyter through anaconda go to anaconda org, and then click download anaconda and Select whatever platform you're using whether it's windows mac or linux I'm using mac here so i'm gonna click Mac OS here and there are two options here Python, three-point-something or python 2 point something, make sure to use python 3 point something because we're going to use python 3 instead of python 2 throughout This, course so click download and then save this file wherever You, want to save it and once this file is downloaded just open it and then click continue continue continue Agree with everything and then select Install for me only or install on a specific disk it doesn't matter which one you choose and then click install and This, process will probably take a, while for you Once this process is done you should see something like the installation, was completed successfully Once you see that just click close and you're all set to launch jupyter you need to launch an application called Anaconda navigator Just launch that in the usual way you launch any other application, and then find jupyter notebook and click launch Like i said before you see a browser tab or window. Opening up and it should be at the url Localhost colon 8080 8th 8th or something like that Ok, let's now. Create our first program First go to whatever the folder you, want to create.

Create NEW Folder

Your first program here i personally recommend that you create a New folder so i just went to my desktop i clicked right click and then, new Folder i'm gonna call this folder python, tutorial 1 and once you create that folder you should see in the jupyter notebook interface to click that and you see that the current location is Python, tutorial one within desktop right here at the top to create a, new, file or a, new? notebook, file as i say just click new at the top right hand corner and then click python 3 So a new notebook has been created, here change the name of this notebook from untitled to Let's say, what are our? variables click rename and Once you, do that if you go back to desktop and the folder that we just created python tutorial 1 you'll see a, new File what our variables dot i pi and b and that i pi and b is just an extension for algebra notebook? Now in jupyter notebook there's something called a Cell each cell represents a set of code and the box you're looking at right now is one cell So you can, type in any python code here for example print Parentheses double quotes hello world and when you run, this? Cell Using this button at the top it executes all the code within the. Cell, so let's run, this. Cell and You, see that the string hello, world, is printed so this text hello?


World is something called a string it's usually enclosed by either double quotes or single Quotes and it's basically just a set of characters so Assuming that this is your first time coding in your life i'm going to explain this, line a little bit more carefully so this says print whatever is in the parentheses these two parentheses and that happens to be Hello, world a string and when you run it again it's printed right below. This Cell how the world and the important thing to note here Is that if you Don't type in the exact set of characters that you see on the screen it might Not go right so for example if you forget to close the parentheses and run the Cell you'll get an error and if you use for example Curly, brackets instead of regular Parentheses you, also get an error and if you forget to close the Quotation, marks it's the same thing so Let's try, using this print function. A little bit more in This, cell that you see right here in the green, box you can, type in print double quotes more string and Actually instead of using double quotes you can, also use single quotes in python and then you can run this.

What are the 3 types of Variables?

The three kinds of variable are Dependent,Independent and Controlled.

Cell and The string more string is printed So you can, use single quotes and double quotes pretty much interchangeably in python and then you can Also, print not just a string but, also a number so you can, say print parenthesis 3 and then when you run The, cell the number 3 is printed and you could, also have multiple lines within the same cell as, well So in this. Cell you can, write print let's use double quotes here more string and then print 3 So when you run, this. Cell these two lines are executed one by, one so you see more string and Three print it just one after another So let's now dive into our main topic here namely, what are variables Before i explain, what our variables exactly in python i'm going to show. You some sample code you can write a Equals 1. And what this means? Is that assign this value 1 this number to the variable named a You can, think of it it sort of like the variable a Containing the value 1 that's not 100% Technically accurate, as i'll explain later but that's one way to think, about it so when you run this Cell you, won't see anything printed this time but the variable a now Contains the value 1 or a more technically accurate, way of thinking about it is that the bar a Refers to the value one and you can. Check,

what's inside the variable a by Printing the variable with print parentheses a and note here that there are no double quotes or single quotes around This character. A, and that's because a is not a string it's a variable and when you run, the? Cell you see the value a is referring to which is one and you can Do the same thing with different variables so you Can write b equals two so the convention here is you write b space and then Equal space and to This, line says, assign the value 2 to the variable b and when you run, the cell again the variable b refers to the value 2 now so if you haven't for example c in this code and If you, want to know, what's inside the variable or what the variable refers to you, can, write just like before print Parentheses be no single quotes or double quotes Run this. Cell with this button right here and then you'll see the value b is referring to Just like before, we can, write multiple lines within a single cell right here By, writing print parentheses a print Parentheses b and when you run, this, cell You'll see one and two so one is what a is referring to and two is what b is referring to? So a variable doesn't necessarily refer to a, number it could refer to a String so if you write for example c equals either double quotes or single quotes hello there And when you run the, cell?

 C now, we first see the value or the string hello there and when you print c? You should see how low. They're printed So i just ran this. Cell and the string hello, there has been printed, so let's now Quickly, talk about What variables are in python when you write a equals one in a different language for example c or c++ The correct, way to think, about it might be as a, box so you have a, box a Containing the value one but in python this is not the accurate, way to think about it the more accurate way to think About it is that a is more like a name tag and this can refer to any value you Want and when you say a equals one you're saying a refers to the value one now. These two Ways of thinking, about it they might not seem that different right now but it's Going, to be more important later and in python you can create a, new variable, by writing as We saw b equals 2 and this says the name b or the variable b now We first see the value 2 and just like you saw A variable can refer to a string as, well so if you write c Equals hello, there you're, saying the variable c refers to the string.

Hello There once you master that basic concept you'll be able to move on to a slightly more advanced topic Let's say you run, these lines of code and then you, want to run more code for example d equals 2 Then what happens is the variable d of course refers to the value to Which the variable b also refers to so it's totally possible for two or more variables in Python to point to the same value in this case 2 and then it's Also possible for you to reassign an existing variable to another value so if you write b equals 1 after executing this line of code b equals 2 after this line b refers to two of course but, after writing b equals 1 B refers to 1, which a, also refers to and you can Even reassign an existing variable for example b which once referred to a number One right here to something else for example a string so if you, write for example b equals double quotes ah The string the variable b now refers to The string ah So let's see how, this actually works out in code Okay, we're gonna continue on the code, we had earlier earlier, we had b equals so if you print be the variable We get the value to and you can reassign This variable to another value for example 1.

By writing b equals 1 and then when you run the. Cell, and print b again you get One printed the new value and what happens if we try to print a variable that doesn't exist yet So if you try to print print Parenthesis, a what happens let's run, this Cell and see what happens it'll actually give you an error because he doesn't exist yet and the error says Name error name e is not defined yet so that makes sense let's fix that. By writing e equals this is a string and This, way the value this is a string is assigned to the variable e and the variable e exists in the system So if you print e with print parenthesis e and when you run this Cell you, don't get the error anymore and let's address another question You might have here is it possible for us to assign a variable to Another one the answer is yes so here if you write Equals 1 a of course refers to 1. And then c equals hello, world c refers to hello world What happens if you write f equals a? What happens then is this, means the variable f the name f refers to? The value a is referring to so f refers to one now and so f? doesn't refer to the variable a Instead it refers to the value a is referring to and this is important for example when you do a Equals two if you write that a now refers to the value 2 instead of 1 but f Stays at the value 1 and this might not be the case if f was referring to the variable a Let's take a look at another example here if you write g iko see the variable g will refer to Whatever the value c refers to which is how it world and then once you write C equals, hello c will refer to the new value Hello, right here But the variable g will, stay at the value hello world Okay, let's go back into the demo earlier in the demo, we had a equals one and Then c equals hello there So once we print a and c. With print parenthesis a, and print parenthesis c We should see one for a and hello there for see what happens if we write f? equals a F should now refer to whatever a refers to So if we print f?

We should see the number one printed and? What happens if we assign a to two? then The value of a should, now be two and then the value of f should, stay as i said earlier at one Okay, now i'm gonna give you a quick practice problem to work on in order to solidify your understanding of variables and to do that Go, back to the previous tab of jupyter notebook the navigation Menu and if you already, close the tab Just open localhost colon 8080 eight eight or just relaunched jupyter notebook And then go back to the same folder as before we had python tutorial one click new in the top right corner click python 3, again and Let's rename this notebook. By clicking untitled and by changing it to swapping two variables and Here's the problem you're given two variables let's say V1 equals first string in double quotes and v2 Equals second string, again in double quotes how Can you, swap the values within, these two variables with Each other the easiest way to solve this problem is just to write v1 equals second string and Then b2 equals First string, but this might not be the best solution Because if you had a much longer string it would be kind of cumbersome to repeat these strings and Then if one of the strings changes so if first string becomes first two strings That you need to rewrite your code right here to Match that to write first two strings again So ideally you, want to be able to solve this problem without repeating the strings think About it for a second and then i'm gonna show You, what a good solution might look, like, when you see this problem you might say, well it's actually pretty simple Once we have b1 equal to first string and v2 equal to Second string, so that's v1 referring to this string and v2 referring to this string, we can just write V1 equals v2 and then v2 equals v1 and we're done but actually this solution is wrong Because when we execute this line v1 equals v2 V1 now refers to whatever v2 refers to of course, which is second string and then when? We write v2 equals v1? V2 will now refer to what v1 refers to now Which is second string so at the end of these lines of code? Will have v1 and v2 both refer to the second string which is not what, we want? Let's now see what a? Good solution might look, like I'm going to give you a few different options here the first option is to use two temporary variables we're Gonna call them temp 1 and temp 2 temp 1 will be equal to What v1 refers to so that's first string and then temp, 2 will be equal to what v2 refers to Which is of course second string and then we'll just need to swap them together.

So v1 will be equal to temp 2, which refers to second string so v1 will now refer to Second string After this line right here and then v2 will be equal to temp 1 which of course first string So v2 will refer to First string, after these lines so this is one potential solution but actually We don't have to use two temporary variables Okay, here's a solution that only uses one temporary variable instead of two the first thing we're gonna do is we're gonna set a New, temporary variable called temp - what v1 refers to so temp will be this string right here and After that we'll set v1 to v2 So v1 will no longer refer to first string. And then it will refer to second string instead and at This point note that the first string this string is not lost yet because We have a variable pointing to that value so after that all you need to do is Refer v2 back to whatever temp refers to which, is first string so v2 Will refer to first string, after these lines of code and the v1 will refer to second string and this, little pattern of using a single variable to switch the values of two variables is Actually really important to know because it's a very common pattern to use for any programmer.

Okay, let's now test that pattern with our python code so in the second sale we're going to write our solution We're gonna create a, new variable called temp, which refers to whatever v1 refers to which Is first string, and then we'll set v1 to be v2 So v1 at this point is second string and then we'll set v2 to whatever Temporary first - which is first string so at this point Once we print v1, we should be able to print second string? We do and then if we print v2 which would see first string and? We do okay, to download the files i created, throughout, this Post just go to rajcoding homepage and in courses section select label Python or if you just, want to Subscribe to my, newsletter so that you don't Miss my future tutorial Post just go down of this blog and subscribe with email to get all News and as always let, me know in comment below, when you thought of this Post i'm Ankit, from RajCoding, and i'll see you in the next Post?
thank you and Take Care.