Intro to Python Livestream - Python Basics with Sam

Brief Summary

This YouTube live stream is a beginner-friendly Python tutorial. The instructor, Sam, guides viewers through setting up Python, understanding basic variable types (integers, floats, strings, booleans), and utilizing built-in functions. The session covers essential concepts such as:

  • Installing Python and understanding the IDLE shell.
  • Differentiating between variable types and their uses.
  • Using built-in functions like dir, help, type, and print.
  • Understanding loops (for loop) and the range function for repeatability.
  • Working with strings, including slicing and concatenation.
  • Creating and utilizing custom functions.
  • Implementing conditional statements (if, elif, else) for decision-making.
  • Introduction to comparison operators and boolean logic.

Installing Python and Understanding the Basics

The tutorial starts with installing Python from python.org, specifically version 3.8.1. It emphasizes that Python is a high-level language with a strong community. The instructor introduces the Python shell (IDLE) as the primary tool for the session, highlighting that an editor is not immediately necessary.

Understanding Variables and Data Types

The session covers four basic variable types in Python: integers, floats, strings, and booleans. An integer is a whole number, a float is a number with a decimal, a string is a sequence of characters enclosed in quotation marks, and a boolean is a binary value (True or False). The instructor explains how computers use these variables for repeatability and storing information.

Built-in Functions: dir, help, and type

Python has built-in functions that provide information about variables and their associated methods. The dir function lists the methods and attributes available for a variable type. The help function provides detailed documentation and descriptions for these methods. The type function identifies the data type of a variable.

Strings: Definition, Rules, and Basic Operations

Strings are defined as anything enclosed in quotation marks. The instructor recommends using double quotation marks for beginners. The session covers printing strings using the print function and demonstrates how to correct common syntax errors, such as forgetting to close quotation marks or parentheses.

Scripts: Writing and Running Python Code

To write repeatable code, the instructor introduces Python scripts. These are created by opening a new file in IDLE, writing the code, and saving the file with a .py extension. Running the script executes the code, and the output is displayed in the shell. The instructor notes that running a script restarts the shell, clearing all previous memory.

Loops: Repeating Actions with for and range

Loops are used to repeat a block of code multiple times. The session focuses on the for loop, which iterates over a sequence. The range function generates a sequence of numbers, which can be used to control the number of iterations. The instructor explains the syntax of the for loop, including the header (keyword for, temporary variable, keyword in, iterable, and colon) and the body (indented block of code to be executed).

Lists: Basic Containers for Storing Data

Lists are basic containers used to store multiple items in a single variable. They are created using square brackets []. The session demonstrates how to create a list using the list() function and the range() function. The instructor also covers the rules for naming variables: they cannot contain special characters, start with a number, or be a keyword.

Slicing: Accessing Parts of Strings

Slicing is a technique used to extract parts of a string. It uses square brackets [] with a start, stop, and step, similar to the range function. The instructor explains how to use slicing to extract substrings, reverse a string, and skip characters.

Concatenation: Combining Strings

Concatenation is the process of combining two or more strings into a single string. The + operator is used to concatenate strings. The session demonstrates how to concatenate strings and variables to create new strings.

Functions: Creating Reusable Blocks of Code

Functions are reusable blocks of code that perform a specific task. The def keyword is used to define a function. The session covers the syntax of a function, including the header (keyword def, function name, parentheses, and colon) and the body (indented block of code to be executed). The instructor explains how to call a function and pass arguments to it.

Input: Getting User Input

The input() function is used to get input from the user. The function displays a prompt to the user and returns the input as a string. The session demonstrates how to use the input() function to get the user's name and then print a greeting.

Conditional Statements: Making Decisions with if, elif, and else

Conditional statements are used to execute different blocks of code based on certain conditions. The if statement executes a block of code if a condition is true. The elif statement (else if) executes a block of code if the previous condition is false and the current condition is true. The else statement executes a block of code if all previous conditions are false. The session demonstrates how to use conditional statements to check if a number is even or odd, positive, negative, or zero.

Comparison Operators and Boolean Logic

Comparison operators are used to compare two values. The == operator checks if two values are equal. The != operator checks if two values are not equal. The > operator checks if one value is greater than another. The < operator checks if one value is less than another. The >= operator checks if one value is greater than or equal to another. The <= operator checks if one value is less than or equal to another. Comparison operators return a boolean value (True or False).

Return Statements: Returning Values from Functions

The return statement is used to return a value from a function. When a return statement is executed, the function stops executing and returns the specified value. The session demonstrates how to use the return statement to return a boolean value indicating whether a number is even or odd.

Nested Loops: Creating Patterns

Nested loops are loops inside other loops. They are used to create patterns and perform more complex iterations. The session demonstrates how to use nested loops to create a square pattern of numbers. The instructor also introduces the end parameter of the print() function, which is used to suppress the new line character and print multiple values on the same line.

Summarize any YouTube video in seconds

Get summaries like this one for any video, in your language, with the free Summ app.

Download on the Apple Store
Get it on Google Play

Transcript

Full transcript of “Intro to Python Livestream - Python Basics with Sam”. Click a timestamp to open the video at that moment. Need another video? Use the YouTube transcript generator.

0:15 well hi everybody uh this is sam with python basics and i just want to welcome you all to a first of mini python tutorial live stream so we're going to do two hours today so locally for me it's 9 and it's 10 eastern and we're going to go for 2 hours so the idea of this is this is for a complete beginner so we're actually just gonna act like we don't even have python on our computer so we need to go to python.org look up here at downloads and as you see right here you can download 3.8.1

1:01 when we look at mine i have three uh excuse me three eight three i have three eight one so you come down here you click this save and it's going to install down here in the bottom corner i got mine kind of zoomed in a little bit and then we'll go ahead and open this up but if you're new to python um it is a very high level language and i'm sure you guys have already seen in the comments that uh python's slow and things like this but one of the things that i love about it that i believe makes it such a very powerful language is the amount of contributors and the

1:47 community and as many people that are involved because it actually started out as a community language so all right um you can just hit uh right now it's gonna ask me but you hit the uh install right here and now there's gonna be a check box down here in the bottom and it's to install the path i recommend go ahead and do that right now but let's just assume that you guys already have that do i want to cancel this so now this is the shell and you might hear me also call this idle and uh just so it's what the integrated development environment idle you might have an editor but right now

