1. Home
  2. Explore
  3. Computer Science
  4. Python Programming Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python Programming Basics

Transcript

In this course, I'm going to teach you everything you need to know to get started programming in Python. Now, 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're trying to write awesome scripts to do a bunch of different things, then 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 it's such an 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 and 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 going to 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 Python? 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 confident and start writing scripts and start writing programs that are awesome and 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 follow along with the course and learn this amazing programming language. In this tutorial, I'm going to show you 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 what we want to do is head over to our web browser. And you want to go over here to this page, it's just www.python.org forward slash downloads. And on this page, there's going to be two buttons down here. And it's just going to say download Python 3.6.3. And at least that's the version that I have right now or download Python 2.7.1.4. So here's the thing about Python, there's actually two major versions of Python that are in use currently. There's Python two, and there's Python three. So you can see over

here, this is like 2.7.1.4. 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 is 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. And so there's pros and cons to picking either one. A lot of people will say like Python two 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 Python two, then you can do in Python three. But

then again, Python two is not supported. And you know, five or 10 years from now, probably no one's going to be using it. Python three, like I said, is like the future of Python. It's the newest version. It's the one that, you know, is 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 the thing, like, if you learn Python three, or you learn Python two, the differences aren't very big. There are a few differences in like some syntax and just some, 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, you know, tell you that you have to learn one or 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 going to go ahead and download this version. And when that's done downloading, I'm just going to head down to my downloads folder. And you'll see here, we just have this file, I'm just going to double click. And we get this like Python installer. So I'm just going to click through here. And we'll be able to install Python three on our computer. All right, when that's done installing, we can just close out of this and we should be good to go. So 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 or 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 notepad or text edit, it doesn't really matter. But there are special text editors that are designed just for writing Python code. And these are called

IDEs. And that stands for integrated development environment. It's basically just a special environment where we can, you know, run and execute our Python code. And it'll, you know, basically, like tell us how we're doing. So if we're, you know, 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 IDE. And one of my favorites, and one of the most popular IDEs for Python is called pie charm. So I'm over here on this website, it's called jetbrains.com forward slash pie charm. And this is the IDE that we're going to be using in this course. So I'm just going to come over here and click this big download now button. And we'll go ahead and download this pie charm program. Alright, so I'm getting this page over here. You can see there's two versions of pie charm. One is a professional version, and that one's like paid,

so you have to pay for it. But then there's this community version down here, and that's free and open source. So I'm just going to download this one. And this should have everything we need to get started using Python. Alright, 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. Alright, so we now have pie charm. And we have Python three installed on our computer. So we're ready to start programming in Python. And 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 pie charm. So pie charm was the IDE, the integrated development environment that we downloaded in the last tutorial. So I'm just going to go ahead and search for it on my computer. And I can just open it up. And when we

first open up pie 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 going to go ahead and give this a theme. So I just went over here to appearance and behavior, appearance. And I'm going to change the theme to dark. Just 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 to. And so down here, I'm just going to click create new project. 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 draft. And then there's this other option down here where it says interpreter. Now, what we want to 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 want to 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 I'm just going to come down here and click create. And this is going to go ahead and create our project for us. All right, so now we have our Python project up and running. And I want to show 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 going to say 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 I'm just going to click

okay. 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 just a very basic Python program. And this is just going to be a hello world program. So we're just going to print something out onto the screen. So what I want to do is I want to type out PRINT print. And I want to type in open and closed parentheses. Now inside of this parentheses, we can make some quotation marks. And inside of the quotation marks, I'm just going to type out hello world. So this is like a very basic Python program. And what this is going to 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 error 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 just going to click run. And we'll

click this run button right here. And now we'll see what happens. So it's asking me what I want to run. I can just click app. And down here at the bottom, you'll notice that we have this text that just got printed out hello world. And so whatever I print, or whatever I put inside of this print statement is going to get printed out down below in the console. So as long as you're getting that print statement to work, then you've actually written your first Python program. And as we go through forward in the course, we're going to be writing all sorts of awesome Python programs. And we're going to be doing all sorts of cool stuff.

In this tutorial, I want to talk to you about writing a basic Python program. So we're going to write just a very simple Python program. We're going to look at how we can go ahead and write our 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 to 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 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 out. So I want to 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 print statements. 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 going to copy this and I'm actually going to make a few of these little print statements. And we're going to actually draw a shape. So we're going to draw like a triangle type shape. So down here, I'm just going to draw a forward slash. And then up here, I'll make a space and we'll do another forward slash.

