YTread Logo
YTread Logo

Introduction to Python with Anaconda for Beginners

Introduction to Python with Anaconda for Beginners
welcome to the

introduction

to

Python

with

anaconda

for

beginners

my name is Matias and I'll do my best to get your style with programming in

Python

in this video I'll explain what

Python

is and what it is used for then I'll explain what

anaconda

is and show you how to install it we will then go over some basic

Python

commands and the syntax I'll also show you how to run your program from the command line and in the end I'll show you some examples of advanced Perl

Python

introduction to python with anaconda for beginners
programs to wrap up I'll point you towards some resources that you can use if you want to dive deeper into

Python

let's get started so

python

is a general-purpose programming language that can be easily used for small projects just as much as for large enterprise applications it is best suited for web development simple scripting and data analysis but its flexibility allows it to be used for much more such as web scraping game development machine learning browser automation and internal
things

python

is able to do all this mostly thanks to all the various packages that is extend its basic functionality and that the beta

Python

community continuously contributes to packages also referred to as libraries or modules our collections of code that serve a particular purpose and help you to speed up your development process an example of a package can be random which lets you generate random numbers

Python

is also very easy to learn and understand before we start coding in

Python

we
will quickly go over

anaconda

which is a

Python

distribution that comes loaded with hundreds of packages that are especially useful if you're planning on using

Python

for data science and machine learning

anaconda

is still extremely helpful even if you're not planning on using

Python

for data science because it comes with the Conda package man and a virtual environment manager and make it extremely easy to work on multiple projects at the same time all this means that

anaconda

makes
development with

Python

fast and eliminates all the headaches of tracking package dependencies unless you are an experienced programmer I highly recommend using

anaconda

since it allows you to skip setting up coding environments and allows you to jump right into the exciting part coding if you are an experienced programmer this tutorial might not be too beneficial for you in the first place hopefully I was able to convince you that installing

anaconda

will be worth giving up a bit of your
precious computer storage if so we'll install

anaconda

by going to www.eddecosta.com slash distribution

anaconda

will also install

python

on your machine so you don't have to download

Python

separately here we will click the download now button and choose

python

3.6 version to download you might have version 3.7 3.8 or something hi do not download

Python

2 as that is a deprecated version and some things might not work for you while this is downloading let's have a look at a very
helpful resource the documentation for

anaconda

which can be found over at dark stat aniconic on slash

anaconda

or you can click

anaconda

documentation link a lower part of the downloads page whenever you run into a problem with

anaconda

this documentation and your preferred search engine will be your best friends you can see that there's a lot of helpful links and information like the chichi or some information about

anaconda

working with the PIP which is a different package manager for

python

on the left side you can find the installation link where you can find all the necessary help in case you have a problem with installing

anaconda

here you can also find packages lengths we can find all the packages that come with

anaconda

let's quickly see all the packages that come in

anaconda

and since I'm running Mac OS I'll click on Mac OS here and on this page we can see the list of all the packages that are supported or come pre-installed with

anaconda

there's tons
on them which is a huge reason for use in

anaconda

because if you did not have

anaconda

you would have to install and manage these packages manually which can cause a lot of headaches let's see if our installer downloaded yet it indeed it so now we can run in this Installer is quite easy to follow mostly will be just clicking continue so let's do that two times and on this page we should notice that the installer is informing us about the fact that this installation will modify our path
what does that mean well the path tells our operating system which directories to search through to find executable files modifying the path means that we add a piece of code that will point our computer to the directory with executable files this will allow us to run various commands from the terminal window and is required for proper functionality of

anaconda

sometimes it is necessary for us to modify the path manually but this installer will do that for us which is great we can continue with
the installation now here are the software license agreement will agree with this because if we don't we cannot install it and on this screen we will have a quick look at the customize option here we'll see that the Installer will install

anaconda

3 and if we click on that it confirms right here that the Installer will modify our path you could tell then followed that you do not want to modify the path if you had a reason for it but we'll leave this option alone we can just switch
back to the standard installation setting and proceed with the installation since I already have an account installed I'll let you pause the video finish the installation and come back when you're done with that I hope that the rest of the installation process one without any hiccups now that you're done let's quickly confirm that the install added