2:33 everything that we're going to be doing today and for a while you are not going to need an editor all that you're going uh all that you're gonna need is um the shell so let's just go ahead and jump into it so in python there are four types of variables you have integers floats um strings and bullions so let's just let's just go ahead and get started so and like i was saying my name is sam and then a float is anything with a decimal

3:21 and let's see true so you got you got your integer you got your string you got your float and you have your boolean so now now we need to kind of understand what these do so what what computers are awesome at is repeatability and remembering things so right here we're storing things in memory so we don't have to remember any of this now let's go ahead and look at some of the very powerful things

4:07 that python already has for us these are the methods that are associated with this type variable and we can look at this so now one like i said python is very powerful because of the community so now there are built-in functions already defined for us so i used dur right here pretty quickly and didn't really explain it so these are the methods and we're going to look at this in just a few minutes but then also these are things you can do with this type of variable so name right

4:56 now my name is a string and you can tell that it's a string because it lives inside these quotation marks and basically the way that i like to explain it to be to beginners is is if it's not a number it's a string so basically and then you have your variation of boolean and binary so booleans are binary we're going to learn about conditions and tests and things like that and that's the way a computer can either tell it's either yes or no true or false and we'll delve into that so what the way that we're gonna do things today and for the next uh few weeks is we're going to go forward and we're going to go backwards so we're going to be exposed to something then we're going

5:43 to move on then we're going to come back and we're going to dig deeper so we're just going to move back and forth and back and forth so all right so now to prove that python and i know what we're talking about str so python says okay i know that name is a string and you want to know that it is a string so here we go now what things so we have our x so we do type x int then type y we have a float and then type true we have a boolean so

6:28 now what we need to look at are the things that we can do that we can do with these things so this right here like i said is idle shell you might have even even heard rebel so you got read evaluate print and loop the next thing is computers can do the the same thing over and over and over again that that a person a human gets bored with frustrated and will make a mistake now when you're over here in this is one thing that i love showing new people is python only knows exactly what you tell it so i just type name in all caps and it

7:14 it kicked back an error so this is a perfect example of how you can learn and become a better programmer because you're going to sit here and you're going to look and you're going to make a mistake and python's going to tell you exactly where and what mistake you made so it kicks out a name error and it gave you the name name is not defined and you wait a minute yes i know i defined it oh i come up here and i see that i forgot that it's all lowercase now i've thrown out a lot of built-in functions pretty quickly so and again i'm assuming that you are completely brand new to python and we're it's summertime we're coming up to

8:00 school you're trying to get prepared uh for fall classes and especially with everything going on this is a complete beginner course starting from scratch you know nothing we're gonna build on it so one important fact that you need to know about me is i've been doing i've been learning python for about seven years so you if you have any concern that you won't be able to learn python i started learning at 36 years old and if i can do it anybody can do it so i want to the the purpose of this also is to keep you guys motivated and going through and proving that you can learn to do

8:47 this if i can learn to do this anybody can learn to do this so all right here we go so okay somebody just commented 36 yeah i was i was 36 when i started and um like i said if i can do this anybody can so what i like to really teach people is i start with uh print and so you can remember the association so python helps you really a tremendous amount just with the with the shell in idle so you got print purple parentheses so now we assigned the variable

9:34 we linked it with our equal sign you guys are if you have no exposure to programming and uh especially python you're used to the equal sign showing the balance between an equation in equilibrium well in python what it does is it links the information to it and again we'll delve into that more but let's just let's just work on and understand that it's it's linked together so the information and i'll say this and again we'll expand upon this everything on the right side is done first and then that information is linked and associated with the variable name so variable name equal sign information so now so i did that with name and then

10:19 i just typed it into the chevrons or the rebel and i hit enter and i got my name out the information i associated it with with our equal sign doesn't really look pretty so python has functions already built in for us so print purple parentheses very important and let's also talk about this now computers like to know when something starts and when something finishes so i showed you one mistake i'm going to show you another so right here i'm going to hit enter python sits here and looks and goes what are you doing so now i close this out and if you look really really quickly it grays out

11:06 so python says okay i know what you're talking about you closed this now let's actually look at reassigning and making a mistake so if i do this and i leave off a quotation mark i get this long weird syntax error ah i forgot to close this out now i'm going to show you another way if i can spell my name and you can get there we go so now so let's look up here sam is all in green now i started typing sam and it's black well python goes you didn't tell me you wanted to have a quotation at the beginning so now also we are going to expand

11:51 um upon this but i recommend especially if you're brand new use double quotation marks so you can you can use single but we'll we can work through this but there are levels of quotation you can use double uh or single but right now until you get very comfortable let's use the double quotation marks so all right oops name equals let's get this in memory all right so now let's go back to what we can do here and also der is your friend when you get stuck and you can't

12:37 remember what a character what an object can do so we're going to start adding new words everything in python is an object and then a lot of these are have classes so we'll begin to build so we'll be switching to members only chat okay um so now we identified that this is a string str so now we can run help on str a string ah-ha now this is another very powerful part of python the amount of documentation that we have

13:23 now so what help does is it goes through and it has the actual description and a small little definition if if it's unable to be really understood so these are methods and we'll delve into what those are and the difference between a method and a function is they act the same you utilize them differently so right now let's run let's look at so i did dur on name and let's look at

14:10 what's one that i like upper so now now so i can call name and upper is sitting right there so i call upper boom return a copy and we are going to talk a lot about return and other terminologies but return a copy of a string converted to upper case so if i call name dot upper now super important here parenthesis like i said parentheses starting finishing beginning and ending so we had our quotations we had one at the beginning one at the end when we used help endure

14:58 in print we had an open parenthesis and we had a closed parenthesis now look right here upper open and closed so i just go boom and it will return that just means create python is going to create something and go forward so create a copy so now if i still call name i still have my original variable and this just spit out so if i wanted to create create a new variable and it was all upper case i would take

15:46 my information put it on the left side associate it link it with my equal sign and give it a variable all right so now i have name and i have upper and look at that guess what kicked out because i can't spell sometimes so i put one too many one too many p's in there so then it kicked out sam all uppercase so we'll delve into if not all of these because these are very powerful and very handy and usable and then we go from there so all right now now what we need to do is we need to

16:31 look at all right so right now like i was saying this is the shell this is like live television when you especially when i show young people this at uh schools and they try to come back up here and fix something you can't this is this is the rebel this is the shell this is live this is like live television but uh for repeatability python's one of python's way to be able to do things over and over and over again is you come up to file click new file and then you have something called a script but i already have one set up and sized so

17:17 so i have it over here and i want you to draw your attention to this dot py so when you're opening yours you're gonna do either control shift s or down here to save as and then you give it your file that whatever name i recommend the date or the beginning of uh beginning python one thing that is super important and uh i've answered a lot of questions on message boards and especially later when you get more advanced don't ever name your file the name of the file of the library you're working that's why that's why i recommend dates or the beginning subject matter that you're working on because you're going to have a circular import error so

18:03 that's that's a side note of something very futuristic so that's why i like that's why i like dates that's why i recommend starting uh with dates so now so we got name and sam now print name so what is awesome about this and so you see this little run up here then you got run module f5 so as long as your cursor is in this script over here it will run it will kick this out you'll get this and it's going to say hey and also right here asterisk see

18:48 this asterisk right up here in this corner beside the file name that means you've changed that file and it has something that hasn't been saved to it so that's why you get this prompt right here you hit f5 you get this prompt because something has changed so then you click ok it runs now this is important and i remember when i was learning i it was driving me nuts what when you see restart it just emptied out everything that was in memory so uppers gone everything everything that you had before so this does a complete memory dump right here and then the only thing in memory is everything in your script so script file your py however you want to think about this but

19:34 all of this is to save your um mental well-being so you don't have to retype something over and over and over and over again so all right oops i just lost all the chat well we'll work on that later but all right uh if you're just joining us today i'm sam with python basics and um this is going to be a complete beginner series uh in python and this actually came about by uh on my channel i think there's 740 videos and i wanted to uh i partnered with bo and we were talking about

20:21 kind of starting over so this is basically a recap of and for the next few weeks we're gonna we're gonna get through the first hundred and really start delving into all of the other videos but that's where all this is so if by chance you're like me and you want to get ahead and know what we're going to talk about before we talk about it you can go the link's down below uh for all those but this chan this these streams are designed for brand new people and especially i started thinking about it about um it'd be in summer time right before school is going to be starting that there's going to be plenty of people that are going to be wanting to

21:06 really get ahead with their programming skills and especially the popularity of python but i have a great passion for python i've been learning it for seven years been teaching it for about five so uh i know i can get excited pretty easy and fly through some of this material so uh bear with me hold on and we'll get through all this together so let's talk about some more repeatability and also actually before we get into that we need to look at this so we looked at der also you run dur with zero arguments i know that's a word you may not have heard before but you leave out the parentheses

21:51 excuse me you leave the parentheses empty you get everything that's in memory right now and we'll talk about all this stuff later but there we are with our name our name variable so now same thing with help if you put help here and you pass it zero arguments you get the you get the prompt help so we looked at we looked at um strings now let's look at some keywords because again like i've like i've been saying python is so powerful because of its vast width and depth of its community so let's look at some more repeatability

22:38 so we already just talked about a file for repeatability then now we need to look at something that is very powerful is something a way that you can do over and over and over and over again and one of these ways is with a loop i made a comment made a brief comment about repple read evaluate print and loop well there are two types of loop with python and we're going to focus on the for loop right now and the reason why i wanted to show you these keywords let's get out of there is one of the other powerful things about python is it gives you some color hints and because being dyslexic dyslexic and being not

23:24 being able to spell so when i'm writing a word and it doesn't go the color that i expect that helps me when i have to when i'm trying to find out why my program is not running very well and i will tell you another one that just is the bane of my existence lambda i have to usually try that three or four times so now we're going to learn about a second built-in or excuse me our our so we did help we did type we did dur we did print now we're going to so that's 5. so now we're going to look learn about range so what range does is this is a very interesting

24:10 function so it has some characteristics to it in programming you need to be able to do something a certain amount of times so one of those tools is range so and if you look right here you got stop so if i give it one argument i get stop but if i give it more than one the rules change so let's just go through it so i'm going to use a new keyword for then i'm going to give it a variable it's a temporary intermittent variable another keyword in and then we're going to pass it and we want this to do this three times

24:57 so i know i know i just did a lot right here so this is actually called the header and everything inside this is called the body and this this also we're gonna see this in our own built-in functions and we're gonna do that very very soon so keyword for temporary variable in this so this has to be an iterable all right and we're going to go into more definitions more terms like i said we're gonna we're gonna go forward and backwards are gonna move back and forth so this is an iterable and now one thing that a lot of new people do is they forget that colon at the end and you can learn right here quickly that i forgot

25:43 something i want to draw everybody's eyes and attention to this down here in this corner so i'm on column zero python automatically indents four so now i'm here on column four so that's how i know and it goes when you have multiple levels you go in four every single time so we're gonna print we're gonna do this slow everything i talk fast but i go slow if that makes sense all right so i want something to happen three times and right now all we're going to do is print out name and name is associated to sam it's we have sam assigned to name and i want this printed out

26:28 three times and this is my temporary variable so i works or even a blank underscore all right so yes it is going to be a full series and we'll build up to a code editor but the reason what this is the way that we're doing these streams is this is for absolute complete beginners absolute complete beginners we don't want anybody i don't want anybody feeling overwhelmed that they can't learn this so i ran across some videos and basically the way that all of this is designed is what how what organization what structure would i

27:15 would have wanted if if if i was starting to learn over again so this is not important this is only if you're going to do something with this over and guess what we're going to do that in just a minute so this is going to print out so you got your header and your body basically what do you want to do and what are you doing so what do you want to do how do you want to do it and what do you want to do so let's run this so now i hit my f5 and i have let's comment we need to learn about we need to talk about commenting ah for the younger people in the crowd you might know the pound sign as a hashtag

