 Okay, welcome to Python for Java coders part 10 in this part I'll talk about how to do keyboard input in Python, and you'll be pleasantly Surprised I don't know to know that it's a lot easier than doing it in Java But it has a little couple little gotchas. Let's take a look here so I've created a short little Java program here and Again, I'm assuming you know Java already. I'm using the scanner class. I've created a scanner object And then I have three variables a string called name and integer called age and a double called height And I'm using the scanner class to get that information from the user So next line gets us a string next it gets us an int and next double gets us a double I'm just printing it out here. So let's take a look at what that looks like So it's gonna ask me what is your name? eventually My name is Christian Okay, how old are you? I just turned 48 this month and how tall are you? I'm 175 point zero centimeters give or take And so just prints out that same information. So let's go ahead and do the same thing over here in Python Now Python, I don't need to import anything. It just works. Okay. I don't need to define my variables ahead of time He's busy. I don't actually even need to print it out first. Watch what I do here It's a name equals input Quotation marks, what is your name question mark? And I always like to put that little thing at the end And I'm gonna go ahead and put age equals inputs How old are you? question and Age and height equals input How tall are you and then I just go ahead and print it out Go ahead and put name And don't forget that little thing and then age Height use the format method and it's gonna be age. Sorry name age and height and That's the whole part basically Let's go ahead and run that My name is Christian Aging as I mentioned, I just turned 48 and I want to say 5.0 centimeters And I forgot to put a little space there And you can see it prints out the exact same Outputs which is pretty cool. That is one of the strong benefits of Python You can do a lot of things really quickly really efficiently as compared to our little friend Java over here Now there is one very very very big Gotcha that you have to be careful of Okay over here in Java if I use next line and I've already declared that name is a string I know this is a string Okay, I know that age is an int and I know that height is a double So it is automatically converted to the appropriate type in Python it is different in This example age is a string. You know, I entered a number It's a string in the computer's memory height is a String even though I entered it as a float. Remember, it's called float in Python It is not a float as far as type goes. It is a string. So if I did this As a test, so say let's print name Plus name see what happens print age plus age and print height Plus height Go ahead and run that And you can see it is treating these as strings. So if I did something like So if I did if age equals 25 it's never going to work because it's expecting a string Okay, so you got to be careful with that now what we need to do is To convert it we need to cast it. Okay, so I want this to be an int so I'm gonna put int and Put it in parentheses remember in Java when we cast we put it we do it like this before the variable but in Python It is it's basically a function. So int parentheses and parentheses height. We want it to be a float so I shouldn't did that and We would wrap that in parentheses. So I'm gonna put that back. I'm not sure why I deleted it I'll put name times to print age times two and print height times two Let's go ahead and run that and see what we get this time. I'm gonna spot it wrong. It's okay age is 48 and how tall are you? I am 5.0 and you see now this was treated as a string and Because you can also multiply strings and just print out multiple copies in Python and here 48 was multiplied by two and And for and 175 was multiplied by two. So I converted it as soon as I inputted it. I converted it to An integer. Now, the only thing you have to watch with that is If I don't enter a number You get an error because you can't convert a LFK JD into an integer So there's other things you have to do to make sure that doesn't happen. So that's the gist of it That's basically how it works So getting input in Python is far far easier But you do have to pay attention to the type because you're always going to get a string no matter what So the equivalent over here would be like putting next line And next line instead of next int and next double Okay, and then you'd have to convert it using probably into your class or the double class Okay, so that is it. Uh easy peasy Uh subscribe for updates and stay tuned. Take care