Here, we'll make two spaces, we'll do another forward slash. And over here, we're going to make three spaces and a forward slash. And now I'm going to draw like vertical bars going all the way down. And actually, we can do some underscores here as well. That'd be kind of cool. All right, so now we have our triangle looking shape 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 if you're using PyCharm, 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 console. And basically, the console is just a place where Python is going to output some information. So when we use this print statement, we're basically telling Python like, Hey, can you print something out onto the console? So there's a lot of situations where we're going to want to see what's going on in our code. And we can use that print statement and print things out to the console. And we can basically like have a little window into what our program is doing. In our case, we're just going to be printing out this triangle onto the console. So I'm going to 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 could really draw any shape I wanted as long as I was able to specify it 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, okay, they want me to draw out these like little forward slash in this vertical bar onto the screen. Once it does that, it goes down to this instruction, it says, okay, they want me to print something out again. When it prints that 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 out 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, it just prints something out onto the screen. There's a bunch of little things like this that we can learn as we go through, we'll learn more and more instructions that we can give to the computer. But in this lesson, I just want to kind of show you guys the basics, right? We can essentially just define these little instructions for the computer, and the computer will execute them in order. In this tutorial, I want to talk to you guys about using variables in Python. Now in Python, you're going to be dealing with a lot of data. 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 in master. So in this tutorial, I'm going to teach 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. But 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 70 years old. He really liked the name George, but didn't like being 70. So this is a valid Python program. I could go ahead and run this program.

And you'll see down here in the console, everything prints out and it looks great. So we have an awesome little Python program here. But 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 John. 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 going to have to go over here and I'll say, okay, John, I'm going to have to manually change that. And then, okay, down here, we're gonna have 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, okay, maybe we want to change the character's name age also. So in addition to changing the name, we also want to change the age, let's make

them a little bit younger. So why don't we say John is going to be 35. And so you'll 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 the character's name and age, like hundreds of times. I mean, I'd 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 and the age. And so we can actually use a variable in order to store the character's name

and the character's 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 going to show you guys how we can create a variable for the character's name and age. And I'm just 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. And 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. And I'm going to say underscore name. And 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 variable. So basically, what I can do is I can just say equals, and over here, I can type a value. So I'm just going to type out the character's name inside of quotation marks. So we're just going to type out john. So now we have a variable for the character's name. And below this character name variable, I want to create another variable called character age. So we're just going to type out character underscore age. And I'm going to set this equal to the character's age, which is 35.

So we now have two variables, one representing the character's name and one representing the character's age. So what I can do now is I can replace the character's name inside of the story with this variable. And I'm going to 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 at 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 text over here at the end. So I'm going to have to put a quotation mark here. So now I have a bunch of text here in quotation marks. And then I also have text 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 am saying I want to print out all of this text, plus the value that's stored inside of character name, plus all of this text. And what this will do is actually print out the character's name. We print this. So I'm going to 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, okay, they want to print out the value inside of character name. So it Python is 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, I'll just copy this guy right here. And I can just paste it down here where the character's name is.

So I'll paste this. And you can see now we're doing exactly the same thing that we did up there. I can also do this for the character's age. So I'm going 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, we'll change it to character age. And I'm going to do this in one more spot. So we're going to do this over here where we're mentioning the age. And again, I'll just change this to character age. And so now when I run this program, it's going to print out the same story that we were printing out before. But now I don't actually have to type in the character's name and the character's age. I can just refer to this variable. And the cool thing about variables is 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 character's name to like Tom or something. And we could also change their age. So I could change the age to be like 50.

And now that's going to automatically update throughout our entire story. So when I click this play button, you'll see now we're using the name Tom. And he's 50 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. Well, I 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 could say like character underscore name. And in order to give it a different value, all I have to do is just say equals, and we'll give it a different value. So let's say halfway through the story, we want to change the character's name to Mike. Well, now when I run on 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. 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 the character age. And I'm actually storing what are called strings. So a string is basically just plain text, right? 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, or you 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 in addition to storing text, we can also store numbers. So if I wanted to store a number, for example, let's say we want to store the character age instead of inside of a string, we could store it inside of a number. So I could just type out 50. 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 want to store a number, I can just write it out like this. And in addition to using whole numbers, I could also use decimal numbers. So I could say like 50.5678213. And Python's going to be able to store that number as well. So 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 a 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 could have a variable called like is mail. And

