 Hey, hi everybody welcome back to Python for Java programmers. This is lesson number three today We're going to talk about strings and here's we're going to see some Bigger differences between the way Java does things and the way Python does things We're also going to see some similarities at least conceptually. Let's get started again with Java You need a class structure in this case class main You need a function to start your program public static void main in Python You do not need these things you can just safely ignore them although you could do it if you wanted to So the first thing we'll see is we have a string called Name and it has been assigned the value of Robert Smith now Here's probably one of the biggest differences between Java and Python Java is strongly typed Once you say that name is a string. It is a string until the day it dies in Python. You can change You can change willy-nilly whatever you want to do You don't even have to tell it. It's a string. Okay, so I would just say name equals quote Robert Smith And those of you who know music know that Robert Smith is the lead singer of the cure So notice I didn't have to put string of course I didn't have to put the semi colon although as I said you can do that I mentioned that in the last video so let's go ahead and prints and that's what we did in last video name and again in Java we got everything's basically an object. So it's always object dot method or object dot attribute But in Python some things are and some things aren't so I would do Len name So Len of course stands for length. So I'm gonna go ahead and run this over here So my I'm using repel dot it and for both of these So you'll see where we got Robert Smith in 12 I'm gonna go ahead and run it over here in Python and hopefully we'll see Robert Smith and 12 not a little difference is you see how Java is pre-compiling From your source code into the byte code, then it's executing the byte code Python it basically just runs So let's go ahead and move on. So I'm gonna print a blank line and print Name in quotation marks I'm gonna print Name colon now this is kind of an interesting one. I'm gonna put name like that and I'm gonna say print quote name colon Dot format name You to kind of do the same type of thing that we did here. So I'm gonna go ahead and run that They say we got name name Robert Smith. You can see there's it's a complete match. So Notice here, this is actually the one area where actually Java is a little bit better And you'll see you'll see this in a bit. I think I actually know you won't because we're just looking at strings now So we'll leave it at that for now. Sorry. So name plus name name plus name now here It's a little bit different In Java you actually have to use the string class dot format method And then you use percent s percent s is a throwback to see programming. There is also a way to do this I believe in Python I don't really use it. So I'm gonna skip it for now But basically you just use format and then where you have the curly braces name will be replaced into that So if I go ahead and run that which I've already done You can see how name plus name works the same string format is a little bit different So here you need the percent s here. You do not use some braces There is actually a way of doing it with the percent s but again, we don't really use it in Python anymore It's kind of an older system. Although. I think they did add something new recently where they're bringing it back I don't know. I'm not that up on it. Anyhow, this is just the basics and get you started. So again I'm gonna go ahead and set print So we have a little bit of space and print here. We're gonna do some string methods And so over here we have two upper and two upper case and two lower And I think it's basically the same. So I'm gonna try it because I haven't done this for a while I didn't write this ahead. I think it's upper with quotation with parentheses and print Dot lower and then again Trying to do this for memory. So let's hopefully see what we get here So we should have upper case. Hello and lower case. Hello You know, let's see what happens Okay, and of course I spelled print wrong So you guys probably figure that out. It's extremely difficult to talk and type at the same time Okay, so this is basically the same thing. So you can see how The same methods exist in both languages. They just have different names So hello dot upper hello dot lower rather than two upper case to lower case Notice this is also Lower case and that we'll get to that a little bit as well probably now. This is where we see a bit more of significant difference in the way that Python does things versus Java excuse me, so I'll say print substrings And so you see over here in Java. We're using substrings zero four substring five twelve substring five In Python, they're not really called substrings. They're called we use something called slices slices are really really helpful You can do them with strings you can do it with Lists et cetera et cetera kind of like you can do You know not you can't quite do substring with lists and arrays in in Java, but they have similar methods so I'm gonna go ahead and do print I'm gonna say good morning and Here we use dot substring zero four here I'm gonna do zero colon four and that is a slice print Good morning Again five comma twelve Again, and this is not to teach you how this works that I'm assuming again You already know these things if you don't go ahead and watch a couple of my other videos There are introductions to Java or introduction to Python They basically follow the same code But this is just a side-by-side comparison for people that already know Java and of course I got to put a print colon there instead and I do one more good morning and If I just want one character, I just put one character in there So I'm gonna go ahead and we're right. So I should see good morning and morning and we go ahead and There's a small morning wrong I do a lot of spotting mistakes and hopefully we will see good morning and Okay, a little different so you can see how with substring To get one we didn't get one letter here. It's a little bit different In Java if you do just one number it starts at that number and goes all the way to the end Okay in Python if you do one number it just gives you that number so zero one two three four and Five M is the index five if you want to do exactly this I'm gonna go ahead and copy that So you can see the difference If you want to do that you just put a colon and That will give you from five to the end. Let's run that Now in Java, let me go ahead and copy that out for you And let's make the output the same if you wanted just the fifth character. It would be for index five You do five and then plus one Let's go ahead and run that Okay, so good morning and morning good morning and morning So you can see on a side-by-side basis They're almost the same Here, of course, we're using a method here. We're using something called Slices, but they work essentially the same. So just if you're coming from Java just be real careful You know your expected behavior here is that you get the whole string or the front the whole end of the string Whereas in Python you only get one character Which is what this does. Okay, so keep those differences in mind Okay, so that's it. That's all I really want to talk about for strings and Just kind of get you started and this is the way Python does things again slices are super super helpful I quite like the syntax. It's very short and compact Compared to all of the typing you do in Java So I should do a comparison see how many characters I typed here versus how many characters I typed here It's it's much much more compact Any that is that for less than three strings. Stay tuned for more