28:02 well that's the comment so whenever you see red colors in python are very important so red means it's been commented out so that just threw off everything so now you're like why why why'd sam come out four so let's rerun this all right so sam came out three times so here we go so i commented this out and i quickly did that with alt three you can also come up here comment out region uncommon out region so alt three and alt four i can highlight and do this so all right so now like i said throughout a little bit of a term this is called an iterable and we're going to throw it into a container in a minute but right now let's change this to i

28:50 actually let's leave this and so you guys can see all of it especially if you guys are joining us now let's see yes okay all right and let's see so we're going to copy this and we're going to change this to i and change this to i and guess what we're going to comment all this out so we highlight the region and then we press our alt 3 comments it out and let's see make sure okay you guys can see that good now i'm going to press my f5 and we're going to see what happens now something

29:37 different that your may not be expecting so all right zero one two all right that's still three numbers right so let's look at range one more time and still no i didn't spell it right because it didn't go purple so all right if i give we have this handy tool and i'm not even using it so i'm going to put range in our help ah here we go so range stop range object range start stop let's read this return an object that produces a sequence of integers start it's inclusive means it is included stop

30:22 is exclusive means it goes right up in two but does not include well what'd we just find out here three i want i want three numbers well python is a zero index language starts at zero think about a number line and the reason why i say this is because we're going to address this in a minute with negative indexing and especially when we get into slicing slicing strings so it starts starts dead in the middle at zero and it goes positive i think i'm pointing up for you it might be that way goes positive and then of course negative so you don't want to have a gap in the number line so that's why gordo decided to start at zero zero indexing and then go positive

31:10 so we got zero one two still has three numbers just it starts start step stop just like this so when you give it two numbers the first one is the first argument is start second one is stop and then you have step so now if i change this so the start sequence is inclusive stop is exclusive so i have one two three four five but five is not included it's exclusive it's excluded so how many numbers will come out

31:56 one two three four now now let's get now now let's learn about a container so we got four different types of variables we got strings we got ants we got floats we got booleans now we need to figure out a way so basically you're saying so i have to assign all these variables well not necessarily now there's also we're going to learn about a list and a list is one of the basic containers help list and it's literally like that and guess there we go so haha it's an iterable built in mutable so we're going to talk about that later but mutable just means

32:44 you can change it and then let's look at der on list and here we are we're not going to worry about these double underscores and i i don't think you'll ever hear me say dunder i don't think uh double underscore methods and then here are the methods that we would utilize so let's go and we're going to do something very cool so we need to um list of 5. so we have our range five now what is so super cool with python

33:31 is like i said python doesn't care as long as it's legal and you do everything on the right side of the equal sign then then link it then give it a variable this is completely legal so i take my range and python knows okay so it's 0 1 2 3 4 because that's 5 numbers i started zero okay i know what you want all right then now you want this around the list functions so you want to turn that into a list okay i can do that so now and i kind of alluded to that so here are brackets so this is our first basic container holder of stuff and will become more elaborate

34:18 holder of objects in python and these are ins so now when i run type on my l underscore 5 and it helps if i close this out it gets back the class of list now let's talk about some rules for variables we have not done that yet there are python has python is a language python has rules so basically when you start programming and you start building uh have a project and then you build it to functionality in the project then you have functions inside the functionality and then you're going you're going and you're strong and you're getting smaller and smaller and smaller so

35:04 you have to take a project and get it down to remembering information and doing something over and over and over again maybe analyzing it maybe a little bit more but that's how simple you have to get this so when i'm teaching people i say that you have to get it down to the bare bones of can you explain this to a five-year-old if you can explain this to a five-year-old you can write this as a program or you can have a function and that's that's how you have to go so uh how much do you have to indent the code all right the code will indent itself if now if you're in sublime you may have to now you want to get very careful with spacing and tabs that's why if you're

35:50 new i want you to be i want you to start here so you can begin to really understand you can get i remember i i equate this to the lesson that i learned when i was playing tennis i had a tennis pro and um i told him that he was better than me because of his racket so we changed rackets and he beat me with my own racket so we're learning the basics we're learning python don't get hung up on the editors let's learn the skills first you learn the skills then you can use the editors this is fine for what we're doing for several weeks alright so we have some rules for python has a couple rules for um variables cannot contain a special character cannot start with

36:36 um a number cannot start with a number all right cannot start with a number and cannot be a keyword and a so that's why i showed you these so these are already used in python same thing also it can't be a function name all right so we can alright so now we're we're 37 minutes in we're going pretty good we're going strong so if you're just joining us i'm sam with python basics and we're going to be doing an entire series um for complete complete absolute

37:24 beginners and the what i was kind of thinking uh and bo bo and i chatted and i would appreciate bo for giving me this opportunity to be here with you guys but i have a great passion for python i learned it at later later in life starting at 36 so if i can do it anybody can um so i've been learning for seven years and i've been teaching for five so i've gotten down some pretty pretty good material and i've had a youtube channel for almost three and a half no it's only three three years and uh four months so

38:10 tons of videos over there and bo beau and i were talking that uh we just kind of wanted to start over from those and compress these and put these into some live streams so thanks for joining us today and we're going to be doing this every tuesday for the foreseeable future so all right let's uh let's continue with on with where we are so we just looked at that we called repeatability we got our scripts so here we go so now all right so now so we ran we ran this let's pull this back up let's touch on this again so we have our range we have when we give two two digits

38:57 all right and i apologize for copying it was not that big of a deal i should not have copied that now let's look at this print i let's comment this out now what did we see about range start stop step and step is uh will will be omitted but i thought it used to say interval does not say interval anymore sorry think about your times table steps

39:42 let's change this to two so what should come out right here any any thoughts oh i don't have chat anymore uh any thoughts of what should come out so we know it's gonna start at 2 and it's going to go by twos right here 2 4 6 8. wait a second i wanted 10 to come out so oh that's right 10 is the stop is 2 4 6 8. you're exactly right uh jan no 10 no why not 10. very good question why not 10 is stop is exclusive so if i wanted

40:28 to get 10 to come out i need to go past 10. stop is inclu is exclusive right up in two but not including the stop position so i went past because we're going by twos but technically really i just need to go to 11 i just need to get past 10 to go to have 10 be included because the stop is exclusive right up into so great question so now now let's change this a little bit because i want i want to i want to wrap so now i want to look at