anaconda

in our path I'm not good enough with Windows to guide those on those operating systems through the following couple
steps so apologize for that as long as you know how to change a directory open a file and list files in command line you should be good to follow on your Windows machine open the terminal window and make sure that you are in your home directory if you're not you can make sure that you are by typing CD and tiled since I am it will not change the director for me we will now need to find a file that stores the code that modifies our path the code can be stored in three different files the file
names would be dot profile that bash underscore profile or dot bash RC these files are always stored in your home directory which is where we are currently located and you might have one of those files or you might have two of them or even all three they all serve the same purpose so don't worry if you only have one to find which one of these files we have let's list all the files in our home directory to do that type LS this will list the files in our home directory as you can see here
however there are no files called dot profile that bash profile or bash or see that is because the files that we're looking for are hidden to list all files even the hidden ones in our home directory type LS - hey now we can look through all the hidden files whose names usually start with the dog as you can see and we can find that I have bash underscore profile right here you might have bash RC or you might have just that profile let's check the content of this file to confirm that the
installer added

anaconda

to our path and how it did it to open the file tap Pico and the name of the file which in my case is that bash underscore profile but in your case it could be bash RC or profile if I click enter I open the file inside of the file I can see all the contents and I can see three lines of code each of them adds a different directory to our path this line for example tells the operating system to search for executable files in the

anaconda

three slash bin directory the line
right above is adding a directory for my dev desktop app to work the first line is adding two other directories one is here and the other one is here they're separated by the column if you install a program that did not automatically modify your path this is the file that you want to access and edit we can exit this file by pressing ctrl + X you can actually check all the file paths that are in your systems paths to do that type echo dollar sign and capitalized path what you can see here are
all the individual pads when your computer is looking into for executable files right here the last path is the

Anaconda

path that the

anaconda

installer added so what this allows us to do is to run various commands through the terminal window like installing new packages with Conda install I would do Quinta install and then the name of the package or I can check the version of

anaconda

to be running that I would do that I would do that with and Conda - capital B this will show me that the
version of

anaconda

that I'm running is one point six point nine and now we should have a good understanding of path and how our computer knows where to look for executable files we have now successfully installed

anaconda

and we understand how PAP works we can now try to open

anaconda

we have two options we can look forward among all of our applications which would be right here

anaconda

navigator or we can type an account on a vagator and press return creator so this command works thanks
to our path which we which to install our modify it with press return we should see that Dan Khan is opening now okay so on the left side you can see that there are a couple of tabs we won't be using them too much but it is good to know what is inside in the environments tab you can create and manage environments in the learning tab you can find some articles and learning resources videos in the community tab you can enjoy various communities where you can learn as well there are a couple of
introduction to python with anaconda for beginners
applications on the main board than

anaconda

comes with like Jupiter lab Joker notebook and spider we will be focusing on spider which is the integrated development environment for

Python

it comes with

anaconda

let's launch it since spider is the place where you will spend most of your time while coding let's get the familiarize with it a little bit on the left you have the text editor right here here you will write a large piece of code that you want to save and execute repeatedly in
the upper right part you can switch between help file expert and variable Explorer window depending on what you need for example I can type int into the help window which will display information about the in function in the lower right part you can find a console where you will spend a lot of time while testing your code so the editor is well you will be writing your programs and the console is where you'll be trying these short pieces of code before we start writing a program let's try
to play a run in concert for a little bit so we can understand the

Python

syntax to do some simple math all we need to do is type the operation we want to execute a press return let's try to type 2 plus 3 we just typed is an expression which consists of a value and operators the two values we typed are 2 & 3 the operator is the plus sign expressions always evaluate down to a single value in this case the expression 2 plus 3 will evaluate down to 5 you can see that

Python

