Placeholder Image

Subtitles section Play video

  • All right.

  • Hello, world.

  • This is CS 50 Live.

  • My name is Colton.

  • Argument.

  • Today we're joined by the man himself.

  • David Malin.

  • Hello, everyone.

  • Good to see everyone on stream and not just in the chat today.

  • Um, we're doing something pretty cool today.

  • Pretty fun.

  • We're doing a from scratch of python tutorial.

  • And my understanding is that you have actually brought some questions and topics that challenges e.

  • Oh, I haven't seen we're gonna implement, and I'm going to be a proxy to somebody who maybe is learning for the first time.

  • Indeed.

  • So I'm gonna pretty much assume that Colton may or may not actually know Python.

  • And so along the way, we'll try to solve some problems actively, by a coating, will pull things up by Google or stack overflow as we go.

  • And frankly, try to approximate the experience that Colton and I arguably do every day when we're writing code to sort of figure out problems that we've got it solved.

  • Sure.

  • I guess maybe we should start off first off.

  • But maybe explaining what Python is, folks, we've advertised.

  • This is sort of an experience for people who may not have even programmed at least have not programmed in python before.

  • Yeah, so why don't we assume that no one here is really that familiar with Python?

  • But if you are, that's fine.

  • Hopefully, we can fill in some gaps in your knowledge, stop us at any point by the chat.

  • If you have a question, there's no dumb questions here.

  • If we taken for granted that you know what some concept is or some function is, or some feature just chime in and say, Hey, everyone would What did they mean by that?

  • So that we can answer here on stream.

  • So python is very popular programming language.

  • It's, ah, little different from languages like C and C plus plus and a few others that you would traditionally compile.

  • Recall that if you've ever programmed in one of those languages, you have to actually run some program called a compiler to convert your source code, the text that you write thio machine code, the zeros and ones that the computer actually understands.

  • Nice thing about Python is that we don't have to do that.

  • What is you want to characterize python for folks to distinguish it from that process?

  • Yeah, no I mean, pipe bombs.

  • Nice.

  • It's essentially it runs almost in this.

  • It's called a virtual machine, but it's almost like having a computer inside a computer.

  • And it executes these with a traditional programming language.

  • You're writing text, and I'll switch over to my computer here.

  • Just that we could maybe frame this visually a little bit better, but not chrome invesco.

  • By the way, this is my text editor of choice just V s code you need in order to write any source code, some sort of text editor application, you could even use something like text edit, for example, if I pull it text edit on my Mac, it's not sure that email is there, but I think that might have been from another stream.

  • But essentially what you do is you.

  • You have some program that you can write text into, and usually you don't want to write it in what's called rich texture.

  • You have formatting you rented in plain text like this, and you write your instructions to the computer a bunch of lines.

  • No, this isn't quite nice this year.

  • Unless you don't know how to write good variable names, things might look This might be some people's Python code, but you essentially go through and you write a set of instructions for the computer like this top down and the computer will execute them.

  • But computers don't understand arbitrary textual information.

  • The locator can only speak in certain languages.

  • Computer law, specifically insulin machine coaches finery, which we talked about his 51 another, more underlying principles of that.

  • David has an awesome series of lectures on our YouTube channel.

  • But long story short, somewhere along the line you have to convert all your instructions in tow something that the computer can understand.

  • And with a traditional language that concluded Before you do this with the help of a compiler, it'll take this text and translating it into, you know, they basically bits, which is the computer's native sort of tongue.

  • But how's Python different here?

  • It is different in that it doesn't actually perform this step explicitly along the line is still actually happens, but it basically translates all the lines that you've written when you just load the script into a program that is itself called Python.

  • Yeah, you can think of Python, then is an interpreter.

  • This sort of middle man.

  • That translates between what you rights and what the computer actually understands.

  • So you can think of pipe on.

  • The program, which will run in just a couple of minutes, is a program that reads your own code top to bottom left to right and just does what you say.

  • You don't have to actually use something like visual studio or GCC or clang or any number of other compilers.

  • Explicitly, all of that sort of happens for you automatically, thanks to the interpretation process along the way, and you can even fire up.

  • Let's see if if you have it installed on your machine, for example, here I have a pipe on three.

  • There's two different versions of Python three.

  • A long story short Python three is the new way.

  • It's the way that is going to be the official way very shortly as 2020.

  • But if I type pipe on three and my command line, if you have it installed, you can see that I actually have this sort of prompt here these three arrows, which and I can actually type in instructions and it will immediately execute things.

  • For example, if I wanted to say, uh, print David J.

  • Malin like like this is to me that I type it correctly.

  • It'll actually literally do it without needing to do that intermediary compilation stuff.

  • Yeah, relation.

  • This is an interactive interpreter, so we'll just do what you say.

  • The downside, of course, is that we're not really saving any of our work along the way.

  • So it's better generally to write your programs in an actual text editor like the S code or sublime, or Adam or something else, so that you can save your code and let the interpreter run it and re run it again and again.

  • So why don't we go ahead and do that?

  • You want to go ahead and open up a blank editor window?

  • So for those of you following along at home, if you want to go ahead and Google the S code or visual studio code, you're welcome to download the same program for free Adam Sublime text in no pad plus plus and a bunch of others are very popular on Macs and PCs and Lennox machines.

  • But odds are, if you're tuning in, you probably have some form of text editor, but if not feel free to try one of those, and then you should also do.

  • If you don't have it already is, make sure your computer, if you do want to follow long, has python installed.

  • So again, Python is not only a language, it's an interpreter, a program that will understand your use of that language.

  • And if you go to python dot org's slash downloads, you'll find yourself at the official website, where you can download the Python Version three installer to make sure that you have that on your machine.

  • Depending on how your machine was configured, you may have Python already as cold and said, but it might be an older version.

  • Python, too, that's officially gonna be end of life.

  • Soon, that is, it's being phased out in favor.

  • Finally, of Python three.

  • So everything we do today, it's Python three specific, But beware because when you're Googling when you're looking at stack overflow, there's a lot of good answers to old pipe on code out there so you don't want to be led.

  • A stray serial has a sweet comment, says David.

  • Because of you, I stopped playing video games all day.

  • Learn to code.

  • I now have a real job at an E.

  • Come, come.

  • Wow, that's amazing.

  • I see Andres taking exception to the fact that we haven't promoted Idol.

  • There's a few other I.

  • D Ys and editors as well, this is not an exhaustive list.

  • What's nice about things like V s code is that they are first and foremost a text editor and you can layer more features on top of them.

  • Somebody asked what he s code Am I using?

  • I think I'm using Dracula right now.

  • It's just that at the end of the last stream, but I actually prefer the noctis theme so real quick, just the important stuff out of the way.

  • First, this is nothing to do with python switch to knock this color.

  • And that's the one that I recently have liked.

  • But they all a lot of the defaults look very nice.

  • And you want to let's go ahead and get rid of the Explorer for now.

  • But let's just go ahead and save.

  • This program is hello dot pie.

  • So hello is gonna be the name of the program.

  • Pie indicates that this is a python program.

  • You don't need number three anywhere in there.

  • You still just use dot pie.

  • So our first program, Well, let's keep it super simple and literally write the program that everyone in the world seems to start writing code in, which is just hello world.

  • So instead of David J.

  • Mainland, how would you go ahead and python and just write a program that prints out literally Hello, world?

  • I would I would use the print function which comes with Python.

  • And actually, the nice thing about V s code is that it gives you a lot of this sort of built in intelligence, depending on how you like to develop or it'll actually tell you when you write functions, you know, sort of what the function of what the function expects, what it does.

  • So this is a nice thing about modern text editors and integrated development environments uses.

  • Andi said, Hello world.

  • So I'm just gonna type in the string Hello world and that's it.

  • Yeah, but some and you'll notice now that you get syntax highlighting with programs like this.

  • I see there's a shoutout thio pie charm as well, which is a popular editor for python as well.

  • Yes, we do know that I don't might come with the default installation, but we're just We're just focusing on Python today.

  • You can use any text editor out there that you would like it.

  • It's amazing folks in the chatter actually typing, typing some responses to what you said, and it's actually it's kind of interesting because Gaurav Birds Wall actually says print hello world.

  • And if I'm if I'm reading that correctly he actually said are here She actually said, Hello, world.

  • Now if we try to do you think we should try and run this in?

  • Oh, I don't know.

  • I don't like the squiggly s that suggests that there's a mistake of some sorts.

  • Okay, Undefined variable.

  • How low and this says unexpected token world.

  • So let's go.

  • Let's come back to that, though, because I think we should run the program first, cause while we have arguably written a program now, we haven't actually run it.

  • Previously, when Colton ran the program called Python three, he was able to write a lot of code hit enter, and immediately it was executed.

  • But typically, the paradigm, of course, for writing code is to write one or more lines of code save it in a file and then somehow execute that file.

  • So I think to execute this file hello dot pie we're gonna need a terminal window.

  • Sure.

  • How do we do that?

  • So I already have one.

  • So this is the Mac native terminal application.

  • Windows has the same thing with C and D Lennox.

  • Actually, it's called analytics, which called Olympics, Terminal Terminal or Ex term or a bunch of other things on DSO.

  • I'm actually I'm still in the pipeline show.

  • I'm gonna clear my screen.

  • And then this is assuming that I'm actually in the directory.

  • We're doing this code.

  • So right now we're at my belief.

  • Dev is the pwd that tells you where you're working.

  • Yeah.

  • So this is for President Working directory.

  • I'm here.

  • Users J Harbor.

  • Deb, I want actually go into where I just created a file, which is streams slash python tutorial.

  • I believe that is where I created it.

  • And you'll see I hit l s for list.

  • And then if I type in Python three like we did before to open up the interactive show.

  • But instead I say hello dot pie after that.

  • Well, see that it actually outputs exactly what we wrote in the source files.

  • And while trivial, go ahead.

  • If you could go back to the terminal window literally run by a python three hello dot pie again, this should go without saying, but because the code is saved and file, you can, of course, repeat your steps.