[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,1\N00:00:04,390 --> 00:00:09,910\NThis video, we're going to talk about data types and operations in Python to get you started, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,2\N00:00:09,910 --> 00:00:13,320\Nmore on being able to write some of your own Python code, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,3\N00:00:13,320 --> 00:00:18,430\Nare learning outcomes for this video or for you to understand basic python data types of operations, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,4\N00:00:18,430 --> 00:00:24,880\Nto be able to work with python variables, storing objects in them, to write some simple python code, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,5\N00:00:24,880 --> 00:00:31,210\Nto do arithmetic and perform basic operations with lists and dictionaries. Also, this slide deck is a notebook. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,6\N00:00:31,210 --> 00:00:38,200\NAnd so rather than the little embedded slides widget like we have for a lot of the videos, for this one, there will be a link to the notebooks. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,7\N00:00:38,200 --> 00:00:40,810\NYou can download it and run the code yourself. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,8\N00:00:40,810 --> 00:00:46,480\NThere's also going to be more resources linked in the class notes that I'll talk about briefly at the end of this video. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,9\N00:00:46,480 --> 00:00:51,760\NPython supports couple primary types of numbers. First, we can write integers just by writing the number. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,10\N00:00:51,760 --> 00:00:56,860\NThere's no decimal point in there. And if we run, that is just a it's a python line. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,11\N00:00:56,860 --> 00:01:02,590\NSo a python line is called a statement. A statement can have something like an F or something like that. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,12\N00:01:02,590 --> 00:01:10,990\NOr it can just be what we call an expression. And an expression is a set of operations that results in a value. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,13\N00:01:10,990 --> 00:01:16,420\NAnd so a number just writing the number itself is an expression. So we can we can write an integer. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,14\N00:01:16,420 --> 00:01:21,340\NWe can write a floating point number with a decimal point. These are stored in floating point format. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,15\N00:01:21,340 --> 00:01:27,250\NThere are a couple of nuances about that. We'll talk about when we talk more in detail about different types of data. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,16\N00:01:27,250 --> 00:01:30,490\NWe can also use scientific notation with the E notations, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,17\N00:01:30,490 --> 00:01:41,840\Nthe six point O to each of the twenty three Avogadro's number a mole and we write E twenty three and that means times ten to twenty third power. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,18\N00:01:41,840 --> 00:01:53,000\NSo we can also do arithmetic on these numbers, so the usual arithmetic operations, addition, subtraction, etc., they work as we would expect. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,19\N00:01:53,000 --> 00:01:54,570\NThey were just like they do. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,20\N00:01:54,570 --> 00:02:00,770\NAnd when you're writing them in math, when they work in other programing languages, we can add five in to order of operation disrespected. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,21\N00:02:00,770 --> 00:02:04,820\NSo three times six at plus two. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,22\N00:02:04,820 --> 00:02:13,250\NWe can also then use parentheses to change the groupings so we can add two and three before multiplying by six. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,23\N00:02:13,250 --> 00:02:17,300\NIt works like you would expect from almost any other programing language. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,24\N00:02:17,300 --> 00:02:23,420\NNo surprises here if you're familiar with Java or Perl or something else. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,25\N00:02:23,420 --> 00:02:25,850\NThose are our basic arithmetic operations. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,26\N00:02:25,850 --> 00:02:32,480\NIf we want to raise something to a power, the star star operator is what Python uses to raise something to a power. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,27\N00:02:32,480 --> 00:02:35,990\NSo two to the fifth power is two star star five. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,28\N00:02:35,990 --> 00:02:43,610\NWe can also get a number of other mathematical operations from two different python modules math and num pi num. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,29\N00:02:43,610 --> 00:02:48,230\NPi has duplicates of most of the math ones, so I usually just work with num pi. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,30\N00:02:48,230 --> 00:02:56,240\NYou have to import a module before you can use its function. So I'm going to import the num pi module here and I want to give it a shorter alias enpi. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,31\N00:02:56,240 --> 00:03:01,670\NThis is very common in Jupiter notebook's that we that we import num pi S&P so then Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,32\N00:03:01,670 --> 00:03:09,020\Nwe can just write n.p. dot log to compute the natural logarithm of the number twenty. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,33\N00:03:09,020 --> 00:03:12,320\NWe can also store values in variables. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,34\N00:03:12,320 --> 00:03:20,810\NLet's just give them a name so X equals seven stores, the value seven in the variable X, there is no declaration necessary, unlike an JARBOE. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,35\N00:03:20,810 --> 00:03:24,230\NJust assign the value to a variable. Then we can use it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,36\N00:03:24,230 --> 00:03:31,130\NSo X is plus five is going to return a 12 because X currently stores the value seven. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,37\N00:03:31,130 --> 00:03:35,670\NNow if we change the variable, so we say X equals two. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,38\N00:03:35,670 --> 00:03:43,510\NOK. It's changed the variable. Python. So the variables are all stored in a commons memory space. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,39\N00:03:43,510 --> 00:03:47,650\NAnd the Jupiter notebook runs the cells in the order we ran them. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,40\N00:03:47,650 --> 00:03:59,150\NAnd it shows us here that number. But in in. Is the order in which that cell was run nine, 10, 11, if we so we've changed the value of of X here. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,41\N00:03:59,150 --> 00:04:05,240\NIf we go back up and rerun this cell, it's going to use the new value of X. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,42\N00:04:05,240 --> 00:04:11,720\NThis is important to keep in mind, and it's an easy way to get your notebook very confused if you've been running cells out of order. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,43\N00:04:11,720 --> 00:04:17,750\NWhen we're developing a notebook we're working on, a data analysis will often run things out of order, try things out. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,44\N00:04:17,750 --> 00:04:28,520\NBut it's important to keep things clear and consistent in your notebook so that if you were to rerun the notebook from top to bottom, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,45\N00:04:28,520 --> 00:04:33,050\Nit runs and produces the correct results. You can do experiments, but before you go, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,46\N00:04:33,050 --> 00:04:44,150\Nsay to submit your notebook to me in an assignment or before you go to to submit it to your client or use it for your final analysis. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,47\N00:04:44,150 --> 00:04:46,880\NMake sure that if you rerun it from top to bottom, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,48\N00:04:46,880 --> 00:04:51,410\Nyou get the right results so that you can be confident that you're actually computing the results you want. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,49\N00:04:51,410 --> 00:04:56,840\NAnd there's not something that's just an artifact of the order in which you happened to run the cells. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,50\N00:04:56,840 --> 00:05:02,900\NSo we've seen numbers do seem variables that we can also write strings. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,51\N00:05:02,900 --> 00:05:06,500\NWe can put them in quotes. Python takes both double and single quotes. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,52\N00:05:06,500 --> 00:05:10,660\NThere's no difference between them. The backslash is an escape character. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,53\N00:05:10,660 --> 00:05:20,740\NSo if we want to have double quotes and a double coded string, we can we can do that with by by prefixing them with a backslash. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,54\N00:05:20,740 --> 00:05:25,870\NWe can one of the fundamental string operations is to contaminate two strings, and if you have strings, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,55\N00:05:25,870 --> 00:05:32,130\Nthe plus operator, it's the same operator we use for additions and with numbers, it can cat Nates the two strings. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,56\N00:05:32,130 --> 00:05:37,120\NSo hello. Plus world is Hello World. There's a bunch of other operations. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,57\N00:05:37,120 --> 00:05:41,080\NFor example, split separates a string into a list by default. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,58\N00:05:41,080 --> 00:05:45,550\NIf you don't tell it how to split it, it uses whitespace. So this is going to split the string. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,59\N00:05:45,550 --> 00:05:49,330\NHello Space World into a list of two items. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,60\N00:05:49,330 --> 00:05:57,710\NHello and world. So Python is strict about types, every object, every value has a type. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,61\N00:05:57,710 --> 00:06:07,640\NAnd it won't auto convert them. So if you've programed in Perl or JavaScript or P HP and you take a string and a number and you can cabinet them, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,62\N00:06:07,640 --> 00:06:11,630\Nit tries to convert the number to a string. Python won't do that. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,63\N00:06:11,630 --> 00:06:19,670\NSo if we do this, we try to add a number to a string. It's going to give us a type error and a type error and tells us what's going on. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,64\N00:06:19,670 --> 00:06:24,890\NOne of the skills you're going to need to develop in this class is the ability to read error messages. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,65\N00:06:24,890 --> 00:06:30,830\NAnd this error message tells us a cup, a few important things. It tells us that the error is a type error. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,66\N00:06:30,830 --> 00:06:36,100\NOther errors you're going to see are value errors, index errors, key errors, et cetera. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,67\N00:06:36,100 --> 00:06:42,570\NBut this is telling us a type error, which means that we're trying to do something with the wrong type of data. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,68\N00:06:42,570 --> 00:06:46,470\NIt then tells us two other things. It gives us this trace back of the code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,69\N00:06:46,470 --> 00:06:53,730\NSo it shows us where in the code it went wrong. The only thing we're doing here, we're not calling in many library functions or anything like that. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,70\N00:06:53,730 --> 00:07:01,620\NWe're just trying to add a string in a number. We have our line of code. So it's showing us that it happened on line one, Maroon plus five, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,71\N00:07:01,620 --> 00:07:07,890\Nand then it tells us a little bit more about the error can only concatenate stir, not end to stir. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,72\N00:07:07,890 --> 00:07:12,720\NSo what this is telling us is that and Cat Nation only works on strings. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,73\N00:07:12,720 --> 00:07:18,670\NYou can't concatenate things that aren't strings to a string. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,74\N00:07:18,670 --> 00:07:21,890\NAnd what we have here, we have a string and we have a number. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,75\N00:07:21,890 --> 00:07:33,170\NSo if we want to if we want to to put five at the end of our our string, we can convert it with the Sturr function. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,76\N00:07:33,170 --> 00:07:40,580\NSo Sturr is a function that takes an object and returns a string representation of that object intended for human consumption. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,77\N00:07:40,580 --> 00:07:48,580\NSo if we do this, then we get our strength, then that will concatenate correctly and we get the string Maroon five. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,78\N00:07:48,580 --> 00:07:55,480\NSo we've now seen three different kinds of operations that we can perform on python values. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,79\N00:07:55,480 --> 00:08:03,400\NWe've seen an operator like Plasty Duck, the binary operators that go between their two operands so we can say six plus seven. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,80\N00:08:03,400 --> 00:08:10,600\NThere's quite a few of these operators. We've seen a function which in this case, the function comes from a module. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,81\N00:08:10,600 --> 00:08:15,010\NSo ENPI dialog and a function takes a value in return some other values. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,82\N00:08:15,010 --> 00:08:21,370\NWe can compute the natural log of 10. And we've seen a method which is a function that's attached to an object. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,83\N00:08:21,370 --> 00:08:24,820\NSo speed up. So the log function isn't attached to any particular object. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,84\N00:08:24,820 --> 00:08:28,990\NIt's just a function hanging around. But the method. Hello. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,85\N00:08:28,990 --> 00:08:36,630\NSo split is going to work on the hello world. String and. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,86\N00:08:36,630 --> 00:08:48,290\NAnd split it. So we've seen a method. If you're familiar with Java, they're like methods in Java and they operate on a particular. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,87\N00:08:48,290 --> 00:08:55,590\NThey operate on a particular object. The Java equivalent of a python function would be a static method. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,88\N00:08:55,590 --> 00:09:02,240\NWe've seen these three different kinds of operations in this class. We're going to learn how to write functions. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,89\N00:09:02,240 --> 00:09:07,880\NEventually, we're going to learn how to write our own methods. But we aren't going to need that for the vast majority of this class. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,90\N00:09:07,880 --> 00:09:14,150\NYou can also define how operators work on custom, on custom data types in Python. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,91\N00:09:14,150 --> 00:09:19,310\NWe're not going to do that. It's learning to do that is outside the scope of this class. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,92\N00:09:19,310 --> 00:09:25,520\NBut it is how some of the libraries that we're gonna be using work on the inside. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,93\N00:09:25,520 --> 00:09:29,570\NSo we've got these different kinds of operations. There's a few other things that we can do. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,94\N00:09:29,570 --> 00:09:35,840\NSo a few other data types you can work with. So now that split method, it returns a list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,95\N00:09:35,840 --> 00:09:41,780\NHello, World. And in Python, we write lists with square brackets and commas separating the values and we can write them. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,96\N00:09:41,780 --> 00:09:46,870\NSo I can make a list that consists of these three values. Martin Cross and Grip's. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,97\N00:09:46,870 --> 00:09:50,530\NI can also save a list of variables. Now I have the variable Rowdy three. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,98\N00:09:50,530 --> 00:09:55,420\NThat contains a list of these three names. We can then, though, add to the list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,99\N00:09:55,420 --> 00:10:03,400\NSo if too rowdy three that append Vogul. And we're going to now have a list that contains Martin Cross scripts and vocal. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,100\N00:10:03,400 --> 00:10:09,790\NNow, notice that in this code I did Rowdy three at a pen and then I just wrote Rowdy three. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,101\N00:10:09,790 --> 00:10:21,480\NThat's because if you remember from the previous video. Jupiter shows the value of the last expression in your cell. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,102\N00:10:21,480 --> 00:10:24,960\NRowdy three A doesn't return anything. The list append method. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,103\N00:10:24,960 --> 00:10:29,250\NAdd something to the end of a list and actually it modifies that particular list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,104\N00:10:29,250 --> 00:10:36,130\NWe don't have a new list here. It modified our list object and and stuck Voegele at the end of it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,105\N00:10:36,130 --> 00:10:37,890\NAnd it doesn't return anything. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,106\N00:10:37,890 --> 00:10:45,600\NSo instead, what we're gonna do, what I often like to do when I do an operation like this is then at the end of the cell, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,107\N00:10:45,600 --> 00:10:51,150\NI just put the variable that I've been modifying so that it'll then show me what's currently in the variable. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,108\N00:10:51,150 --> 00:11:02,190\NSo we can see that after we appended Voegele to the list stored in the variable Rowdy three, that list now consists of four items. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,109\N00:11:02,190 --> 00:11:09,010\NAnd yet the list now consists of four items and includes our new entry at the end. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,110\N00:11:09,010 --> 00:11:13,960\NSo lists are indexed, starting with zero so rowdy, three of zero gives us Martin. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,111\N00:11:13,960 --> 00:11:21,820\NWe can index backwards from the end, rowdy three negative one gives us voegele a slice, takes multiple elements from a list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,112\N00:11:21,820 --> 00:11:27,610\NSo rowdy three one Colen three gives us element the element that one and two. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,113\N00:11:27,610 --> 00:11:31,630\NWhat it does is it gives you it starts at the first index of the slice and gives Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,114\N00:11:31,630 --> 00:11:36,940\Nyou all of the elements up to but not including the last element to the slice. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,115\N00:11:36,940 --> 00:11:42,130\NSo. Zero is the first item, one is the second item. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,116\N00:11:42,130 --> 00:11:46,120\NSo it's giving us items one and two and then three is one past the end. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,117\N00:11:46,120 --> 00:11:52,810\NThese kinds of half open intervals. We call this a half open interval because it includes the left side and not the right side. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,118\N00:11:52,810 --> 00:12:01,510\NThey're very, very common when we're using zero based indexing in a data structure because it's a very convenient way to express a range. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,119\N00:12:01,510 --> 00:12:08,240\NAlso, the length of the range is. The end, minus the beginning, three, minus one. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,120\N00:12:08,240 --> 00:12:17,920\NIt's going to give us a list of length to. One more thing we can do here is the land function. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,121\N00:12:17,920 --> 00:12:23,740\NIs a standard python function that will give you the length of anything that has a length like a list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,122\N00:12:23,740 --> 00:12:29,680\NA number of other data structures have links. Most data structures that can contain other data structures will have a length. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,123\N00:12:29,680 --> 00:12:34,210\NIt will also work on a string. But the length of rowdy three is currently four. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,124\N00:12:34,210 --> 00:12:41,950\NSo we can also loop over a list. So this list, this loop here is going to loop for each person in the list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,125\N00:12:41,950 --> 00:12:45,960\NStored and rowdy three. It's going to print the person. So we get our four people. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,126\N00:12:45,960 --> 00:12:52,530\NMartin Cross scripts and vocal. What if we want to know the position of each item in the list as we go through the loop? Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,127\N00:12:52,530 --> 00:13:02,910\NThe enumerate function wraps a list and returns the list, but also the position in the list as we go through the loop. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,128\N00:13:02,910 --> 00:13:07,530\NAnd then this string here, this. That's prefixed with an F. We call this an F string. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,129\N00:13:07,530 --> 00:13:10,290\NAnd when you put a F right before the opening quote of a string, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,130\N00:13:10,290 --> 00:13:15,810\Nyou can then use squiggly braces and variable names to include variable values in the string. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,131\N00:13:15,810 --> 00:13:21,000\NIt's one of the ways that Python lets you easily build up strings that contain additional data. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,132\N00:13:21,000 --> 00:13:25,740\NAnd so we're going to we're going to run this loop. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,133\N00:13:25,740 --> 00:13:31,500\NAnd now we see each. Each person is now prefixed with their member number. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,134\N00:13:31,500 --> 00:13:35,490\NAnd it's starting from zero because as we saw before, Python always starts from zero. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,135\N00:13:35,490 --> 00:13:43,700\NSo the first one is members zero. And this enumerate function is just giving us the positions along with each item. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,136\N00:13:43,700 --> 00:13:50,670\NPython for loops operate over what what it calls iterable, something that iterable just feeds an object that you can use in a for loop. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,137\N00:13:50,670 --> 00:13:55,770\NLists are iterable, but if you want to loop over a sequence of numbers like you might in Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,138\N00:13:55,770 --> 00:14:00,780\NSo you want to go from zero one and two, you use a range. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,139\N00:14:00,780 --> 00:14:09,750\NSo this is going to print zero one and two, because, again, the python does not include upper bounds of ranges and slices by default. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,140\N00:14:09,750 --> 00:14:16,950\NSo we're going to go zero, one and two. So a tuple is another container. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,141\N00:14:16,950 --> 00:14:21,990\NIt's like a list, except its size can't be changed. It's used for representing things like pairs. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,142\N00:14:21,990 --> 00:14:28,470\NSo I'm going to create a variable called coords and I'm going to store the tuple three five in it coords. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,143\N00:14:28,470 --> 00:14:34,020\NSub-Zero, then, is the first element of the tuple three chords. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,144\N00:14:34,020 --> 00:14:46,170\NOne is five. If we did the Len of this tuple, we would we would get would get to a tuple can be unpacked by unpacking the tuple we take it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,145\N00:14:46,170 --> 00:14:55,500\NSo this tuple has two elements and we can say X, comma, Y to unpack the tuple into two different variables and then X is going to be three. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,146\N00:14:55,500 --> 00:15:03,300\NSo the parentheses with the comma packs the tuple and assigning it to variable separated with a comma unpacks the tuple. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,147\N00:15:03,300 --> 00:15:11,670\NThe tuple size has to match. So if we say X, Y, Z of coords and try to run that, it's going to tell us not enough values to unpack. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,148\N00:15:11,670 --> 00:15:18,790\NIt expects three values X, Y and Z. But coords only has two values. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,149\N00:15:18,790 --> 00:15:25,960\NA dictionary is another data structure that maps, keys, often strings, but not always you can. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,150\N00:15:25,960 --> 00:15:34,600\NYou can use numbers, tuples, any data structure that can't be changed, you can use as the key for a string or for a dictionary. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,151\N00:15:34,600 --> 00:15:38,710\NAnd so we're going to map some different animals to what they eat here. We created a variable. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,152\N00:15:38,710 --> 00:15:44,590\NAssigning to a variable doesn't return a value, so there's nothing to print here. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,153\N00:15:44,590 --> 00:15:49,690\NAnd then we can look up a value by its key. So we say Dietze of rabbit equals plants. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,154\N00:15:49,690 --> 00:15:57,550\NAnd that gives there like lists, except we can look them up by any key we want instead of having to look them up by a position. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,155\N00:15:57,550 --> 00:16:02,150\NSo everything in Python is an object which has a type. We saw this when we saw the type error. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,156\N00:16:02,150 --> 00:16:06,320\NWe try to to try to add the number five to the string maroon. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,157\N00:16:06,320 --> 00:16:11,950\NThe Sipes we've seen in this video are integers, strings, lists, tuples and dictionaries. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,158\N00:16:11,950 --> 00:16:13,570\NThere's a lot more to do with these. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,159\N00:16:13,570 --> 00:16:21,100\NI refer to you to the readings and also we're going to be introducing a various features of them as we go throughout the class. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,160\N00:16:21,100 --> 00:16:27,100\NNow, another thing that's important to understand is that in Python variables, store references to objects. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,161\N00:16:27,100 --> 00:16:31,210\NThis is how Java works as well. But this matters, particularly for mutable objects. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,162\N00:16:31,210 --> 00:16:42,100\NSo we have our list. Rowdy three. Now, if we assign the list to another variable, rowdy five and then we add Amanda and we print routing. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,163\N00:16:42,100 --> 00:16:47,980\NWe show the result of rowdy five. OK. We have our list. Now we've added Amanda to the end of it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,164\N00:16:47,980 --> 00:16:52,660\NThe rowdy five and rowdy three variables are references to the same list objects. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,165\N00:16:52,660 --> 00:16:59,110\NWe only look at Rowdy three. It's now going to show five elements, including Amanda. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,166\N00:16:59,110 --> 00:17:05,050\NBecause when we assign the variable, it doesn't make a copy of the list. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,167\N00:17:05,050 --> 00:17:09,140\NAll it does is it creates another variable that also refers to the list, too. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,168\N00:17:09,140 --> 00:17:15,220\NWe modify this list, object and append modifies the object, what we call in place. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,169\N00:17:15,220 --> 00:17:21,050\NThat means it modifies the object itself. It does not return a new object. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,170\N00:17:21,050 --> 00:17:30,200\NIt the object changes and any variable that's referring to that object gets the change of this in-place Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,171\N00:17:30,200 --> 00:17:34,700\Ndistinction is going to be important throughout the semester because some of the libraries we use, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,172\N00:17:34,700 --> 00:17:46,350\Nthey they offer options to whether you want to modify something in place or whether you want to return a new object that has the new data. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,173\N00:17:46,350 --> 00:17:50,010\NSo there's a variety of ways. Resources to learn Python. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,174\N00:17:50,010 --> 00:17:57,270\NI'm going to be making some videos, but we're not going to have time in the videos to go into every piece of python you might need. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,175\N00:17:57,270 --> 00:18:04,300\NThe tech chapters two, and I'm going to be writing some resources, chapters two and three in the text book are going to. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,176\N00:18:04,300 --> 00:18:10,380\NThey talk about basic python operations and data structures. There's the Python tutorial that I'm providing you a link to. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,177\N00:18:10,380 --> 00:18:16,920\NThat's a relatively comprehensive tutorial from the Python developers about the key Python language features. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,178\N00:18:16,920 --> 00:18:22,740\NIf you really want to dove in depth, there's a book, Learn Python the Hard Way, which is quite comprehensive. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,179\N00:18:22,740 --> 00:18:30,510\NI'm also going to be providing in the resources section of the class site some additional notebook's that walk Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,180\N00:18:30,510 --> 00:18:36,600\Nthrough and demonstrate different Python features and give you information about the different operations. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,181\N00:18:36,600 --> 00:18:42,240\NFor example, I'm planning on one such notebook that goes over a bunch of different things you Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,182\N00:18:42,240 --> 00:18:48,540\Ncan do with lists more than I've had a chance to get into in in this video. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,183\N00:18:48,540 --> 00:18:55,680\NSo to wrap up, Python supports many different data types. Everything's that object and variable store references to objects. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,184\N00:18:55,680 --> 00:19:03,180\NIf you do an operation that modifies an object, all variables that refer to the same object are going to get are going to see the change. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,185\N00:19:03,180 --> 00:19:07,920\NYou can perform a number of standard arithmetic operations on python variables. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,186\N00:19:07,920 --> 00:19:17,333\NAnd there's many, many more operations that we're going to be seeing as we go throughout the semester. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,