took the
expression 2 plus 2 as an input and output it a single value 5 you can also do other types of expressions like multiplication for example 4 times 5 or division like 10 divided by 2 with this we introduce the first data type integer other common data types are strength floats and boolean's strings are sequences of characters and we usually use this data type to start words and sentences unlike numbers strings have to be surrounded by quotation marks let's try to create a string hello
don't forget to put quotation marks around there and we got a return of a string hello we can also perform some operations on strings like adding two strings together with the plus sign let's try adding hell and Oh Plus this is also an expression and that consists of two values hell and oh and plus operator sign again this expression like any other expression evaluates down to a single value in this case hello another data type is a float floats are numbers with decimal points just like
with integers you can perform mathematical operations with them let's try to multiply two point three times four point four and this expression evaluates to 10.12 another data type is bullying which can be either true or false you can only have these two values it is not common to use traditional plus and minus operators with boolean's instead we use and and or operators the end operator says that the boolean value have to be true for the expression to evaluate down to true for example
the expression true and true will return true if we say true and false and false the expression well we'll evaluate down to false because one of these two values are as false and for this expression to be true when there is an end operator both would have to be true the or operator says that we only need one value to be true for the expression to evaluate down to true for example true and true or false have a value eighths to true false we'll have a write it down - true true or true will
also evaluate down to true the only way to make this type of expression evaluate to false is false or false values and expressions are essential for programming but they would not be too useful if we could not to store them good thing that we have variables with variables we can store values for later use we can also store expressions since they always violate down to a single value to store a value in a variable we used a silent statement the statement consists of a variable name and equal sign
and the value let's try to store the string hello in a variable called foo let's type the net variable name foo the equal sign and the value hello here this part is the variable name is the equal sign and is the value that we're trying to store if you press return we can see then in our variable Explorer the value came up now it shows up us that we have a variable called foo that has value hello the data type of the value is STR which stands for stands for string you can easily
overwrite the value in the full variable by assigning a different value to it let's try to do that tech foo the equal sign and one plus two now remember that this is an expression that will evaluate down to a single value one plus two will evaluate down to three so embrace return the variable foo has been overwritten now the new value is three because one plus to evaluate it down to three the type is no longer string but an integer now the three is stored in food we can use foo in an
expression for example let's try to add food to four plus four the expression will evaluate down to seven this is because when

python

is evaluating expressions it replaces the variable with whatever it's stores since food stores three it replaces it with three so in the end typing food plus four is the same as typing three plus four there is one more data type that we'll be using today the name of the data type is lists and lists is used to store multiple values if we wanted to store
the number one two and three without lists we would need to store each one of them in a different variable but list store all of them in a single variable just like this one two three the list starts with an opening square bracket and ends with a closed square bracket the values that we store in the list are separated by commas this is the first value in the list and it's one this is the second value in the list and it's two this is the third value in the list it's three it is
important to note that the first value in the list has an index of zero the second value on the list has an index of one and a third value in the list has an index of two let's try to store this list inside of a variable called bar bar is equal to one two three now when we press return you'll see that in a variable Explorer we'll have a new variable stored the type of the variable is list the name is bar and the value is a list the consists of three different values now if we call
the variable bar what we all get is a list of three values if we wanted to return a specific value from the list for example the first value we can do that by adding a square bracket after the variable call like this that bar let's try we let's try to return the first value in the list which is in the index of zero so we'll type zero in the square brackets and we're press return we'll get the specific variable we called for if we wanted to return any other value all we need
to do is call for the variable with the square brackets containing the index of the value let's say we wanted to return the second value in the list which is 2 all we need to do is call bar opening square bracket the index which is 1 and close square bracket now I'm going to press return we'll get the value 2 now that you know basic

Python

syntax we can create a simple program as I mentioned earlier there a ton of things that can be done in

Python

unfortunately covering how to write
complex programs with a lot of packages is beyond the scope of this short video which means so I will only show you a short program what we'll create is a restaurant picker this restaurant pickle will store restaurants analyst and a random number generator we'll choose a restaurant from said list we will also be able to and delete restaurants from the list as well as less the restaurant that we have stored in this program we will also use loops conditionals and functions if you have
never heard about any of these terms try to follow along as they are quite easy to understand a quick search on the Internet can also help you in case they do not make any sense at all remember that it is not necessary to understand every single statement in the code rather try to understand the bigger picture let's get started to open a new file you can press command N or go to the file and press the new file what do we will need to do is create a list let's call it star restaurants
list and this list will store some restaurants we can do Polanco clover don't forget to put quotation marks around your strings and let's do a sweet green greens and that should be enough for now these are the restaurants that the program is going to pick from when choosing a random restaurant that reminds me that we need to import a random module for it random this module will choose a random number and help us determine which is trying to go to here program is just telling us that
random has been important but we have been used it in our code which is fine little useful later to pick a random restaurant we'll try to call the random number generator will generate a number in range that we specify the parenthesis here if we do a 0 to 2 it will do numbers from 0 to 2 0 1 2 now if we restaurants list here if we run this of course we have to save it first let's call it just around take her save it now if we run this file nothing happens because we have not printed it
introduction to python with anaconda for beginners
on the screen so we'll have to use the function print now if you run it we're going to get a random number the random restaurant this time we've got sweet green if you run it again we're gonna get something else or the same let's try to run it again I got a below code now we get to clover then I got sweety greens again so this is working what do we need to do now is put it into a function so we'll define a function called pick restaurant and we'll put this print
statement inside of the function so the this is a function definition statement and inside the function is a print function that will print the random restaurant now we also want to have a way to add any westrom so we'll define a function that will allow us to add a restaurant to our list let's call it ad it's general this function will take one parameter let's call it name and all we need to do is say restaurant list dot append this is a method of the list object they will take
value and we'll pass it to the end of the list so mr. neurons list here if you run this object around us and if we say it's tyrant and put a name let's let's do dig in you will be able to see here in a very little Explorer that digging will appear at the end of the list here it is so it is working that's great let's define a function that it will remove a restaurant from this list let's call it rent this function will also take the name of restaurant we want to remove
and to remove something from the list I'll call the name of the list that we move up ah geez I don't know restaurant but around first does remove restaurants please no and that will take the parameter so now if if we call remove I stir it around and say we want to remove below Co you'll see here that below Co will be removed from the list there it is it's gone now you might notice that digging is no longer here as well that is because this list is initiated every single time we
run the program so every single time we run it the list will be created from scratch so now when I run it again focus is back here now let's create a really simple interface for the user to use so that they don't have to type remove restaurant at a restaurant and pick restaurant every single time they want to use this program we'll use a while loop for that so while something is true so this is an infinite loop and you would not want to do that you have to make sure that there is a
way for the user or for the program to end this loop and we'll do that with the break statement but if you were to run anything loop your program but it will not work so what we want to do is print a little message for the user and give them some options that they can choose from so the first option would be to to list all the restaurants and we have not yet implemented dysfunction but it will do that soon the second option would be to add a restaurant third option is to remove restaurant
the fourth option will be to pick restaurant and the fifth option would be to exit the program so this add a restaurant option will utilize our add restaurant function remove restaurant will utilize remove restaurant function and big restaurant will utilize the bigger restaurant function now if whyever right to run this program you will see that this message will be printed to the user over and over and over again until I stop it with ctrl C this is what happens when you have an infinite loop in
your program let's let's try to do that I'll show you how it looks so you see how is it being printed in print and print it over and over again I will stop the execution of the code well attempt to so I've used control C to interrupt the execution of the program otherwise you've ran forever now we'll add some if statement so if Oh before that we'll have to ask the user to select one of these options we'll do that with an input function so in the input we'll
ask the user to please select option from please select an option that's good enough I think and save the selection and a variable let's call the variable selection now once they select will run their selection through series of if statements determine which of these function we want to run so if selection is equal to one so here we will implement the list restaurants little later l if so else if this is not true it will go to the other to the next line up to Co which is here and check
whether this one is true or not so let's say selection goes to two and if the selection is equal to two we will want to add a restaurant so what we will do is call the function add restaurant that's restaurant now you also have to ask the user to input the name of the restaurant that they want to add and we'll do that again with the infant function so a name that's equal to input and we'll ask the user to input their restaurant please we have been nice enough to them here I
can just say type and here in the parameter we'll put in name else if so if neither of these are true we'll go to the next next if statement which is here and it will check whether this one is true or not three so it tastes like three we'll want to remove the restaurant and again we'll have to ask them for the name of the restaurant do you want to remove please step on the please type name of the restaurant that you to remove you to add let's just add a little bit more
clarification so they know what kind of what is happening now we'll call the function to remove s turn around and input the parameter and name then we'll go to another if statement o selection floor so each of these will determine whether the if statement will go to the next if statement or not this expression will evaluate to true the code inside of the if statement will run so if the you if the user puts it puts one then the selection here will basically be replaced by one and one
indeed does equal to one so that would mean that this expression would be one or it would actually look like one is equal to one which does evaluate to true I'll prove it to you here this evaluates to true which means that this expression would evaluate down to true and the code inside of this will run I change it back to selection the same would be true for this if if user selected two then this would return false because two equal one will evaluate down to false it would go to the next
statement which is here it will check whether 2 is equal to 2 that would evaluate to true and the code inside of this statement would run the next selection would be typical restaurant so we would run the big restaurant function now this function does not need any parameter and certainly we do not need to ask the user to input any and last option the user has just to exit out of the system so say okay LF selection L F stands for else if so if else if this is true when this else if this is true
Ventus else if this is true friend is and so on so if this is equal to five break so this statement right here will exit the infinite loop at this point we can actually try to run the program I believe expected in infant blog okay so it actually wants us to do Lester s to write something in here we have nothing we have no function to put in there yet so let's create one that's define a function list and in this function we will go through every single item in the restaurant list and
print it so for each just turn around and most restaurants list so what this is saying is for each item or for each value it will be below Co clover and sweet greens and restaurants list restaurants list pray do something so do anything that is in here will be done for every single value in the list what do we want to do for every single value in the list is to print it so what we'll do is just say print mister run and now every time we call this function the function will go to the
restaurants list go through every single one of these items and print them we can add the function into our if statement say list restaurants and since we do not need any parameter it will just list all the restaurants we don't need to ask the user for the input there must be a nervous I'm you yeah should be correct no it's correct let's save it and let's run the program if I click run file I'm being prompted to making a selection so what it did is print this part of the
code now it's asking me to make a selection right here with this input function so what I'll do is say I want to list all the restaurants I'll click one now it it listed all the restaurants here Bullock or clover and sweet greens it looks kind of sloppy because it's right it printed it right after my selection so we can make it look better by printing an empty line so that there is little space between this line of code and just so just print an empty line now if I wanted to add
a restaurant let's try to do that let's show you press - now we're asked to add a restaurant let dig in again again let's press return no nothing happened but or at least I think it seems to be happening but if I press press 1 again the rest all the restaurants will see that dig in is now here so the gain is part of the list if I want to remove restaurant let's press 3 let's try to remove clover let's press return now again nothing seems to be happening we could
implement a little message to the user somewhere down here below that would say you have successfully removed clover from the list but you don't have to spend time on that right now but to check whether it has been removed or not I can just press what a type one does return and I'll see that clover is no longer no longer part of the list now if if I were to accidentally type something else than one of these five numbers if I press L for example type O and press return it just went
through the loop again because while this loop is true it will always run so it would be good to read a little message to the user about what happened why he's being asked to and put something again so the final part of our code will be else and if none of these are true then the last statement right here would run and we want to say something like please select one of the options above so now when we run it and user makes a wrong selection it will tell him that that was an error he
didn't select any of the correct options and ask him to select one of the options above let's try to exit this for again for now it's plus five no program is done executing now we have to run it again so that all the changes we have made in a code will take place let's try to press elegan we type the wrong option it tells us error please select one of the options above which is exactly what we wanted if we wanted to make a brick I want to have a line between these two messages we
can just put a line break so we would put backslash n now if we were to print it again I was actually doodad there would be space between you two so look a little nicer typo press Enter there is a little space between the two we could do that I don't want every one of these messages so that everything is nicer we have no two messages right next to each other but for now it looks pretty good now there's one more thing that needs to be done before the program is completely finished and
that is to make this random integer generator flexible depending on how many items we have in our restaurant list right now it will return numbers from 0 to 2 randomly and depending on what it returns it will select one of these items in the list if it returns 0 it will return the first item if it returns 1 we will get the second item if it returns 2 will get the third item but if we were to add one more item to our list which we can do with this add the rest function this restaurant would never
be picked because this random integer generator is random integer generator will never returned number three which is the index of this value so what we need to do is look up the length of this list so that this random integer generator can return values depending on how many items we have inside so what we need to do is call the length function and well put the restaurant list in there yes so this length function will return a number depending on how many islands we have in this list so we
return in this case it will return 4 1 2 3 4 but what we actually want is 3 because we want the index not the actual length so what do we need to do is to minus 1 so now I will return numbers from 0 3 let's try to run this if it works let's save it we have an error here on the restaurant list here now it should work let's run the program let's pick a restaurant sweet green clover sweet green again look oh so it was able to get the last item in the list which is exactly what we
want it it works properly now and it can be pretty happy with the program there are some things that could be done to make it even better but for now it's pretty good now that you have finished writing your program let's try to run it to the terminal so you don't have to open Spyder every single time you want to use this program to select the restaurant for you let's open a new window in my terminal and here will have to go to the location where the file is stored in my case
it's on the desktop so I'll type change directory and go to desktop desktop now that I'm on desktop I can list the files in here I can see that I have two files which I didn't do and we'll have to change the permissions of our restaurant picker that py file to do that type CH m OD + X and now you have to type the name of the file that you change trying to change the permissions to picker py press return and permission should be changed by now now if you want to run it all you
need to do is type dot slash and the name of the file that you want to run I think our case it's restaurant picker if I press return I should be prompted with something we have already seen if I press one they list the restaurants that I have stored just like everything we've done before if I press pick I'll pick one of those for restaurant it picked sweet means I do it again it's below echo ever if I click five it will exit this program in the last part of this tutorial I would
like to show you a more complex file or program that can be created with

Python

I'll pull up a program I will wrote a while preparing for the intro to data science class that is offered here at Suffolk this program accesses the world factbook which is located on the CIA website it would be just pull it up really quick the program collects some interesting information about every single country in the world and saves it into the CSV file so the type of the information that is looking for its
area GDP roadways railways the type of the program that this is is called web paper it scrapes data from a website I also show you the website that it scrapes the air from let's go to Safari open a new page so there's a list of countries here here's all of them it's more than 150 countries and it goes through and for every single country opens the webpage finds the area the total area it also finds some information about GDP which is somewhere down here I believe economy it finds
the total purchasing power and I also find the length of the railways and roadways so the length of the always right here so you can imagine how long it would take you to get it by hand to go through every single one of those countries and get that information now if I run it it will run for a little bit considering that it goes through over 150 web pages so now you can see that program is done running it took actually much longer than I expected it took around a minute for it to go to 150 pages
we can we can open the file right here it's the output file see I ate that CSV that's shorter in finder and look at the data so for each of the countries it found country name it it's code the area the road length the railways length GDP and put it into this CSV file there is over oh not over 150 it's 269 different entries so in this program went through 269 web pages and collected this data so the fact took it a minute is pretty good considering it had to download every single
one of those web pages so this is the end of the tutorial I really appreciate your time I hope I was able to teach you a thing or two if you're interested in learning more about

Python

I would recommend looking into a book called automate the boring stuff with

Python

which is an excellent resource for

beginners

it will teach you all you need to know not just about

Python

but programming it's a pretty good start you don't even need to buy the book because the author distributes it for
free and an HTML form on its website which is listed on the screen the website is automated the boring stuff com if you prefer to learn from a PDF or hardcopy it's worth the $20 or how much it cost to buy it I learned a lot from it another good resource is data camp calm if you're interested in using

Python

for data science it will teach you much less of the basics but if you already know that it's an amazing resource the Information Systems Club at Suffolk University or you can also
give you access to all the paid content because the camp comm was very kind to give them complimentary access to all the club members also if you wish to give me feedback or have any questions about this tutorial I'll be really happy to chat with you you can reach me at em Kowalski at SU that Suffolk that edu and for now happy coding thank you again