41:14 iterables as another because right here this is a so this is this returns an object of sequence so this is iterable but let's let's see what we did here so we took so we got our l so you don't want to do see if i do this list it's not going to work so that's why we did our l five then we wrapped list around range five close this out let's go over this real close so i do five i gray out i get around this and i grade

42:01 out one more time and i get all my contents so now let's comment this out we're going to type some more for i in and so let's look at this number num in l underscore five i get my because it is that that is the same rule it a so we so the rules for a variable are can't contain a special character can't start with a number and it can't be a keyword or a function so there we go those are the three rules

42:46 now print num so here's my temporary intermediary variable and right here now now let's look at one more very important other function my goodness sorry guys i cannot type today len short for length return the number of items in a container so now lynn on l underscore five close this out five so there we go so now when i run this what will happen

43:32 anybody jan you got any you got any guesses so if i run if i press f5 what will what will happen i don't know how much of a delay there is on my end in chat so i'm going to run this i don't know if you're sitting there watching me going why hasn't he pressed it yet so same rules apply here now let's do let's do something cool because no i changed it to just one integer so it reverts back to starting at zero yes you're good you're good

44:18 so when you pass in one integer to range help on range when you pass in one integer it's only the stop point so zero through right up into not including the stop point so that's why this was four so now so now what happens right this is also where it gets really cool so now that i'm inside the body right here i can i can list however many instructions i want okay sorry guys that was probably a big loud

45:05 and study okay so print all right and print num [Music] times actually let's do this over here first we need to talk about this so we have not talked about operators yet so python was built upon the basics and again that's why this thing is so so very powerful so it just jumps out as a calculator so you got your standard multiplication subtraction excuse me addition subtraction multiplication division uh exponents and there are a couple others that need needed to be added so we got our oh where they did that so

45:50 1 minus 1 then you have 5 times 2 6 divided by 3. now here's how you handle exponents so two two asterisks is a exponent and then um so where it gets very important and when you're dealing with floats and integers and guess what we'll get to that there is a way so if i go and divide so as you can see right here this kicks back a float well when you're doing specific things and you're expecting one type of integer excuse me one type of object and you get a different type of object that can be a

46:35 problem so guess what python has a way to handle that so this is floor division it removes it removes everything that you don't need now one of the very cool operators it took me a long time to figure out was the modulo this is what is so cool it's the remainder so right here let's go 5 divided by 3 i get 1.66 so 5 modulo 3 i get two okay so three goes in two times no no no no three goes in one time or it almost goes into no

47:22 let's do long division so three goes in to five one whole time and the remainder is two or two thirds so we're going to have a very interesting exercise and a very nice problem especially when you're trying to solve mathematics and you're looking for ways to handle rounding this modulo is a very important character so all right a little bit of side note so we're going to do print we're just going to give an empty line and we're going to do print num times 2. so i want i want the number then a then a blank then a

48:08 and actually we're gonna add another one print so we're gonna do the number then a blank line then the number times two then a blank line so let's run this so i will get okay i got 0 0 0 1 2 2 4. now let's change the scale you know what i don't like that i don't like that one there i want to do number number times two then a blank line and then go to the top so this is what's very powerful about loops and also then you have to plan and think about loop control flow of the program how are you going to be doing this and i think we're going to get to it today we're going to do a number triangle i love teaching this because this is a perfect example

48:53 of how do you control control the flow of the program and you have to think about it you have to go through the order of events and how can i do this in a form that can do this every single time that is that is the challenge of a loop is that what order of events can i do this every single time with maybe a variation at the beginning or a variation at the end to kick outside of it so now let's run this again alright so i get zero zero blank line one two blank line two four blank line three six and four eight so the order of events are

49:41 one time through i do all of this then it kicks back up here so all right we're going to expand upon this sorry i can get sucked in and talk about loops for hours so all right let's see what is next all right so we need to now look at some slicing so slicing has the same rules as let's bring in um name say s-a-m-u-e-l

50:30 so all right so now you have slicing and indexing so we've seen parentheses and we've seen a bracket with a list so when i give python brackets and one digit beside a string variable i will get a singular character this is the zero index all right so this is one this is two three 4 and so on but the same rules apply if i now with our range function i gave

51:18 i used commas with slicing i use quotations so we're gonna we're gonna look at this 4. so what in the world just happened so let's look at this i start at 0 i go through up to but not including here let's come over here so let's look at another quick comment way to do this so if i give three quotation marks everything inside this is not looked at by the computer so i got 0 1 2 three four five

52:06 let's space this out some that wasn't very good that looks jumbled okay there we go shrink this a little bit so we can see both of them side by side all right so i got zero i got one two three not including i did not include four now we need to look at this so when i leave now with our range function you could not leave one of them blank but with the string you can omit and pass in the colon so python goes okay you

52:53 know what you're talking about you know you want to use the stop location and we kind of understand each other that you know what you're doing and you want to start at zero and then you want to stop at five so i close this out so i go to 5 2 5 not including 5 and that's why i stop at e now so let's see so now i go name [Music] if i leave the other one blank i'm telling python hey i want all of it i want i want the whole thing now there's a couple ways that you can

53:39 do this in reverse and this is this is just one of the things that i just love about python so all right same rule start stop step start stop step now so if i go by twos start stop step i want start at the beginning go all the way to the end and i want you to go by twos so start at zero uh start at zero skip every other so boom boom so that's why i only get s m e start and come over here now all right

54:25 now let's look at how to go backwards negative so i'm going negative in reverse one time so this is a way that you can take the string and reverse it so this is a very cool test if you've ever heard of palindrome so palindrome so this is a very good test to how could you take in exactly it is exactly it is the same rules that's why i like to tie these together range you can look at the documentation for help on range and then we slide over to slicing with strings

55:11 the exact same rules so that's why i like to include this what you'll notice about me and the way that we're going to do things is we're going to have association and then we're going to have reinforced learning so we're going to learn a couple of things together that act similar and then it's going to revert back to something and it's going to support it so we're going to we're getting our good base down we're quite getting we're getting that we're building a good foundation and then we're going to build upon it we're not going to rush through anything if anything we're going to go over a couple things uh several times and hopefully while we're here together you're going to get something that you've never seen before because that's what i tried to do i wanted to do one letter in the string i can't do that what if we only want to omit one letter in the string

55:58 you want to just omit one oh okay so you just want to jump over one letter all right so there is because we are actually going to get to something like that so now one of the other issues with strings are let's look at help str string we need to do we need to look at this uh where does it say it watch it not say it in here for me uh immutable you cannot change a string but you can use parts you can use the whole string parts of strings

56:44 and here's the little bit that can get confusing at first until you really start thinking about it you can add to a string but you're actually then creating a new object really but alright so let's say we wanted to so we got we got sam right uh name actually let's shorten it to just sam so now we're going to do this in a minute so this is a very great question we're going to take a bank of

57:36 well let's build upon this so if i just wanted am to come out how how could i do this so we can look at how to slice up and chop this up in the middle so how would i get so if i know 0 starts s how could i get a to start where would i need to where would i need to go what would i need to type right here so i say start at one and index one go all the way to the end include everything i get am so now all right this is called concatenation just a fancy word to say

58:23 adding strings together all right so p should do it oh okay uh jan i think i know what you're saying but hang on a second so if i want so if you did that that's going every other letter uh and i don't know if that was name for sam or samuel but then that so if i wanted to if i just wanted am to come out it's one starting at starting at this index one second letter always be off by one especially when we start doing our number triangle here in a little bit you're always going to be you're usually off by one either side plus or minus one so we got

59:12 oops i typed that wrong let's come up here all right so what did i do so name slicing starting at one index one then going through so i got am right here and i added i concatenated p with am and that's how i got pam and then you got uh so then if i made a bank right here this is i love this exercise so bear with me so if i make a string

1:00:01 and i do p t j what's the other one i do yeah four and i still have name yep so this is going to call name up here just to remind you for letter in letters so this is a group this is a string this is an iterable so i can place this here this is an iterable so i get my colon then print letter plus name just like we did over there

1:00:49 close this out all right this is this is my building block this is just the same rule i'm just using variables all right let's put this into memories we'll go slow we'll go slow so letters what is this so if i go for letter in letters print letter i'm going to get each one of these i'm iterating through an iterable one at a time p t b all right so those are my building blocks i'm iterating through my iterable one letter at a time so here's my

1:01:35 temporary variable and i remember that this is am and i'm adding m to the end of each letter which comes out p t j b so then now i hit my f5 and now i get pam tam jam bam all right does that make sense any questions about that all right cool let's keep going hour one is down so all right if you're new here thanks for joining us i'm sam with python basics and we're going to be doing a live stream uh once a week for two

1:02:22 hours and basically this is a compressed course of all the videos off of my youtube channel uh 700 plus videos and we beau and i uh been talking and i had been experimenting with live streams and uh free code camp has given me this wonderful opportunity so i just want to make sure i tell them thank you thank you to them and thank you to beau for this um uh wonderful chance to share this because i just love python absolutely so much i think it is a doorway to so many things for anybody who wants to learn uh anybody who wants to give any effort

1:03:08 to programming because if i can learn how to do this i promise you i can teach anybody because i was 36 i'm dyslexic adhd any issue you can think of i got it i learned it i love teaching this it is a powerful tool it changes the way you think it changes your outlook it i want you guys to stay motivated all right i want to i'm i'm here to keep you guys going so all right let's keep going let's keep going so now so we've done a little bit of slicing we've done a little bit of concatenation so now we need to really look at what did i want to look at next so we slice the strings

1:03:55 ooh we haven't even built a function yet so let's go ahead and do that so all right we have been using all of python's built-in everything so now i like to i like to build on from our from our loops into our function they do the exact same thing so that it's designed the same you have your header and then you have your body and that's it and the same rules apply so let's just go ahead and do this let's comment out all this so we don't have any straggler stuff and also very important side note don't ever delete anything

1:04:40 i remember i was going i was like oh i'll remember this i you got tons of hard drive space there's stuff in the cloud don't ever delete anything you've ever written one it's kind of cool to go back and look and see what you've done in the past but don't delete it just comment it out save it and also one important thing to really learn is make sure when you're writing programs you put comments in them because what i have a challenge for you is if you've been programming a while go back and look at one of your programs you wrote a year ago or even six months ago see if you didn't put any comments in there see if you can remember what in the world you were trying to do so all right now we're going to build our first

1:05:26 function all right let's get this up here so it's all towards the top so all right now we're going to learn about another keyword and we know it's a keyword because it is orange so let's let's come and remind ourselves help keywords keywords and i'm there i'm at our interactive help prompt and you get to there by typing in help with zero arguments all right and as you can see now we have def we pass in def and oh wow okay so we use this for defining uh a function okay there we go so let's jump into it so yeah if you can't

1:06:13 ever remember exactly what something does especially i remember i was going nuts i'm like how am i gonna what do i what is that what does that keyword do what is that key oh wait a minute yeah i have my interactive help and i can ask about that keyword so all right we're just gonna type hello i think it's good if you get a zero all right so the way that i like to explain this is you need five things on your header your def keyword the name of your functions your parentheses your colon because if you leave your colon out you go back to under def on the edge column zero you have a problem so you make sure you put your colon in

1:06:58 there and python will take care of it in the script and indent four for you now stuff in the middle the argument inside the function is optional right now we're not going to take in anything we're just going to print out hello and it helps if you pass it a string all right my goodness guys i'm very sorry for the typing today so let's look at this same same setup sorry same setup so when i'm here i go down python says hey do you have any more instructions i'm sitting here i'm waiting i'm at your beck and call and you're like no actually i'm done so now that just now a little variation just like when we created so i put this

1:07:45 into memory looks like nothing happens so same thing just like when we did our variable we put it into memory and it looks like nothing happened but then we had to call it right so we did this went to the next line you're like nothing happened actually a lot happened same thing over here so in our file in our script we created then we called it we put it into memory but where did we call it we haven't actually called the function so we just go hello and it's a function and as you can see python helps you it says hey doesn't take any arguments just pass parentheses

1:08:32 and you're like okay cool now if you're like me you're going to want to see this thing run so you're going to so i'm here inside my function right and i'm coming here i'm coming here i'm coming here well i need i get outside the function i'm not inside so like i said we're going to build we're going to add we're going to sprinkle we're going to add we're going to go back we're going to go backwards we're going to add we're going to add all right python tracks white spaces this white space right here python goes okay you know what you're talking about you just made a function and everything i'm going to do everything inside this function and when i get outside the function then i'm going to go through so just like our for loop

1:09:17 python comes down here and it loops through everything here once it gets to the bottom exterminates at the bottom goes back up to the top same thing with the function it's going to read all this in then kick outside here so if i want to then inside this file inside this script called the function after i put it into memory i come down below it and then just call said function just like i did here so i just put it over here now it can't be inside the function that's another type of issue we'll deal with that later but we'll jump into that very very soon all right so here we go i get hello now now let's do a little bit

1:10:03 more so now i'm going to pass in sam [Music] name and then concatenate name so then i give it here we go all right so now i'm taking in information here's my here's my argument my first my first

1:10:48 exposure to an argument i'm then going to print hello along with this argument this variable and then down here when i'm calling the function i'm passing in this so the way that i want you to look at this is this is the variable from here right same concept same concept where we have the information the variable and then we're utilizing that variable here so now we're passing this in this goes here so visualize this as sam and sam now there is a problem here and we're going to see it and then we're

1:11:34 going to fix it and i love teaching young people and they say i did it wrong well it didn't do it right it didn't put a space in there okay well show us where we put the space we didn't put a space anywhere so of course the computer it's not gonna guess it's not gonna hope it's not going to go i know you meant to put a space in there it's not going to do that so we're going to come here we're going to run boom hello sam all right now now why don't we right now we have this program and it's not even close to an end user i got to get into the program to put my name in there well guess what python's got something for you help

1:12:21 input let's pull this over these get bigger and bigger so all right let's go back to chat who has seen the input function before anybody okay so read a string from standard input trailing trailing new line is stripped the prompt string if given standard output with a trailing new line before reading in sorry what this is basically saying you have okay cool so basically now we're going to get rid of this we're going to get then we're going to do name input

1:13:07 enter name so now this can you can get uh user input from the command line but that's gonna be at least a video or two away because that's dealing with uh um sysrv and i don't wanna we're not we're not to that point we're we're we're still dealing with beginner beginner stuff but yes you are come completely completely accurate there is a way to grab all input from the command line and that is some very powerful stuff with python and i i love it i love it i don't i don't want to get sucked into that crack quite yet i want to i want to deal with uh all the basics first but we are we are going to

1:13:53 get to that and we're actually going to uh do some pretty cool stuff with that so all right um so now we have so i got to get rid of this because this is not we don't take in any information uh with our with our function so i have this function i then am creating a variable utilizing the input utilizing the input function i'm passing any in some a prompt in then i'm taking that information and going forward all right so now let's go through this enter name and then i go oh i don't like that it's right there on that uh colon so we're gonna fix that later and we do that just by this

1:14:40 boom so now i have my space right here let's run this again so now my prompt is sitting right here it's now i go sam oh very cool okay so now now i have this now now now we're going to look at this and let's close comment that out now we're going to look at how to uh def crent so i want blank print empty blank

1:15:25 so then i call blank and what happens get a blank line all right deaf blank three so now i want three blank lines so now i'm going to call blank three times so the reason why i'm showing you this is i know i could use print but the the point of this exercise is to show you

1:16:10 that you can begin to utilize so now i got three lines so now now i'm gonna go def blank nine so instilled sorry blank three all right i'm gonna cheat a little don't tell nobody do not recommend this okay so now i call blank underscore nine open close run this and now i get nine so the point of this exercise is to begin to show you that where this becomes very powerful

1:16:56 is so i don't have to go in here and type i don't have to type print three times three times so or nine so this is the building block of how you would go in create a function be able to utilize that function at a later time and then even expand upon it so that was one of the first things because when when when computer programs were first being built you had to go in and do the exact same command over and over and over again i i can only imagine what that what that could be and had to be like and then then they designed efficiencies hey there's got to be a way for us to

1:17:41 do this over and over again and the first one was the go-to line and then and then it was like okay do we really need to then go back up there so we have this thing circulating so then they came up with a way to have a function and then it has developed and evolved and then files and then boom boom boom because i mean if if you're if you're anywhere near my age the computers were actually the information was actually saved on magnet tapes it would search the tape and coil and spin and run that was the original hard drive it was it was nuts all right i digress but uh all right it's a little ads we got another bunch of time that went by if you're just joining us today thanks for being here can you

1:18:28 can i call the function with the same function like blank function inside the blank function yeah but i don't want to get into that right now that's recursion and that you can do that for certain purposes if you mean to especially we're gonna have an exercise uh a recursive function but um what am i what am i trying to think um oh where we swap fibonacci so uh the fibonacci sequence can you call the function from within a print function when giving an example jana what i mean you can but all it would do is print out the

1:19:14 function can you give an example what you're wanting to do [Applause] because here if i call because you're going to get something like this that's what it would look like so okay yes oh well i'm glad to hear that i'm very i'm very glad you uh you joined because look if it like if like if you're just joining us right now um i've been given this wonderful opportunity to live stream with you guys and python has just changed everything uh about me and i know that sounds a little

1:20:02 cheesy but i mean it has it's given me a bunch of new skills the way that i see everything the way that i problem solve i've been able to teach python at my kids school been able to expose a great deal of people i've had a youtube channel for over three years it is just a wonderful tool uh that is out there so yes i'm going to be doing we're going to be doing this for a very very long time and i don't see it slowing down at all if anything i see it going faster so all right but yes you you do have a function called other functions and especially a fibonacci sequence well

1:20:48 well i really appreciate that thank you very much all right so we have a function call in other functions and all this basically is and then we're going to get it we can get into nested functions later for example if you want to user to enter the gender [Music] the character in the program standardizes their input the user enters the character as male and the sentence would say the character is a male uh okay i'll look at that later i think i get that let's see if i can copy that all right i'm copying that question right now and i'll look at it i don't want to slow uh all of us down but jan that's a good