this would tell me whether or not someone was a male. And in my case, it would 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. 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 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 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 99% of the time as a new

user and 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, I want to talk to you guys about working with strings in Python. Now one of 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 want to 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 string. So 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 of the quotation mark, I can put whatever text I want the string to have. So we could say like, draft Academy. And so now we have a string with the text draft Academy inside of it. So if I run my program, now down here, we're going to print out draft 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 want it, I can come over here, and I could say backslash n. And you can see it got highlighted in a different color. And what this is going to do is it's actually going to insert a new line into the string. So now it's going to say draft on one line and Academy on another line. So I'm going to click play. And you'll see down here, we just get draft Academy. In addition to the backslash n, I could also use a backslash quotation mark. So if I wanted to put a quotation mark inside of my string, I can't just put a quotation mark like that, because Python is going to think that I'm trying to end this string. 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 literally. So when I say backslash quotation mark, it basically means

like, Hey, Python, I want to print 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 a backslash. So if I needed to print out a backslash, I could say backslash. And it'll just print out a normal backslash now. So you can see just like that. So if you want, you can use that backslash to make new lines or print out 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 we'll just call it phrase. And I'm going to set it equal to draft academy. 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 draft 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 special things 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. And we can also use functions to get information about our strings. So I'm going to show you guys a couple common functions we can use with these 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

going to show you guys a function that we can use to convert this string entirely into lower case. 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'll convert it to lowercase. So you can see now we just have draft academy down here, but it's entirely in lowercase. I could also do the same thing for uppercase. So I could say phrase dot upper. And this will convert the entire string into uppercase. You can see now it's entirely uppercase. So in addition to converting the string into uppercase and lowercase, I could also check to see if a string is entirely uppercase or entirely lowercase. So for example, I could say phrase dot is upper. And this is going to give me back a true or a false value. So it's going to be true. If the string is entirely uppercase, or false, if it's not. And you can see here, we're getting a false value because this is an

uppercase. I can also use these functions in combination with each other. So for example, I could say phrase dot upper, and then parentheses. And then after this, I could 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 uppercase. 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 uppercase.

So you can see now we're getting a true value. So you can use 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 LEN. And I'm actually going to make an open parentheses. And I'm going to make a closed parentheses. So I'm essentially saying LEN. And this is another function, it's the length function. And inside of this LEN function, I'm actually passing this phrase variable, I'm basically giving the length function this, and it's going to spit out a number. So it'll tell me how many characters are inside of this string. And so you can see here we get 15 because there's 15 characters inside of draft academy. So that's how we can get the length of a string. And that's going to be really useful as we go forward and 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 this string is, we can actually use an open and closed square bracket, just like that. And in here, I can specify the index of the character that I want to grab. So if I wanted to grab the first character in this 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. And that's because in Python, when we use indexes on a string, we start with zero. So if Python is counting the characters, or it's indexing the characters in a string, it's going to start with zero. So it's

going to say G is zero, i is one, r is two, a is three. So we would say that G is at position zero in the string, i is at position one, r is at position two, a is 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 a, I'm going to have

to put zero 123. So if I put three inside of here, now we'll 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 going to be using that a lot as we go forward in Python, there's 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 string. So I could say 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 a 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 could say inside of here capital G. And now this is going to return the index of the capital 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 an a inside of here, like a lowercase a, it should give me 0123, because that's where the first a 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 eight because that's where Academy starts right 012345678. If I put something in here that wasn't in the string, so 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 Z is not found inside of our program. So that index function, again, can be really useful. And we'll be using that a lot. There's also one more that I want to show you, which is called replace. So we can say phrase dot replace. And in here, I can actually give this to parameters. So I can give this replace function to 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 draft.

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 draft 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 strings with other ones. So those are just 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 and use and you know, see what they do. But you definitely want to get comfortable working with strings in Python, because you're going to be working with them a lot. In this tutorial, I want to talk to you about

working with numbers in Python. Numbers are one of the 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 just the basics of using numbers, we're going to 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 numbers. So we can do certain like mathematical operations, we can do some awesome things with numbers. I'm going to show you guys all of that in this video, it's going to 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 two. 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 could say like

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent