 In this lesson, we'll be providing an introduction to the Python programming language that you'll be using throughout this course. If you're not familiar with it, Python is a general purpose programming language, meaning you can use it to do a whole lot of things, not just cryptography. It's also very popular to use in data science, server architecture, and all bunch of different kinds of projects. It was designed to really emphasize code readability, meaning that people usually read code more than they actually run code when you're a programmer, so you want it to be easily readable to understand what it's doing. And it helps do this by having significant indentation and white space constraints, meaning that whether your code starts on the first character of a line or the fourth character of a line makes a big difference. And we'll see as we learn more and more about how to program in Python, how picky Python can be about where your code is in a line. This language can be object oriented if you're familiar with object oriented programming. If not, no worries, we're not going to do any object oriented programming in this course, but it might set you up to learn that in a subsequent course. And its goal in its entire language is to help programmers write clear logical code that works for both small and large scale projects. So with the reason why we use Python in this course is that not only does it help you solve the problems of cryptography, but also sets you up to learn how to use the same programming language to tackle other problems maybe in your schoolwork, maybe in a future job, or just for fun. When you are programming, if you're brand new to programming, commands are have to be given to the computer one line at a time, and the computer runs them in order from top to bottom. So here we have four sample lines of code that even if you've never programmed before, you might be able to make a guess about what they're going to do. The computer gets the first line of code and it assigns a value of nine to the variable that is named A, then it assigns the value of four to the variable named B, then it assigns the sum of those variables A and B to the variable named total, and then it prints the result out so it prints the value currently assigned to the variable named total, and we get the result of 13. So working from its top to the bottom of this block of code, we get a end result. Now, if you had maybe a formatting error or an incorrect command provided to Python, that code is going to stop running and you're going to get an error message displayed. The most frequent error message that we'll see is called a syntax error, meaning that you gave the computer a command that the Python programming language didn't know how to interpret, it didn't know what to do with that command. In this case, I've taken out the plus sign and replaced it with the word plus written out in characters, and that's not something that Python knows how to do. Maybe there's another programming language that that's how you do it, but that's not how Python does it. So you can see that you're going to get this big red box showing up, and you have that little arrow up arrow symbol just under the letter P inside the red box trying to be helpful in letting you know where Python thinks it's found the error that you've given it. Hopefully you don't see too many of these throughout your time in this course, but it's very common to see these types of errors in the first few weeks that you're learning a new programming language as you start to understand the commands that you'll be using to make the computer do what you want. One note about programming in Python in this course is that we're going to be using a Jupyter Notebook or otherwise known as a Python Notebook in order to do our programming. This is a kind of newer way to think about programming, and it's different than perhaps if you've programmed it what's called an IDE or a full editor. I've got screenshots here that show the differences between the two visually. The one on the left is called Microsoft VS Code, a very popular code editor that is made by Microsoft. It is free. It is open source. You're welcome to download and play around with it. And you can see we've got that same code written out there on the left. On the right-hand side is what your environment that you'll be programming in looks like. There are a few big differences between these two programming environments. We'll go over those in just a second. I think that when you want to use something like Microsoft VS Code, you're probably working in teams to make big products. You want all the bells and whistles. It's really powerful and it's great. But it's not necessarily intuitive to learn, which is why we use Jupyter Notebooks or Jupyter Lab. We'll also call that data hub is a lot of kind of synonyms for what we call it. That's the one on the right. You could open this in your web browser. There's nothing to install. And we'll see that there are a few other nice things about the Jupyter Notebook environment. The first one you might be able to see already on the screen is that instead of just code, you can have other things on the screen. You can see the word demo and then there are some directions. So the big differences between using Python Notebooks like Jupyter Notebooks and our data hub is that notebooks allow you to have text and images to be interspersed around your code that allow to provide additional directions or context as you're working in your notebook. Notebooks also allow you to just run small parts of your code. You'll see in the next couple of days that your code is not just one big cluster of text. You can put it in these little cells or boxes that can compartmentalize your code into just little bits and pieces. You don't have to run the whole thing at once. Just the bit that's important to you at that time. And the last big difference between a notebook environment and the full-fledged programming environment is that notebooks will automatically print out the result of your last line of code in the cell. If that last line of code, some sort of calculation or computation or maybe the output of a function, it will just automatically show it to you. Notebooks are meant to be exploratory programming places, so it's kind of assumed that you're going to be interested in the results of a lot of your calculations. So by default, notebooks will just show you a lot of those results. Whereas in your full programming environment, you may have to specifically ask the computer to show you the result using a print statement. So let's learn about some of the different ways that we'll be programming. In this introductory lesson, you're not going to actually need to be able to program anything. We're just setting a big picture idea about what you can expect to learn about throughout this course. So you don't have to pay too close attention to the syntax, but just take in the big ideas. We'll be using a lot of numbers in our programming since this is a math course. And the first type of number you'll want to learn how to use in Python is called an integer. Also abbreviated as an int to the computer, int. It is just like an integer you'll learn about in math class. So whole numbers, they can be positive, they can be negative, but they'll never have a decimal point displayed to you. And they can be any size. We'll see that some numbers in pythons or some types of data are limited, but not integers. Integers, you can make as big as you want as long as your computer has enough storage to represent them. We'll use integers in this course a lot of times to represent letters. So we'll perhaps say the letter a is equivalent to the number zero and the letter b is equivalent to the number one and so on. We'll also use integers to count the number of letters that appear in a particular message. And we'll also use integers a lot of times to be the key for a particular encipherment technique. So our particular algorithm. The other type of number we'll use pretty frequently in this course is called a float to the computer, also known as a floating point number. Or maybe if you're a mathematician, you prefer to call that a real number. So this is any number that you could use that can be represented using scientific notation. Numbers could be fractions, it could be decimals, it could be numbers like the number pie, any of those real numbers. Now, because these numbers are a little more complex, they do have some limitations. They can be big, but not infinitely big. They only have precision to about 15 or 16 decimal places, which for most things you're doing is probably fine. And when you do some arithmetic with these floating numbers, sometimes those 15th or 16 decimal places can be inaccurate. They can be wrong. And that's just due to some strange algorithms and round off errors that occur behind the scenes. But typically at that 16th decimal place, it's not going to impact any work that you're doing. Floats in this course are often going to be used for proportions of a letter and a message. So instead of saying there's five letter A's, you might say, well, 0.12 of the message is ease or about 12% of the message. So we'll be using them to represent that and to perform other statistical calculations. We can perform operations between these numbers and many of these might be intuitive for you to understand. So the addition operation, we use the plus symbol between two numbers. Subtraction symbol the same way. Multiplication symbol, we use the asterisk, so the shift and then the number eight on your keyboard. Division, we use the slash. There is no kind of division with the horizontal line with the dot above and below that maybe you're used to writing by hand, but we will use the division symbol here. Notice that even when you divide two integers, the result is a float. It'll always return back to you. So it's going to be mindful of if you need your division to be a integer when you're done, perhaps because you want it to represent a letter and an alphabet. You have to convert that float to an integer and we'll learn how to do that later in the course. In this class, we'll also use the mod operator quite a bit, which is the percent symbol. We'll get more into the mod operator later. But for now, you can think about this as the remainder that is obtained when you divide by a number. So, for example, if you were to say seven divided by four, four goes into the number seven one time, but it has a remainder of three. So the result of that operation is three. We'll use that quite a bit in this class. The exponentiation instead of the carrot, so shift six in Python, we use two stars. So star star. That may be the hardest one to remember because if you're used to typing math commands on a computer, you're probably already used to just using the carrot. So here you can see that two star star three is eight. And then on the right hand side is just an example of using some of these together. So one point eight times 10 to the three hundred and eighth power turns out that is the largest number that Python can hold. And when you get to that size, it actually can't hold that number. It will return back infinity or INF for short. So that's just to show you that's the that's the extent that floating point numbers can be represented in Python integers can go bigger. But for floats, that's it. We saw this in the example code block I demonstrated on an earlier slide, but we'll hit this again. A lot of times you'll be calculating numbers or creating data that you'll want to store that you can use for future calculations. You can do that by assigning that value to a name or a variable in Python. We do that using in a single equal sign and it's called an assignment statement. So this block of code will assign the value of nine to the variable named a the value of five stored to the variable named B and so on. And then you can use those variable names to refer back to the values without having to actually remember what those values are. It's good practice to use descriptive names for your variables. So in this case, bad practice A and B don't exactly tell me what's going on. And the reason why we do that is that future you a day a week a month from now, when you go back and look at your code, you probably won't remember why you labeled that thing Q three three days ago or a week ago. So using descriptive variable names will help you remember and also help others who might be looking at your code. There are some naming conventions that are outlined by the Python community and what's called pep eight. You can click the link on the Google slides here to read more about that. But these are just kind of best practices. These are not rules. The computer will still run and show you the results of your code. But if we can follow these rules, it's going to make your code very easy to read for others. So here are some naming styles that are kind of outlined in this document here. The first one we've already seen is a lowercase single letter. We could use an uppercase single letter for a variable name. You could use all lowercase, but more of a word. If your variable name maybe needs multiple words, we're going to use all lowercases and then underscore in between the words to help make that easier to read. Some variable names are depending on what you're storing to them. We'll use an uppercase letter and then again underscores instead of spaces. This is a method that's called capitalized words or cap words or camel case. There's a few names for this camel case because it kind of has the ebbs and flows like the back of a camel. We can use mixed case, which is almost the same thing as as capitalized words, but just the first letter is lowercase. And then capitalized words with underscores in between. Again, the first letter of each of those words is capitalized and then instead of spaces, we use underscores. So there's some conventions that go along when you should use each of these. You don't have to worry about it too much, but we'll go over them just real quick for the ways that you might see them in this course. I will always try and use these conventions when I am creating code that you'll interact with. If there is a value that you think will be constant throughout the entire project or code that you're working on, we'll typically use those in uppercase letters and underscores in between those if it's multiple words. So for example, in max overflow or a total. In this class, a lot of times at the beginning of a code will define an alphabet that we're working in, maybe just a to z. That would be something that remains constant throughout all of your code. So you could create that as a variable with uses only uppercase letters. If you write your own functions or define your own variables elsewhere, that can just be more general purpose. We'll typically use lowercase letters and then lowercase with underscores if you need multiple words. That's true whether that variable is holding a float in int text. It's true with your naming a function. We just want lowercase with underscores. Other programming languages have different conventions, but this is what's been decided on for Python. Now there are some requirements for naming your variables and functions and things like that. And if you don't follow these, your code won't run, but they're pretty simple to remember. For Python variables, they must start with a letter or the underscore character. So you can't start them with a number. They must only contain alpha numeric characters and the underscore. So that's like a to z uppercase and lowercase are fine. You can use numbers as long as they're not the first character in your variable name. And just remember your variables are case sensitive. So if you have all lowercase a g e uppercase a g e and then all uppercase a g e. Those are three different variables to Python. So just be very mindful of that that you're consistent in the way that you name your variables. That's part of the reason why best practices. Hey, you know what? Let's just call them all lowercase unless they're constants and then they're all uppercase. Easy to remember and not get mixed and matched. Another type of data that we'll use almost all the time in this course is what's called a string or str to the computer. And a string value is just a snippet of characters and they can be any length. So unlike an integer or a float, we maybe have some restrictions on their size. Strings can be at any size you want a single character, an entire word. It could be a sentence or two in there. Notice they can hold numbers or punctuation. But when we denote them into the computer, we they'll always start and end. With either a single quote or a double quote. They can contain numbers, but those numbers actually then lose their numerical value if you store them as a string instead of as a float. This now it's just a character. It's a glyph. It's just it's just some writing between those quotes. So it loses the numerical values. Typical ways we'll use strings in this course for storing our messages, either a plain text message or a cipher text message that we're working on. We don't really use strings too much else in this course. Okay, coming down the home stretch is a few things that you'll learn how to do. This will happen probably a few weeks into the course to help control your code. We're going to start to start things simple. But as our programs and code gets more and more complex, we might want to have to do other things with that code than just say add two numbers together. So some ways that we'll do that are what's called conditional statements. You might refer to them shorthand as if else. And that allows us, as you can see here, is that if a certain criteria is met, do one thing. Otherwise, do this other command. Very helpful if there's different parts of your code base that you want to run under different circumstances. We'll also learn how to write loops. This is an example in the code box here of a while loop. And that allows you to repeatedly run part of your code until a certain condition is met. So in this case, the variable a starts out being assigned to the value of zero. And I want something to happen while a is less than three. What do I want it to do over and over and over again? I wanted to print the value of a and then reassign the value of a so it's a plus one. So just make it one bigger. So you can see when I run this, it's actually going to show the number zero. The first time it runs that those two lines of code and then it will show the value one and then it will show the value two. And now a is bigger than three or actually equal to three. So we'll no longer run the code and it's done. You'll learn more about how to write these loops and how to apply to what we do in this course later on. But that's the big idea right now is that you can run the same piece of code over and over again pretty easily. And lastly, we'll use functions all the time in this course functions are way for you to use complex bits of code without having to copy and paste it from somewhere else in your project. You can just refer back to that part of code by name. Python has some built in functions. Here's an example of one that's called max where if you give it a collection of numbers that we call a list. It'll tell you what the maximum value is contained within that list. You can actually write your own functions to do whatever you want. So we'll be writing functions in this course to like say in Cypher a piece of plain text using the Caesar Cypher or decode an RSA encrypted message. So we'll write right our own and then that'll let you also use code that other people write. So it's really powerful ways to do a lot of complex bits of code without having to go back and pull those individual snippets back out from earlier in your program. So that is a brief introduction to Python. You will be learning alongside the cryptography over the next few lessons how to dig in and learn more about each of those individual pieces and you'll soon be able to put them all together to start encrypting and decrypting messages.