1:21:34 question i'll look at i think i know what you're saying but i don't want to not answer i got i got some other stuff i want to go through but i will examine that and if you go to my uh my channel and then there's an email address that you can email me and we will uh we can we can chat about that or you can send me a uh a paste bin if you have a script that you're kind of working on and i can i can help you with that all right so cool where are we oh i think we're to the point where we need to where where was i are we gonna do the

1:22:22 oh yeah okay we need to look at how to start looking at making decisions so we need to because we're talking about modulo so we need to thou bring in we're going to make a list numbers and it's going to be all right we're going to go 1 5 2 4 6 10 and i don't think i have three

1:23:08 so print number and numbers print number so what i want to do is i want to we're going to we're going to we're going to build we're going to start small okay so we got our we we got where we can go through our our list so now we need to find out and we want to print out if if each number is odd or even and i made one little concept one little passing comment about a tool so does anybody have any guesses how in the world

1:23:53 we could begin to use the tools that we have to find out if a number is odd or even or i guess how would you explain to a five-year-old what an odd number is and what an even number is any comments jan you've been doing awesome and they're super interactive any any quick comments how you'd describe to a five-year-old what a uh what an odd or even number is all right best description for the tools that we have is if a number is divisible by two with a remainder of zero all right so now if a number can be divided by itself it's even

1:24:41 okay all numbers wait hang on if a number it can be divided by itself it's even by two yes absolutely with a little a little bit of but with a little bit of caveat with a remainder of zero so we have to have that little we have to have that they're all evenly divided evenly divided that that's where the sticky the stickiness of this gets so now we've learned about how to use an equal sign to link information information to a variable now now we need to learn how to find

1:25:26 equivalence boom okay very very good if there is a remainder of zero awesome uh modulo we're gonna it's gonna be like this if you guys are looking at the comments that is exactly it so this is then how you do a condition so another keyword keywords words if as alphabetical order for me where'd it go there it is

1:26:13 if all right conditional statement conditional execution and the way that we do this is one equal to one is one the way that i would recommend and say put an is in front of it to help put you until you get very comfortable with this is one equal to one two equal signs is the equilibrium one equal sign is association linking assigning association linking assigning two equal signs equivalency test true is one equal to zero

1:27:04 so now now we have inside our for loop now we're going to have some more indention if number one here do we have a number still in here okay numbers all right so if number modulo 2 so i divide it by 2 equals nether colon more indention and i want you to print out number we're not going to do anything else right now so basically all that should happen right now is we should

1:27:50 only print out because this is the only instructions we have so we have we have our loop we have our header loop now we have our header condition now now we have our specific here's our condition now actually i want to let's hardwire this all right so we're going to cheat i want i want to really focus on this this line will only happen these instructions will only happen if this line is true all right so it just printed out everything i made i just said make everything true so right here i have one equals one true

1:28:36 one equals zero absolutely not it's false okay so i hardwired this i made this true so every single number printed out so now we're going to pass in if number modulo 2 equals zero so now this has to be true for this to happen all right so i should only get even numbers to print out right because this will only it will only happen it will kick down here past here and then it exhausted the instructions and will go back up so now let's run this so i only printed out even numbers

1:29:22 so now how about we say let's change this up a little bit uh is even all right and i told you to do this and here i am getting fancy and giving you bad examples i'm a bad teacher all right 2 is even 4 is even 6 is even so we have the same thing so now bingo else odd so now we have to the way that python works is it goes hey i got you an if so you don't have to do another if because we're going to talk more about

1:30:07 that i don't know if we'll get to that today i think we will we only got we only got 30 minutes um i don't know if we'll get to that today but you have to have a way to grab the opposite because let's let's hard wire this let's hardwire this right now as false false and i'm going to run this nothing happens because all these are false so nothing happens it comes up here gets exhausted so i back this up boom now the way that i did that i know i just typed a lot so if you're new here uh let's

1:30:58 see yeah you're right is that better i should be probably more consistent so now the way that we can do this is i print number so if this becomes false if this if this is not true excuse me if this is not true don't do this content continue on all right boom so now i get okay

1:31:45 now here we go one is odd five is odd two is even four is even six is even ten and so on and soon i don't know if it's next we need to then figure out a way and there's another term actually yeah let's go ahead and i think i do have that next oops see where i am with the notes

1:32:30 all right yeah yeah yeah all right so now now the next one and we need to figure this out is is is a number so this simple example works because there are two conditions right we have we have a positive we have a positive and we have a positive and excuse me we have an even and an odd so there's only two there's only two scenarios what happens if we have a even or odd number what would we do i need to add one little one little caveat here

1:33:18 there we go all right so kind of just gave gave it away right there so i got i got a set of numbers let's go through these numbers for number and numbers print number all right do i have even a rod how am i gonna excuse me positive or negative i need to change excuse me i forgot to change that that and that so how many conditions will we have if we have because right there even or odd there's

1:34:04 only two but if we do positive or negative that's kind of a trick question because there's actually three conditions so we need to learn about we can we can do this one of two ways so we're gonna we're gonna do it two ways so i'm gonna do a nested all right so we print out oh did i not save this then it's not safe there we go all right so we got we got some we got some negative numbers we got negative 5 negative 4 negative 10 and we're going to zero so that's that's

1:34:51 our that's our little bit of our our hint right now yep we got three conditions so how in the world are we going to handle those three conditions we could we could devise this a couple of different ways so let's let's just go ahead and get started if num equals zero print zero wow zero and there i am doing that again sorry now we need to look at this

1:35:36 else if statement all right or another one shoot help keywords and it's very very handy very very cool lf so the reason why this was created was if you have a bunch of if conditions this took me a long time to figure out and i was new to programming and i was old so if it worked i i went on about my day but then i started realizing that these that i was these longer programs and especially checking these longer uh lists and these longer containers this was taking

1:36:23 forever because it was running through and checking every single if so the elif you you utilize elif so it will only check the first if and then exterminate and go out for zero uh for even for even an odd oh that's actually kind of cool so if it's zero and even and odd all right so right now i may have been misspeaking because i was trying to read some comments so no all we're going to do right now is if it's positive or negative and there's a tr there's a trick there's a sneaky condition in there as if it's 0. so if it's 0 do that l if

…

Share

More video summaries