Intro to Python Basics | Storay Amiri | Skillshare
Search

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Intro to Python Basics

teacher avatar Storay Amiri

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Intro to the course

      1:27

    • 2.

      Lesson 0 Installing python

      3:36

    • 3.

      Lesson 1 Strings

      8:49

    • 4.

      Lesson 2 Numerics

      7:31

    • 5.

      Lesson 3 Variables

      6:08

    • 6.

      Lesson 4 Interactive

      7:14

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

1

Student

--

Projects

About This Class

An introductory course to python. This course introduces the core concepts in python to get you started in creating your own python scripts. It will show you the basics and provide you with the information necessary and empower you to teach yourself. By the end of this course, you should be creating your own python scripts.

Meet Your Teacher

Teacher Profile Image

Storay Amiri

Teacher
Level: Beginner

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Intro to the course: Hi, everyone. I'm Storey, and I'm a researcher who's used Python for a number of years and I'm mainly use it to analyze scientific data from my experiments. In this course, I'll guide you through the basics of Python so you can confidently start your own coding journey. Now, why Python, Python is one of the most widely used programming languages today in fields like data science, web development, and whatnot. Learning Python opens up a world of possibilities. Now, what will you learn in the course? So we'll start with the very basics. We'll start with how to install Python and then we'll move on to things like strings and numerics and then variables. Then we will also apply what we've learned, build an interactive Python script, and that will be the project. So in the class project, you'll create a simple but powerful Python script that takes input from a user and uses that input to perform actions, just like real world programs do. Now, who is this course for? This course is designed for complete beginners. You don't need any prior coding, knowledge or experience, just a computer and an Internet connection, and we can start installing Python and getting started. So by the end of this course, you won't know everything about Python, but you will have the confidence to keep learning on your own and build things that matter to you and your work. So having said all of that, let's get started and see you in the first lesson. 2. Lesson 0 Installing python: Hello, everyone, and welcome to this course. This is a follow on introduction into Python basics. This is where we will learn the cool concepts to get started in Python. By the end of the course, you should be able to write your own scripts and hopefully very creative in writing script. Now I understand why everyone will say Python is a very popular language and it's a great place to start even if you're interested in programming in general. Let's get started. Now, to download Python, you just come to the Python official website, python.org, you come it to Downloads and you download Python 3.8 0.5. Now, the numbers don't really matter because as it gets updated, the numbers will change. You just click here, you download it, pretty straightforward. But I personally like using a code editor, which is Visual Studio code. This is my preference. I don't want to go into too much detail about why I use this and why not any other. But basically, this is a code editor. It's where you will write the code and where you will run and execute it. It also has other advantages if you make a mistake it catches there for debugging and all this. Like I said, this is a personal preference, so you can go and do your own research regarding this, or you can just download this one with me. So you come over here and you pick your own software, the computer that you have, and you download it. Like I said, this is also very straightforward. Okay. So once you've installed Visual Studio Code, this is the page that you will see. You click on here Extensions. You can search extension, for example, Python. I've already installed so comes up for me. But you click on the Python, the one with the star because this is the official Python. You come over here and you have installed. I've already got installed. So for me, I say it's uninstalled, but hopefully for you, there should be an option to click on Install. So to get started, you can click on file and you make a new folder. Now we're going to write our own very first code. We're going to write print brackets. Speech marks, hello world. Now, hello world is really standard. Everybody just starts with hello world and you write in brackets and speech marks, print, no capitals with the P print. Now, before you run it we have to save it, which is what this srt is about. We come over here, we save as. Lesson zero. Yeah, I've already got it, but now I do want to point out every time you send a file to use under Python extension, you do want to put dot PY because that's how you recognize it, and then you save it. But obviously, man system will just replace that. This is your first code. Now to run this, we just click on Run over here and Hello world. That's it. That your first code. Every time you make a change here, you click on Run. Hello world. There we go. Congratulations, everyone. We just wrote our first guide. June in my next lesson, as we go into more detail. Thank you. 3. Lesson 1 Strings: Hello, everyone, and welcome back to the course. This is our first official lesson in Python and we're going to be talking about data types and more specifically strings. Basically, string is a set of characters. This can be letters, numbers, punctuation. It's text. I'm going to write my first string here. If you guys, sorry, that's the terminal. That's where the code will show once we've run it. Print bracket, speech marks. Welcome to this course. Welcome to the scores. Let's make a bit longer. This is lesson one. If I run this code, it should show up here. Yeah, just make it bigger. Welcome to the scores. This is Lesson one. Now, if we want to do this and the second line, for example, we want the second part and the next line, what we can do is we can end this, start a new line, print and we'll just take this out because we already have it here and we can run it. Now, silly mistake. Welcome to the schools. This is Lesson one. Now, there is a simpler way to do this. For example, let me just copy and paste this. The easier way really is we can add it here. Once we add it here to start a new line, we can do backslash N let's run this and there we go. Welcome to the squares, this is lesson one. Now there is this space that we don't need. If we run this again without the space, there we go. Welcome to the squares, this is lesson one. Now, we've just performed a function on this string. I also want you to know that this backslash is a very special character, it's called an escape character. Anything you put after this will be taken quite literally. For example, if you want to put speech marks in our text, of course, we use speech marks for a very specific purpose in Python, which is to show the beginning and end of a string. If you put it here, it assumes that this string has ended here, and we don't want that. What we do is we put backslash before it, and there we go. When we print this, here it is. The speech mark just prints itself. These are just some basic functions. Of course, we can also just print a backslash itself and here it is. These are some basic functions. There are some other functions we can also do in string to make life just a lot more easier. For example, let me just take this out. Let me clay my terminal. I'm doing Control Shift P and terminal clay. Now I've recently used this, so it shows up for me, but this is clayed. Okay. So if you want to make this all, for example, upper Kase, what we can do is we do string dot upper and you start another brake and finish this brake. String upper and then in brackets, we just write the string that we want and it should hopefully turn this who, it's capitalized the whole string. We can also obviously do lower if there's er, there must be a lower. Welcome to scours. This isn't exactly obvious. Let me just capitalize this so it's more clear, for example. This is now lowercase. There's some other things we can also do. For example, we can ask Python question, for example, is this string upper? We can do that by string, not lower. We can write is upper. That's a question we're asking. And answer comes false because the whole string is not upper. There is a lot of it in lowercase and we can also do is this lower lower. Another question we ask, can we run this, and we get another false because there is per case in this string. That's also another function you can use. There's lots of functions that you can use, but I'm just showing you some of the basics that you need to know to get started. Something else we can do is we can check what the length of the string is. The length, and then we run it. 40 characters. The length of this whole string is 40 characters. If we are specifically looking for a specific character, we can also do I can write a number in here. For example, we want the fifth character in the string, five and we run it. M. Now, some of you paying close attention might say that that's wrong. You might be right. For example, one, two, three, four, five, five is clearly, O. But I do want to point out that in programming in general, we start our count with zero, zero, one, two, three, four, one, two, three, four, five, five is. Exactly, six, seven, eight, that's how it would go. We can do another one, for example, 31. If we do that because of course, this number doesn't work because that's not exactly code. But if we do just want to make notation in here, we can just do a hash. And it should have no problem. Now you might have realized there's nothing here. We've obviously clearly asked for the character 31 and there's nothing here, but that's probably because it's space. For example, if I do 30 and I run this, that's S. It's either thisS or thisS and the one after this is space. That's where 31 comes as blank. I don't realize that space is also a character. We can also ask for index. That would be dot index. This is where we're passing it through a parameter, we write a specific letter here. For example, I want the letter O. I put it again in speech marks O and I finish the bracket off. O is four. O is character four, and there we go. That's where we get four from. Another function we can use is replace, for example. We can use the word replace and in here we don't write just one thing, we write the old and the new that we want to replace it with. For example, I want to change course to module. I would have to not dot speech marks, speech marks, and comma. If I take this away and I run this, Welcome to this module. This is Lesson one. Obviously, we replaced course with motle. These are just some of the main functions that I want to talk to you about in string that we use. There are a lot more functions that you can use that you can just simply Google and it's not that you have to memorize or know most of these functions. Whenever you need them, you can always just Google them there's lots of resources out there. Thank you for watching and I hope this has been useful. 4. Lesson 2 Numerics: Hello, everyone, and welcome back to this course. In the last lesson, we learned about strings, which is a data type that consists of a set of characters. In this lesson, we will be learning about another data type which is numbers or numerics. So this is a string that we talked about in last lesson and some of you might have realized that there is a number here, but this is still a string data type and not the number or numeric data type. Now, that's because Python treats this number as a character as another, for example, letter rather than a number. Now, I'll show you what I mean by this. If I take all of this away and I do three plus one and I print this or run this. I will give me just three plus one. I will type everything out or print everything out literally. That's because it sees as a string. How do we know this is seen as a string? It's because there's speech marks around it. If I take the speech marks away, then Python will now see this as a number or numeric datatype. When I run this, it will not give me three plus one, but it will rather treat it as numbers and it will add the two. Three plus one is four. Now that's a function of numbers. You can do simple arithmetic exercises in here. For example, 43 plus one times four. Now, three plus one is four, four times four, 16. We should expect to see 16. But we don't, we see seven. That's because Python follows bid mass. Anyone who has some background in math might know what. This is the order of operations. If you give it in arithmetic sentences, it will go through these functions. That's why it multiplied these two because multiplication comes before addition so four times one times four is four plus three addition afterwards is seven. But if I do want to see 16, I can put a bracket around this because brackets is before multiplication and that would do three plus one is four and four times four, which is 16. And there is 16. That's one of the functions I wanted to talk about. Another function I would want to focus on is mod. For example, we can do ten percentage. Four. This percentage sign is called the mod sign. What it will do is it will tell you what the remainder will be if ten is divided by four. 10/4 will give us two with the remainder two. Let me just take this away and I'll run this. And we saw two. If I change this four to five, 10/5, will just give us two with no remainders, we should see a zero because there are zero remainders and there it is. This is another function. Another very simple function that we can use is the power function. For example, we can write power and then we do three to the power of two, three comma two will be read as three to the power of two, and when we run this, it should give us nine because three times three is nine, and we can certainly do really long ones, for example, three to the power of 42. If we run this, it should give us a really big number, and here it is. Let me just take this way and this is the really big number. This is another function that we can use. Another simple one is called MAX. Max will give us the biggest number in a list. Now we only have two numbers, so let me just make this longer. I will add 31, 56, 78, 91, and one. I would ask you to give me the biggest number, the max. If I run this, it would give me 91, which is the biggest number. Similarly, I can do men, which will give me the smallest number and that would be one. Now, the thing with this is it can be really easy to see right now where the biggest and smallest number number is. But in a long list of numbers or large amounts of data, this can be very useful. Another very simple function is rounding another swell right round and I'll give it a number, for example, 3.3 and this will be rounded down to three or 3.9 will be rounded up to four. Now these are some of the basic functions that are available in Python. I want to show you some other functions as well, but they're not available in Python itself, so we have to import something called a module. Now let me just clean my terminal fas because it's really busy. To import a module, I will have to write down from math Import star. When I write this down, it will not to import the module mass which is readily accessible and available. There's lots of functions in this module that we can use. One of the is, for example, square root. If I write the square root, for example, of nine, it should give me three. Now, without this module, this will not work. For example, let me take this away and let me run this without it. Square root is not defined. We will see an error message because this does not exist in Python itself and we will have to import some other functions from math to be able to use this. That's why we input this module. Something else we can use another function that's available here is, for example, floor. Now, if we even write 9.9, it will round it down to the lowest number, which is nine. If I round it, it will give us nine. Now, if there is floor, there is ceiling and even if I have 9.1, if I run this, it will give me ten because it will go to the highest number. These are some of the basic functions that I wanted to talk about. There are a lot of other functions available and a lot of other modules that you can use. But there's just an introduction to show you how to import modules and how to use them and to introduce you to modules itself. You are able to import your own modules and learn functions yourself. I hope this has been useful. Thank you for watching. I'll see you in my next lesson. 5. Lesson 3 Variables: Hello, everyone, and welcome back to the course. In this lesson, we'll be focusing on variables. Now, before I explain what a variable is, I would like you to focus on these three lines, this short story that I've written. Brenda really likes cookies. Brenda stole five cookies from her brother. Brenda's brother now has five less cookies. Now if I want to change the name Brenda in here, I can easily just come over here and replace it with Kate and I can come down here. I can similarly replace this with Kate and not Brenda's brother, but Kate's brother. That was fairly easy to do. However, if this was a really long story or a really light set of data, this could take me hours to do. This is where variables come in. No, variables can hold a piece of data and story, and you can change it easily. I'll show you here, for example. I can make a variable called name. This is a variable and I want to equal this variable, what I want to store in this variable is the string called Kate or just for the sake of there actually to be a change and I'll change it back to Brenda. Every time I come down here, I don't have to write Kate itself, I can just write the variable. I'll come over here. I'll write the variable name. Now I can do the same down here and write name. And even not Kate's brother, I can just go over here. Now, I don't want to take the S and apostrophe away because that's not stored in the variable. I can write name here. And there you go. Every time there is a name, that would be replaced with Brenda Brenda Brenda. Now let me just run this. Brenda Brenda. With Kate and Stoll there's no space. I can just make space here, Brenda's brother. Brenda's brother now has five less cookies. It seems to have worked fairly well. Now, I can make another variable here as well. I can do Cookie amount, and I can equal that to five. So I can change this, finish this off. I can add, not a space because space wouldn't work. It has to be one word, cookie amount. Cookie amount, and I'll finish this off the only string here is stow and cookies from her brother. There is a variable here and a variable here. Now I can also use this variable. And use it here, I can finish this off here and over here as well. I'll replace the five with the variable. Okay. Let me just do this and let me run this not five, but six just so you can see the change. Brenda R likes cookies, Brenda stroll, six cookies. Again, I need to make space. Brenda's Brother has six less the the space. And space. Let me print this. Brenda really likes cookie, Brenda stole six cookies from her brother, Brenda's brother now has six less cookies. That's fairly easily done. I can change Brenda into ate whenever I want and six to whatever number I want. If it's a really long story, a large set of data, this makes life a lot easier and it makes dealing with the data a lot easier to work with. This is how variables can be useful. Now, some of you might have realized that this number, I've treated it as a string. I've put it in speech marks. What I can do, if I take this away, and just write six. Let me just clear my terminal first so you can see the difference. I run this. I will show me an errant message. That's because you can't put strings and numbers or numeric data types together in one line. I have a string here and then I'm adding a number here because this is storing an integer and I can't put them together. But what I can do is I can leave this as a number, but I can temporarily change this into a string. For example, I can do string string cookie amount, and I can change that here as well. So what this means that even though this is a number and it's a numeric data, it is only temporarily just for the sake of this one line being changed to a string and in this line it's being temporarily changed to a string. If I print this, there should be no mistakes. There we go. I've printed it twice. Brenda real have cookies, Brenda stole six cookies from her brother, Brenda's brother now has six less cookies. This was a basic introduction into what variables are and how we can incorporate numbers and strings together just by temporarily changing a number into a string. I hope this has been useful. 6. Lesson 4 Interactive: Hello, everyone, and welcome back to this course. In this lesson, we're going to be taking what we've learned a step further and we're going to create something interactive where we're going to ask the user for some data or information and we're going to use that data to respond to them. To ask them for something, it's called an input. Brackets, speech marks, and what we're going to ask them is say, what is your name? Okay. Now, the data they give us or the information they name that they give us, it has to be stored in a variable to make a variable, we write over here equals and what we're going to call the variable is name. Because we are asking them for their name so I guess it would make sense. Now we're going to respond to them. We're going to say print hello. Hello, and whatever the name is. To incorporate that variable of their name, we've learned in the previous lesson, it's add and then the name or add then the variable. Now, let's run this. What is your name? Say Kate. Hello, Kate. It works. Pretty straightforward. But I don't like how these are together, like we've previously learned, backslash N and let's run this. What is your name? Now it's asking me in the next line. The cursor moves to the next line, and it's asking me what my name is. Let's try Brenda this time. Hello, Brenda. It's much neater. Let me just clear everything. This was something simple, asking them for their name. This time we're going to try asking them for numbers. Let's print first, what the purpose of this is. Print. We are going to add your two favorite numbers together, for example. Numbers. We're going to tell them this initially and then we're going to ask them for their two numbers. It's not going to be called name, but rather number one. What is your first favorite there we go. What is your first favorite number? Now let's just copy and paste this. Next line. To. This can be number two. What is your second favorite number? So far so good. Now we're going to print them. The result is we're going to include the two variables here, number one, add number two. Let's run this. We're going to add to two favoritenumbers. What is your first favorite number? Say three. The equals. What is your second favorite number? Five. The result is 35. Now that's not what we're expecting. We're expecting those two to be added together. But the thing to note is that every input that we take in by default, it's considered a string. What we've written here is really simply two different strings being put next to each other. The three and the five are just written next to each other. What we have to do here is make sure that this is treated as an integer as a number, and we're going to use an integer. An integer is any whole number. I'm going to tell them to treat this as an integer. We've done this before we are changing a number into a string. This should not be a new concept. This time we're just doing the opposite, we're a string into a number. Let's see if this works. What is your first favorite number? I'm going to write three, second favorite number five. Okay. Now we see an error message here and some of you might have realized it's because we've put a string next to an integer. Last, we're learning how to change a string into an integer or an integer into a string. I was simply because we can't put numbers and strings together, so we've done the same mistake here. To avoid this, we can do is copy this out, take it away from it, and we can make another variable here. Let's call that result and we'll equal it. To the addition of these two, we're first going to convert the string into an integer and this string into an integer and then we're going to add them. This will give us the result. Now, this result is an integer simply because these draw integers, two integers make an integer to incorporate that result here, we can't incorporate an integer, we have to convert this into a string first, and then we're going to result. Let's see if this Let me clear this up. The terminal. Now let's run this. We're going to add you two favorite numbers. Where's your first favorite number? Say three. Second, five. There we go. It worked. But let's try something else. Let's run this again and I want to try something different. Your first favorite number, I'm going to write 3.5. Your second favoritenumber, 2.1. And we see error message. This is because we've used integer. Integer, by definition, is a whole number, so it will not accept decimals when we've added the decimal, so we've just confused it. There is another number data type. Remember we talked about number data types. Now the sub type is integer and floats. We can change this into a float and that will take in decimals. If we just change this to a float and let me just clear this again. Let me just run this whole thing. Where's your first favorite number 3.5? Where's your second favorite number 2.1. The result is 5.6. This works. I hope this has been fascinating, even though all we did is add two numbers together. But there was quite a lot of steps that we had to go through and those were important to know what data type to use and when to use and the fact that all inputs are strings initially. I would also really like to urge everyone to make something like this, something interactive. All I did was ask for two numbers and add them together, but I'm hoping everyone out there can be a bit more creative and share it with us. Thank you for watching and I hope this has been useful.