in this course I'm gonna teach you everything you need to know to get started programming in
python.
Python is one of the most popular programming languages out there,
and it's by far one of the most sought after for jobs
and so if you're trying to get a job
or you're trying to you know,
automate your life
or you try to write awesome scripts to do a bunch of different things than
python's for you
honestly
more and more developers every day are moving their projects over to python because it's such a powerful
and the surgeon
easy to use language,
a lot of programming languages out there just aren't very beginner friendly there's
a lot of syntax there's a lot of like little things that if you get wrong the program will yell at you.
python is the complete
opposite of that.
you basically just type out what you want to do in python does it it's that simple there's not
a whole lot of syntax to learn the learning curve is literally zero you jump in,
you can start writing your first program in seconds.
in this course
I'm gonna teach you guys.
everything you need to know to get started in python.
I designed this course
especially for python,
and each lesson has been specially designed with examples
that will help you along the way.
with so many people starting to learn python the question isn't,
why should you learn pipe on the question is why shouldn't you ?
and I think for a lot of people the reason they might not want to learn python is because they're intimidated or they're afraid that it's going to be too hard.
trust me I am going to hold your hand through this entire course we're going to talk about all the core concepts in python we're going to look at
everything you need to know
to start programming in python and start being confidence are writing scripts and start writing programs that are awesome in doing cool things in your life.
anyway
I'm super pumped to be teaching you guys python.
I can't wait to get started in this course
and I hope you guys stick around and fall along with the course and learn this amazing programming language
in this tutorial dominates three guys how to install python onto your computer.
and we're also going to install a text editor that we can use to write
our python programs
in.
so the first order of business is to actually install
python on your computer.
so we want to do is head over to your web browser
and
you want to go over here to this page it's just
www dot python dot org
forward slash
downloads
and on this
page there's
going to be
two buttons down here
and this is going to say download python three point six point three.
and at least
the version that I have right now or download python two point seven point one four.
so here's the thing about python there's actually two major versions of python
that are in use
currently
there is
python two
and there's python theories you can see over here,
this is like two point seven point one four
basically any python two
version we would just refer to as like python two
and here's like the latest
python three version.
and so there's these two versions that you can download and the first thing we have to decide on which version do we want to download.
and here's the basic difference
python
two
is a legacy version of python which basically means that
it's like an
old version and it's not being like actively maintained or supported
like officially by python anymore.
python
three is like the future of python it's like the newest version it's the one that's getting actively maintained and supported.
so there's pros and cons to picking either won
a lot of people say like python too
has been around longer and so there's more like
libraries there's basically just more python code written in python two
so therefore like there's a few more things that you can do in pipe onto then you can do in python three
but then again
python two is not supported and you know,
five or ten years from now
probably no one's going to be using it.
python three it like a site is like the future of python it's the newest version it's the one that
you know it's sort of being maintained going forward.
so for the purposes of this tutorial I'm going to be teaching you guys
python
three
so we're going to want to download python
three
now here's vaguely
if you learn python three or you learn python to the differences aren't very big.
there are a few differences in like some syntax and just so
you know little things here and there,
but if you learn python three you'll be able to jump right in and
code in python two as well don't let anyone
tell you that
you have to learn one of the other.
we're going to learn python three just because it's I think probably the best for a beginner to learn.
and so that's the one that we want to download so I'm just going to click download python three
and we're gonna go ahead and download
this version.
and when that's done downloading I'm going to head down to my downloads folder
and you'll see here we just have this file
doubleclick,
and we get this like python installer so I'm going to click through here,
and we'll be able to install python three on our computer
right when that's done and stalling we can just close out of this and we should begin to get us now we have python three
installed on our computer.
the next step
is we need to choose a text
editor so
we're going to be writing a bunch of code so we're going to need some you know environment of some program that we can write all that code in.
and really you can write python in any text editor you could write it in like a note pad or tax at it,
it doesn't really matter
but there are special
text editors that are designed
just for writing python code.
and these are called
id ease and not stands for
integrated development environment.
it's basically just a special environment where we can you know ron and execute our python code.
and it'll you know basically like tell us how we're doing so were
the only if we write something that's wrong or we
have errors it'll kind of
point us in the right direction of what we need to do to fix that stuff,
so in this course we're going to be using an idea
and
one of my favorites
and one of the most popular ity ease for python is called pi charm.
so I'm over here on this website.
it's called
jet brains
dotcom
forward slash
pi charm.
and this is the idea that we're gonna be using in this course
so I'm just gonna come over here and click this big download
now button
and we'll go ahead and
download this
pie charm program
right so I'm getting this page are here you can see there's two versions of pi charm
one as a professional version and that one's like paid they have to pay for it.
but then there's this community version down here and that's free and open source so I'm going to download this one
and this should have everything we need to get started using python
right when that finishes downloading I'm just going to
pull that up in my downloads folder
and
again we can just sort of
run this guy
and I'm on a mac so I'm going to have to drag it over to my applications folder.
all right so now have pi charm
and we have python
three installed on your computer.
so we're ready to start programming in
python.
in this tutorial we're going to create our first
python program.
and we're going to be able to run it and
see how everything works.
the first thing I want to do is open up
pi charm so pi charm was the
idea he the
integrated development environment
that we downloaded in the last tutorial so
I'm just going to go out and search for it on my computer
and I can just open it up
and we first opened up high charm we should basically just get a window
prompting us to create a project.
so you can see that down here.
actually the first thing I want to do though is come over here to configure
and I'm just going to
click on preferences.
and I actually want to
change the appearance
so
I'm gonna go ahead and
give this a theme so I just went over here to appearance and behavior appearance
and I'm gonna change the theme to
darker color
because I think it's a little bit easier to
use and look at,
but you don't have to do that if you don't want you
so
down here
I'm just going to click
create new projects
and it's going to
give us this little window right here so I can just name my project.
and I'm just going to name this
graph.
and then there's other option down here where it says interpreter.
now
what we wanna select
is
python version three
so if I click down here you'll notice that there's a couple different options.
so I'm on a mac computer
and
by default mac has
python
version two installed on it.
if you're on a windows machine I'm not sure if it does but
in this tutorial we're going to be using python three so you wanna make sure that you have python
three selected as the interpreter,
otherwise
you
might not be able to fully follow along with what we're doing in this video.
so now it's going to come down here and click
create.
and this is going to go ahead and create our projects
for us
right so now we have
our
python project
up and running,
and I'm sure you guys how we can create our first
python program,
so over here in this draft folder and this is just that project that we created.
I'm just going to right click
and I'm saying new
and I'm going to come down and click
python file so we want to create a new python file this will be our first
python program.
and
I can just give this a name,
so why don't we just call this
app
and it's going to click ok
all right so now we have our first
python file
open
and we can just start typing in some python so I want to show you guys.
does a very basic python program.
and this is just going to be a hello world programs so we're just gonna print something out onto the screen.
so when I say
what I want to do is I want to type out p r iyer anti prince
and wanted to have an
open and closed
parentheses
now
inside of those parentheses we can make some
quotation marks
and inside of the quotation marks I'm just going to tape out
hello
world.
so this is like a very basic python program.
and what this is gonna do is
it's just going to print out hello world
onto the screen.
and so now what I can do
is I can actually run this file and we're actually getting a little arrow here it wants us to create a new line
at the end of the file.
and so now in order to run our python program I'm just going to come up here to the top
and I'm cinematic run
and we'll click this run button right here
and I will see what happens
so it's
asking me what I want to run I can just click add up
and
down here at the bottom you'll notice that we have this text that just got printed out
hello world,
so
whatever I
print
or whatever I put inside of this print statement is going to get printed out
down below in the council so
as long as you're getting that print statements work then you
actually written your first python program.
and as we go through it
forward in the course were can be writing
all sorts of awesome python programs.
and we're going to do an
all sorts of cool stuff
in this tutorial I wanna talk to you about writing a basic python programs so we're going to write it as a very simple python program.
we're going to look at how we can go ahead and write up programs we're going to talk about
how our programs are getting executed by python
and we're also going to draw out a little shape onto the screen so
this is going to be pretty cool I'm excited to
talk you guys about just the
bare basics of python,
and really just sort of give you an introduction so
over here
we have our
basic text editor and so
any of the
python code that I write inside of this file
is actually going to get executed by a python so
this python file
has a bunch of
python code inside of it.
and basically what we're doing when we're
programming in python is we're just giving the computer a set of instructions.
right that's really what programming is it's just like we're specifying a set of instructions
and the computer is going to go off and execute those instructions that we give it.
and so
the more complex the instructions we give to the computer the more complex
the tasks
the computer can
carry up.
so I'll show you guys how we can use some python instructions or some python code
in order to draw out a shape onto the screen so
I'm actually going to draw out
a little triangle.
so over here,
we can actually print something out onto the
screen and python using something called a print statement so I can just type out
print.
and inside of these parentheses.
I can just type
some quotation marks
and inside the quotation marks
we can
put whatever we want to print out onto the screen.
so I'm gonna
copy this and I'm actually going to make
a few of these little prince statements
and we're going actually draw a sheep.
so
we're gonna draw like
a triangle type shape
so down here it's gonna draw a forward slash
and then up here I'll make a space and we'll do another foreign sash
here will make
two spaces
with united forward slash.
and over here
we can make three spaces and afford sash.
and now I'm going to draw like a vertical bar is going all the way down.
and actually we can do some underscores here as well.
I think high school
right so now we have our triangle looking shave and you can see
it looks kind of like a right triangle
so I can save my file.
and I can either come up here to run and
click run app
or of using pie charm you can also just come over here and click this play button
and when I click the play button I want you to notice what happens down here
so
down here we have this little window and
this is called the consul
and it basically the council is a place where python is going to
output some information so
when we use this print statement were basically telling python late
hey can you print something out onto the consul.
so
there's a lot of situations where we're gonna wanna see what's going on in our code.
and we can use that print statement and
print things out to the council.
and we can basically like have a little window into what our programs doing
in our case we're just going to be printing out this triangle onto the consul.
so I'm gonna come over here and click this play button
and you'll see down here
we're actually printing out that
triangle
so mission accomplished we were able to print out our shape.
so I can really draw any shape I want it as long as I was
able to
specify
inside of these print statements.
so
essentially what python's doing when I click that play button
is it's going into this file and it's looking at all of these instructions in order.
so the first thing it does is it goes to this instruction and it says
ok,
they want me to draw out these like little forward slash in this vertical bar onto the strain,
once it does that it goes down to this instruction it says
ok
they want me to print something on again
when it prints dot out it goes down to this instruction
etc
so
python is actually going to execute the lines of code that we write
in order.
so
the order in which I write the instructions
matters a lot.
so for example if I was to take this last line here
and put it up here at the top.
now when I save the file.
instead of just drawing up that triangle.
it's going to draw out
this little upside down
bottom thing at the top and then
the rest of the triangle down here so
the order of the instructions actually matters a lot.
so this is basically how your python programs are going to go.
as we go through this course we're going to learn more and more of these little lines so here we're just using this little print function basically and just print something out on to the screen,
there's a bunch of little things like this that we can learn as we go through
will learn more and more instructions that we can give to the computer.
but in this lesson I just wanted to kind of show you guys the basics right.
oh
we can essentially just define these little instructions for the computer
and the computer will execute them
in order.
and this tutorial I wanna talk to you guys about using variables in
python.
now in python and you're going to be dealing with
a lot of data
and so a lot of times in our program we're going to be working with
all types of information and data and values,
and sometimes that data
can be difficult to manage.
so in python we have this thing called a variable.
and it's basically just a container
where we can store certain
data values.
and when we use a variable when we put those
data values inside containers.
it makes it a lot
easier for us to work with and manage
all of the different
data inside of our programs.
so variables are extremely helpful and it's sort of like a
core topic in
python that you're really going to want to know and master.
so in this tutorial omelets each you guys.
everything you need to know to get started with variables we're going to look at what they are
why they're useful and we'll look at the different types of variables
and the different types of
data that we can store
inside of variables,
who over here in my
python file I just have a very simple program.
and it's basically just printing some text out onto the screen.
and so this is actually a little story that I wrote it says.
there once was a man named george
he was seventy years old.
he really liked the name george
but didn't like being seventy.
so this is a valid python program I can go ahead and
run this program
and you'll see down here in the council
everything prints out and
it looks great so
we have an awesome little python program here.
well let's say that inside of our story I wanted to change
the character's name
so instead of naming the character george let's say I wanted to name the character
jon
well
I'm going to have to go through and I'm going to have to manually change the name george to the name john at every place inside of this story where it's mentioned.
so I'm not to go over here and I'll say
ok
john I'm going to have to manually change that
and then
ok it's out here we're going up to again manually type in john and change it to john.
so in order to change the character's name I had to manually go in and change it in both places.
and now let's say
ok
maybe we want to change the characters ne
age also so in addition to changing the name.
we also want to change the age let's make him a little bit younger so why don't we say john is going to be thirty five.
so you see here I had to come here and manually change the age and then come down here
and manually change it again
right.
and now that we changed it like
it's going to work it's going to be updated in our program.
but you'll notice that in order to make that change like I had to look through the entire program find it where that
value was and change it,
and
this was only with
four lines
of the story imagine if I had a story that was like
thousands of lines long.
and we mentioned that the character's name and
age like
hundreds of times.
we don't have to look through each one of those lines and
manually change the character's name
and that is not a very good way for us to do this
and
it's really not a good way for us to manage the data in our program right the
character's name in the age.
and so we can actually use a variable
in order to store
the character's name and the characters.
age.
and when we use that variable it'll make it a lot
easier for us to put the character's name and age.
inside of our little program here.
so I'm gonna show you guys how we can create a variable for the character's name and age.
now it's going to go up here above this print statement.
and
up here I want to create a variable.
so when we create a variable in
python we actually need to give
python
a couple pieces of information.
the first piece of information we need to give python is the name of the variable so I need to actually assign a name
to this container where we're going to be storing information.
so all I have to do is just type out
the name of the variable
that I want to create so I'm going to create a
variable called character name.
so I'm just going to say
character
adam's they underscore
name
so generally when you're creating a name
for a variable in python.
you want to separate different words
with an underscore so I have two words here and I'm separating them with an underscore.
and now what I need to do is I need to
put a value
inside of this very more so
basically what I can do is I can just say
equals
and over here I can type a value
so I'm just gonna type out the character's name inside of
quotation marks.
so we're just gonna type out john.
so now we have a variable for the character's name
and below this character named variable I want to create another variable called
character
age certain just going to tape out
character
underscore
age.
and I'm going to set this
equal to the characters age which is thirty five.
so we now have two variables,
one representing the character's name and one representing the characters
age.
so what I can do now as I can replace
the character's name inside of this story
with
this variable.
and I'm gonna show you guys how to do that
so if we want to put a variable inside of this print statement.
I'm actually going to have to do a couple of things.
the first thing I'm going to have to do is
end off this
text in here so I'm going to have to put
a
quotation marks here the end
and you can see I'm basically
wrapping this whole thing into a
single like quoted line.
and now I also have this tax overhear the end so I'm going to have to put a quotation mark here.
so now I have
a
bunch of tax year in quotation marks.
and then I also have tax over here in quotation marks
now inside of here
instead of
saying the character's name
I want to refer to that character name
variable
so I'm just going to say plus
character
underscore name
and I want to say another plus sign so I basically I'm saying I want to
print out all of this text,
plus
the value that stored inside of character name
plus
all of this text.
and what this will do is they will actually print out the character's name we print this
so I'm gonna go ahead and run this program
and you'll see down here
and actually let me put a space over here,
and we'll run it again.
so you can see down here,
we still are printing out there once was a man named
john.
and so what python is doing is when it executes this line of code
it's coming over here and it's seeing
ok they want to turn out.
the value inside of character name
so it
python's going to go up here it's going to get the value,
and it's going to
insert it inside of there
so I can basically do this for every instance of the character name in my file so I can
you know
r is copy this guy right here
and
I can just paste it down here where the characters name is
so apace this
and you can see now were doing exactly the same thing that we did up there.
I can also do this for the characters
age someone to come down here
and I'll paste in what we just paste it in.
and I'm going to change this instead of character name was changed to character
age.
and I'm going to do this
in one more spots are going to do this over here we're mentioning the age
and again I'll just change this to
carry
your age.
and so now when I run this program it's going to print out the same story they were printing out before,
but
now I don't actually have to type in the character's name and the characters age.
I can just refer to this
variable.
and the cool thing about variables as if I wanted to change the character's name.
now all I have to do is change it up here so I could change the characters names you like
tom or something.
and we could also change their age so I could change
the age to be like fifty
and now that's going to automatically update throughout our entire story
when I click this play button you'll see
now we're using the name tom
and he's fifty years old.
so that's where variables can come in handy and
this can be a really awesome way to control and manage
the data that's inside of our programs
with variables you can also
modify their values
so
for example let's say that halfway through the story I wanted to change the character's name
why can just make some new lines over here,
and down here
I can actually assign a new
value to one of these variables.
so I can say like
character
underscore name,
and in order to give it a different value all I have to do is just say equals
and will give it a different value and so
let's say halfway through the story we want to change the character's name to mike
one now when I run my program
you'll see here in the first part of the story it says
there once was a man named
tom.
and in the second part of the story,
it's referring to the name as
mike.
so I actually
updated the variable
inside of my program
over here
and that's a really awesome way
you know a lot of times in these programs you're going to want to be modifying the values of variables
so you can do it
just like that.
and so finally I want to talk to you guys about the different
types of data that we can store inside of these variables.
so over here
I have the character name and character age
and
I'm actually storing what are called strings,
so a string is basically just
plain tax straight
so the name tom that's just plain text
down here these guys are strings as well.
so there's a data type in python,
called a string and it's just
basically going to store
plain text
so
you know any text that you would have like in a story early know someone's name
you can store inside of a string.
there's also another type of data
that we can store inside of python
which is numbers
so an additional storing text we can also store
numbers.
so if I wanted to start a number for example
let's say we wanted to store the character age instead of inside of a string.
we can store it inside of a number so
I could just type out fifty.
and when we're storing a number we don't need these quotation marks
you only need that quotation mark
when you're storing a string so if I wanted to a number I can just
write it out like this,
and in addition to using whole numbers I can also use decimal numbers.
so I could say like fifty point five six seven eight
to one three
and pythons are going to be able to store
that number as well.
you can store all different types of numbers
and we can also store
what's called a boolean value
and a boolean value is essentially a true or false value.
and there's a lot of instances in programming where we're going to want to represent
true or false
data
for example I can have a variable called like
his mail
and this would tell me whether or not someone was a male,
and in my case it will be true because I'm a guy right so I can
actually this needs to be
capital
so
I could sort of value of either true
or
false.
and actually if we were naming this in python
we want to use an underscore or so I would say
is underscore mail
and this can be either true or false
so
true or false values is maybe not something that you're used to dealing with like in the real world
but
in programming we're going to be using a true or false values
all the time they're super important so
like I said there's three basic types of data that we can work with in python there's
strings which is just like a plain text,
numbers which would be like either decimal numbers or whole numbers like this,
and there's true or false
values.
and these are the basic types of data I mean there's a bunch of other types of data that we can use but I would say ninety nine percent of the time.
as a new user
in a new programmer to python,
you're just going to be dealing with these
three types of data
so
those are the basics
of the data
and
also with variables
and you're going to be using variables
all the time in python so you definitely want to practice up and get comfortable
using them
in this tutorial are talks you guys about working with strings in python.
now what the most common types of
data that we're going to be working with in python is going to be strings
and strings are basically just
plain text so any text
that we want to have inside of our program
we can store inside of a string.
so I wanna talk to you guys about all the cool things we can do with strings and we're basically just going to get a
full introduction into why strings are awesome.
so over here,
I'm just going to actually print out
a strings I'm just going to say print
and
inside of these parentheses.
I can type out a string
in order to create a string I need to use quotation marks so I can make an
open and close quotation marks
just like that
now
inside
the quotation mark I can put whatever text
I want the string to have so we could say like
draff
academy.
and so now we have a string
with the text
draff academy inside of it
so if I run my program.
now down here we're going to print out draff academy as you can see,
and when we have these strings there's actually a bunch of cool things that we can do with them so
one thing I could do would be to create a new line inside of the string so if I wanted I could come over here,
and I could save backslash
n
and you can see it got highlighted in a different color.
and what this is gonna do is it's actually going to insert a new line into the string so now it's going to say draff on one line
and academy on another line.
so I'm gonna click play.
and you'll see down here we just get draff academy,
an addition to the backslash
n
I could also use
a backslash
quotation marks so
if I wanted to put a quotation mark inside of my string.
I can't just put a quotation mark like that
because pythons going to think that I'm trying to end
this strength.
so if I want to include a quotation mark I can just use this
special backslash character
and that's called the escape character and it
basically just tells python that
whatever character comes after it we want to
render a literally so
when I say backslash
quotation mark.
it basically means like
hey python
I want to point out a quotation mark.
and so now we'll be able to print
out
a quotation mark
right there.
I can also use this to print out of backslash so if I needed to put out a backslash.
I could see backslash,
and
it'll just print out a normal backslash now
so you can see just like that so
if you want and you can use that backslash to make
new lines or pronounce quotation marks,
or you can just use it as a normal
backslash
in addition to just typing out a string here I could also create a string
variable.
so I could come down here
up here and we can create a variable and let's call it
phrase.
and I'm going to set it
equal to
drop off a colony,
so I can
store this string value inside of a variable called phrase
and then when I want to print
out that variable,
or I want to access that string variable.
I can just
type the name of
the variable.
and you'll see that it's going to print out the value that was stored inside of it.
I can also use something called concatenation
and concatenation is basically the process of taking a string and
appending another string onto it.
so I could come over here and I could say phrase,
and I can say
plus.
and now I can add in another string so I could say like
is cool.
and now this is going to say
druff academy
is
cool,
so I'm basically appending another string
onto another one they call that concatenation.
and so in addition to doing all that stuff we can also use a special thing is called
functions
and a function is basically just a little block of code that we can run
and it will perform a specific
operation for us,
so we can use functions to modify our strings.
we can also use functions to get information about our strings.
so
I'm gonna show you guys a couple common functions we can use with the strings.
and
they're actually going to do awesome stuff so
in order to access one of these functions I can just say phrase and then I can say
dot.
and
I'm gonna show you guys a function that we can use to convert this
string entirely into lowercase so I could just say phrase dot lower.
and I'm going to want to type an
open and close parentheses,
and this will take this phrase,
it'll take my string and it will convert it to lower case.
so you can see now we just have a draft academy done here but it's entirely in lower case.
I could also do the same thing for upper case so I could say phrase dot
upper
and this will convert the entire string into
upper case so you can see now it's
entirely upper case.
so in addition to
converting the string into upper case
lower case
I can also
check to see if a string is entirely upper case are entirely lowercase.
so for example I could say phrase dot
is upper.
and this is going to give me back a true or false value
so it's going to be true
if the string is entirely upper case
or false
if it's not.
and you can see here we're getting a false value because this
is an
upper case
I can also use these functions in combination with each other so for example,
I could say phrase
dot
upper
and that a
parentheses
and then after this I can say
dot
is upper
and now what it's going to do is it's going to run this
upper function,
it's going to convert it into upper case.
and then it's going to run this
is upper function right after that
and you'll see now we're going to get a true value back because it will have converted the whole thing into upper case.
so you can see now we're getting a true value so
the news these functions
one after another it can be really useful.
and there's a few other ones that I want to show you so we can also
figure out the length
of
this string so
if I wanted to figure out how many characters were inside of this
string I could just say
l e n
and I'm actually going to make an
open parentheses,
and I'm going to make a close parentheses.
so I'm essentially saying
alien and this is another function it's the length function.
and inside of this alien function I'm actually passing
this
phrase variable
basically giving the length function this and it's going to spit out a number so tell me how many
characters are inside of this string.
as you can see here we get fifteen because there's fifteen characters inside of draff academy.
so that's how you can get the whole length of the string and that's going to be really useful as we go forward in python.
we can also get
individual characters inside of a string so
imagine if I wanted to just grab one of these characters like imagine if I wanted to
figure out what the first character in the string is
we're going to actually use
and open a closed
square bracket
just like that.
and in here I can specify the
index of the character that I want to graph.
so if I wanted to grab the first character in the string
I can put in a zero.
so if I say phrase
square bracket zero,
this is going to give me that capital g
and you can see down here
that's what gets printed out.
now I want to point something out
in
python.
when we're working with strings.
a string
gets indexed
starting with zero.
so you'll notice that in order to access this g.
I had to put a zero in here.
that's because in python.
when we use indexes on a string we start with zero
so if python is counting the characters
or its indexing the characters in a string it's going to start with zero so it's going to say
g is zero
I as one are as to
a history.
so we would say that g is at position
zero in the string.
I is at position one
r is at position two
a's at position three etc.
so we start counting
at zero.
so if I wanted to access
the first
character in the string.
this g I have to say phrase
zero and that's just a special thing
in python and actually most programming languages
do that so they'll start with
zero.
so for example if I wanted to access this
ei,
I'm going to have to put
zero
one
two three so I put three inside of here
now will be able to access that first
a.
as you can see we get an
a right here,
so this
is actually really useful being able to grab a specific character inside of a string
and you're gonna be using it
that a lot as we go forward and python
is also another really awesome function that we can use and it's called the
index function.
and basically what the index function will do is it'll tell us
where a specific
character or string is located
inside of our strings like unsafe phrase
dot
index.
and
I can actually give this a value so sometimes when we use these functions in python,
we can actually give them information so I can give this
of value
and we would call this passing a parameter so
I would call a value that I would give to a function
a parameter and you'll hear that word a lot.
so
for example I can say inside of here
capitol g,
and now this is going to return
the index
of
the capitol g inside of our string
so it should give us back
a zero because g is at the zero of index
and you'll see down here that we get a zero because that's where g is.
so for example if I put in
a inside it here like the lower case
a
it should give me zero one two three
because that's where the first
aid is inside of this string,
so I can click the play button
and you'll see it's giving us
a three.
you can also put actual words in here so for example I could put like
academy in here,
or I could even just put like
a c a d.
and this is going to tell me where this starts
inside of my string so when I click play,
it's going to give me an
a
because
that's where
a cat and he starts right
zero one two three four five six seven
eight
if I put something in here that wasn't in the strings of for example if I put a z in here,
that's not in here.
it's actually going to throw an error so when I play this you'll see that we get this error down here
because
the z is not found inside of our program so
that the next function again can be really useful we'll be using that a lot.
there's also one more than I want to show you which
is called replace
so we can say phrase not replace
and in here I can actually give this
two parameters so I can give this replace function
two values that it can use.
and the first thing I want to you
to give it is what I want to replace so for example I could say
giraffe.
and then I'm going to put a comma in here,
and I want to put in here what I want to replace
draft with so I could just say like
elephant
and now instead of saying draff academy this is going to print out
elephant academy.
so you can see down here it just says elephant academy so
this replace
function
can be
really awesome because we can replace
certain
words or even certain letters
inside of our springs with
other ones.
so those are some basic ways that we can work with strings inside of python
and
there's a lot of these different functions that we can use with strings.
these are some of the most common the ones that I just showed you right now,
but if you just do a google search you can find all sorts of
python functions that you can try out in use and you know,
see what they do,
but you definitely want to get comfortable working with strings and python because you're going to be working with them
a lot.
in this tutorial I wanna talk to you about working with numbers in
python
and numbers are one most
common data types in python and
any python program you write is most likely going to be dealing with numbers at
some point
so
I want to talk to you guys about the basics of using numbers we can talk about the different types of numbers that we can represent in python.
and I also want to show you guys some
awesome functions that we can use with number so we can do a certain like mathematical operations mechanism
awesome things
with numbers I'm going to show you guys
all of that in this video it's gonna be awesome so
first thing we can do is
we can actually just like print out a number.
so if I want to write a number in python it's really easy I basically just write the number so I could say like print
too.
and this is just going to print the number two out onto the screen,
so I can use a whole number like this I could also use a decimal number so I can say like two point
oh nine eight seven
and pythons are gonna be just fine with that we'll be able to print that on
the screen as well.
I can also make numbers
negative so I could make this
two point
oh nine
eight seven
a negative number and
python to be able to handle that just fine too.
in python we can also use
basic arithmetic so I could do things like addition subtraction multiplication
fancy like
three
plus four
and now this is going to print this out or was he like three plus
four point five.
and this will be able to print out the answer so we get seven point five.
and we can do a dish in we can do subtraction.
we can do division
or we could do like multiplication as well so you can
pretty much do whatever you want inside of python,
and if you want to make more complex mathematical equations we can also use
things to specify order of operations
so I could use parentheses.
so for example if I said three times four plus five
what python is gonna do is it's gonna multiply three and four together so it's going to be twelve and then we'll add five to that so we should get seventeen.
but let's say that we wanted to change up the order
right
I could actually put a parentheses around four and five
and now
it's going to add them first social ad foreign fighters will get nine and will multiply that times three so we should end up with twenty seven,
so you can see we can use those parentheses to specify order of operations so I could make like a very complex
little equation here and just by using numbers and parentheses.
we can also
use one other operation which is called the modulates operator so I could say like
ted,
and use this percent sign
three and this is actually read
ten
mod
three
and basically what this is gonna do is it's going to take the first number
divided by the second number,
and it's going to spit out the remainder.
so it's basically going to say
ok
ten divided by three.
that's going to be three
with a remainder of one.
so this is going to give us the remainder.
and
you'll see down here we get one because
that's the remainder of ten divided by three
that modulates operator can come in handy quite a bit.
we can also store these
numbers inside of variables
so we can store them inside of these
variable containers,
so I could
come over here
and I could create a variable called like
my underscored gnome
and we'll just store a value
of let's say like five and here
is why have you come down here and I can just print out my underscore numb.
and we'll be able to print that number out to the screen
just fine.
so in addition to doing things like a basic arithmetic
we can also
do some other stuff so one thing I could do is I could actually convert this number into a string.
so if I wanted to convert this number into a string I can just say s t r
and I can put the number that I want to convert
inside of these parentheses.
and so what's going to happen now is this number is going to be converted
into
a strings when I click
the run button you'll see it's
just printing out five but now instead of being a number this is actually a string.
and this is going to come in handy when you want to print out numbers alongside
strings,
so I can come over here and I can say like
my
favorite number,
and we'll be able to print this
number along with this
string so I click play,
and it's as five my favorite number,
if I was to get rid of this
string
right here
and I wasn't converting the number into a string.
now pythons gonna have a problem with this.
it's not going to allow us to do that you can see we get an
error so
anytime you want to print out a number
next to a string you gotta make sure that you use that little string function.
so
there's a bunch of other stuff that we can do with numbers and
a lot of times in python
you're gonna want to be using specific
metabolic more advanced math operator so
there's a bunch of different math
functions that we can use on our numbers
and a function is basically just like a little collection of code that does something so
a function could perform an operation like a mathematical operation on our number,
we can also give us information about our number,
so I'm sure you guys some of the most common functions that you'll be using in python
related to numbers.
the first one is called
abs
and it stands for absolute value so we can get the absolute value
of
a number.
and so over here I'm going to
make this variable negative five
and basically I can just say
abs
and I can make an
open enclosing parentheses over here,
and this is going to give me the absolute value of
this number up here,
so when I click the play button,
you'll see it's just giving us five because five is the absolute value of negative five,
I can use a few other functions there is another one
which is called
pau at so it says p o w
and I'm actually not going to use this variable we just as a normal number
and
this function is going to allow us to pass it
to pieces of information so I can give this function
two pieces of information.
the first is going to be
like a number.
and the second is going to be the power that I want to take that number two so I could say like three
comma
two
and this is basically just going to be
three
raised to the power of two,
so
it's just going to be three squared so we should get nine down here,
you can see that we do,
so I could pass in like
you know
some crazy number like
we could pass in a four
and we can raise it to the power of six,
and so we should get like a pretty big number here
and you can see we get four thousand ninety six so
this
power function is really useful for taking numbers to specific
powers.
so in addition to using this power function we can also use another function which is called
max.
so I can say max.
and what this is gonna do is it's basically gonna return
the larger of the two numbers that we pass into it
so right now I'm giving this
a four and a six
and this should tell us which number is higher
so over here it's just pulling out six because that's the bigger number.
I cannot see is another function called
men and this is going to do the opposite so now instead of printing out the max number it's going to print out the smallest number.
and it's going to turn out for down here as you can see.
another cool function is called the round function
and this is going to allow us to round a number so it's just going to follow like standard rounding rules.
so if I said like three point to inside of here
now is going around it
down to just normal three
but if I said like three point seven.
it's going to round it up to four so that'll allow you to round a number.
so there's a few other functions that I want to show you guys but in order to
get access to them I'm actually going to have to do something called
importing
and in python we can actually
import
external code
into our files and so if I want to access these
specific
math functions.
I have to import something called python math
so I can just say from
up here math
import
and this star and basically what this is gonna do is it's going to
go out and it's going to grab
a bunch of different math functions that we can use so
I already showed you guys a few of the zipper math functions but there's actually a bunch more.
and in order to access them we're going to need to include this line of code inside of our file.
so once we have that now I can access a few other so
is another function which is called the floor method and it's just
f l o r
and what this will do is it'll basically just grab
the
lowest number so it's essentially just going to chop off this decimal point.
and you can see over here now
we get a three because we're using that floor function.
there's also another one called
seal.
and that's just going to do the exact opposite so that's just going around the number up
no matter what so
no matter what will always get for
which we have a three point whatever here
and there's another one which is called square root so it's just asking you our team
and essentially this is just going to return the square root of a number so I can say like
thirty six.
and now we should get six back.
so
those are also very interesting functions and
inside of this
math module so we would call this a module and you don't have to worry too much about what that is right now,
just know that when we put this line of code into our program
it gives us access to a lot more
math
function so though
it basically allows us to do a lot more things with math
inside of our program
and there's a bunch of different math functions
in python and if you why you can basically just go online and search for different math functions.
I showed you guys a few here and I would say the ones that we looked at here are
probably the most commonly used but there's a bunch more.
and
like I said you know there's
tons of documentation on all this stuff so you can just look up
your math functions in
python and there's going to be tons and tons like lists of these things
that you can use inside of your programs to perform different math
operations,
but for now that has been a little bit of by using numbers a little bit about doing it on certain math operations and using functions
with those numbers
in this tutorial I'm going to show you how to get
input from the user.
so we're basically going to allow a user to
input information into our program.
and I'm actually going to take the information that the user inputs.
I'm gonna store it
inside of a variable and then we're going to be able to do something with
that variable.
so I want to show you guys how we can actually go about getting
input from someone.
and down here in my python file.
all I have to do to get input from someone is I just have to type out
input
and then an open and closed
parentheses.
and what this is basically going to do is it's going to tell python like
hey we want to get
input from
a user in python will
allow the user to
type in some information
and inside of these parentheses we can actually type
a prompt
and so generally when we want the user to enter in some information
we want to tell them what we want them
to enter.
and that's what we can put inside of here so I'm just going to say.
enter your
name,
so we're actually going to create a little python app,
which is going to allow the user to enter in their name
and then will store the name inside of a variable and then we'll basically just
say hi to the user so we'll say like high
and then whatever the name they entered was
so what I want to do is I actually wanna store
whatever the user and put it into our program
inside of a variable.
so I can actually go over here and I can create a variable I could just call it name
and I could set this variable
equal to
input.
so what I'm doing now is I'm taking the value that the user inputs
and I'm
storing it inside of this
variable container called
name
and so now
I have access to whatever they entered it.
so what we can do is we can say
print
and inside of the
parentheses I can just print out
hello
and then I'm just going to add on to this
name
and actually want to put an exclamation point.
so essentially we're getting a name from the user.
restoring it inside of the named variable
and I'm printing it
out onto the screen.
so I'm gonna go ahead and play this ?
and when we run the program you'll notice down here
python is giving us this little problem
so it saying
enter your name.
now
in here I can actually type in of values so I could type in might.
and then I can just hit enter
and pythons going to go ahead and store this value inside of that variable
and then it's going to print out
hello
mike.
and so this is kind of cool and
actually what we could do is we could
prompt the user to enter in more than one piece of information.
so I can actually
copy this line of code.
and I'm an
pasted below here
and why don't we have the user enter in another variable.
so we could have them enter in for example their
age.
and over here we just want to say enter your
age.
so now
we're able to get two pieces of information from the user.
and I could say hello name.
and then I can say
you are
and I'll print out their
age
so I'm going to print
age.
so now I'm basically able to get both of these pieces of information
from the user I can get their name
and I can get their age so when we run this program.
I can type in both of those pieces of information so as they enter your name.
so
we could just
make up a name like john
and then enter the age that say john is twenty five
and now is going to say hello john you are twenty five.
so the program is able to get input from the user and then it's
able to use that information
in order to say hi to the user and
tell them how old they are,
so
getting input from the user is a great way to make your programs more interactive and
here we're just scratching the surface right word just basically getting to know a piece of information from the user but
you can use these inputs to do
awesome things in python and as we go through this course.
you're going to see some
really cool things that we can do
with these inputs
in this tutorial I'm going to show you how to build
a very basic calculator in python.
we're basically going to build a calculator where we'll get to numbers from a user,
and then we'll
add those numbers together and print the answer out onto the screen.
so this will give us some practice in getting input from users and we'll also talk about getting
numbers from users as opposed to just
strings.
so I'm really excited to
get started on this calculator.
the first thing we want to do is
create
two variables and
inside of those variables we want to store
the two numbers that the user wants to add together
so down here,
I'm just going to say,
number one,
and that's what we'll call our first variable
is
equal to.
and now I need to get input from the user so I'm going to say.
input
and inside these parentheses
I'm going to say.
enter a number,
and now I basically want to do the same exact
thing
but for
the second number,
so we'll piece this guy down here,
and I'm just going to say gnome
two
and then we'll just say
enter another number.
so now we're able to store the user's input
inside of these
two
variables.
so now all I want to do is just print out the results so
I'm actually going to create a variable called result somebody's going to say a result
is equal to
and basically we just want to add these two numbers together something as a number one
plus
numb
too.
and now all we have to do is print out the results I'm just going to print
result
so
we basically have our entire program written out here
and this will allow us to enter in two numbers and then we'll add them together and print out the answer
so I could play.
and down here we can enter our number,
so I'm gonna enter the first number we'll say five,
and I'm going to enter my second number so let's say
eight point zero
or else a point
three
it's now should print out the answer,
but
if you look over here.
that's not quite the answer we were looking for at five plus
eight point
three is definitely not fifty eight points three
and here's what happened
when we get input from a user
by default.
python is just going to convert
it into a string,
so it doesn't matter what we put
down their when we're entering the numbers
python's always is going to be like.
ok
this is a string
that's it
sounds good right ?
it's just going to make it a string
in order for us to make these number one and number
two variables numbers,
we're actually going to have to convert the strings that we get from the user
into numbers,
and so
the way that we can do that is by
basically just coming over here
and when we add the two numbers together
I can use a special python function
in order to convert those
strings
into numbers.
and there's actually two
python functions that we could use for this.
the first is called
int
so I could say I auntie.
I can make an
open parentheses and I can make a close parentheses
and basically what this is gonna do is it's going to convert whatever is inside of these
open or close parentheses
into an
integer
number,
and an
integer number is basically a whole number so it's like one two three four or five so it's a,
it's a whole number another word that can't have a decimal point,
so what I could do is I could say
I n t,
and I could put these
inside of
parentheses.
and now what this is gonna do is it's going to convert both of these numbers into
integers in other words
into
whole numbers that don't have decimals,
and it's going to add them together and will print out the result so why don't we do that
we'll just see if this works I'm gonna
click the play button
and down here we'll enter our first number sums can enter into four
and then I'll answer in a five
and now you can see it's printing out the correct answer four plus
five
and so that's essentially our basic calculator.
but we do have one
problem with this calculator salmon run it again and I'll show you guys with that problem is
if I wanted to add in
a decimal number so we'll add four point three and five point five.
you'll see that we're getting this error.
and that's because I'm using this
ain't
function of here and this
int function is looking for a whole number.
so if
I put decimal numbers inside of there it's going to break the programs.
there's another function we can use
instead of an
n we can say float
and a float
is basically just a number that has decimal so it's a decimal number
so I can convert both of these guys into floats
and now I'll be able to use decimal number so I can click play.
and I can just enter into number so I could say like four
and I could also say like five point five.
and now it's going to be able to add
both of those numbers.
even if one of them is a decimal
and that's the beauty of using that little float function so
in certain circumstances you might want the user to only be able to enter into an integer
to a whole number.
but in a lot of cases like in this calculator.
we want them to be able to answer any number that they want so we're going to use this flow
function.
so
I'm just going to recap what we did one more time we created two variables number one and number two
and we basically stored the two numbers that the user's implanted into those variables,
then we converted them into numbers
and
weed
out of them together and we printed out the results so
this is a pretty cool calculator, i'm happy with it.
hopefully you guys learned something.
and as we go forward in this python course you're going to learn all sorts of ways that we can make this calculator more complex
in this tutorial I wanna show you guys how to build a
mad libs game in
python,
so a mad libs game is basically just a game where you can enter in a bunch of random words so like
you know
verbs nouns
names
colors
and
you basically take all of those words and
put them into a story randomly so
over here I had
my web browser I just have
an example of a mad libs so you know
down here were basically just taking random words like an adjective or a noun or a pronoun
and entering them in
sort of a story so like you read through the story than like some random word pops up in
mad libs can be pretty fun and I'm sure