Hello, everyone. And welcome back to intrude a python here on cyber eri on demand, I as always I'm your instructor, Joe Perry, And I'm just thrilled to have you back here for the second video of lesson six. In this video, we're gonna learn more about how to take in but from our users and how to write better print statements.
So to do that, we're gonna go back into our trusty terminal here. We've got Python three already up and running from the last video in the last lesson.
And in this video, we're gonna talk about, as I said, input and output in python three. The way we take input
You can see here that when I typed it not only didn't print anything the screen, it also didn't take me to a new line of the interpreter. That's because it is waiting on the user to provide some kind of input. So here, I'm going to do
hello World String that we like to use so much
and you see, it's going to go back to giving me a problem.
Now we can see that the value that we gave it the hello world is stored in X Now. When I wrote that, I put quotes around it.
But in fact those quotes aren't part of the string or are
the normal string definition line
as they would be in normal python because of the fact that Python assumed whatever we gave it was a strength.
And to demonstrate that a little bit better without my verbosity and rambling, you can see X equals input.
So from this would be from the command line. And I'll show you how to do this from a script in just a second. So I'm typing this stream without quotes around it, and Python still takes it and knows that in reality, that's a strength.
And I'll show you. Like I said, I'm gonna show you that from
So we're gonna do them
with them. I owe, not key. Why
and we're gonna create a function, take
and that's not gonna take any arguments at all.
And all that's going to do is they X equals input
that we will call that function down here below
and you see that nothing else is happening because we only took the input and returned it. We didn't actually print it anyway.
the other problem here is that we're not really very it's not very verbose. It's not telling us it wants anything. We're not understanding necessarily. If we didn't write the code, we're not necessarily gonna understand. Oh, this program is looking for input from me.
So the way we can do that
well, you can kind of fix this up a little bit, Make it more functional
is by providing an argument to input. And what we would do there
is We would write some prompt string. So, for example, input text,
I'm here at the bottom will go ahead and just prince
the return from take input.
Now you see, we've got a prompted. It says input text.
and it prints it back out for us.
So that's the way we actually take input in Python. It's with a very, very simple function called input.
What if we wanted to put things a little bit Maur for most of what I wanted to add a little bit more information, For example,
What if we wanted to print a string that had a lot of inputs. So perhaps we might want to say something like
and we'll do a comment here to describe the idea
How would we go about doing that?
Well, the easiest way and the way that we're gonna do it here
Not necessarily the easiest way, but the best way and the way we're gonna be doing it here
is by using the method.
and method is a string format is a string method
that is designed to input data into a string sort of in the abstract. So we could do, for example, and I'll actually show you this first from our interpreter.
Wrong key word. There we go.
they were going to use these curly braces again, or brackets.
So that string right now just looks like this
format. The method format is a really, really cool method that's gonna take that those braces and say, OK, data needs to go in here. So
and then we're going to do
and the end. But we're gonna give it his test,
and you see, it's going to say you said tests
well, the input method does. It goes back
to the string that it's addressed against, finds braces and inserts data into them just one piece of the time.
So if you want to say
we would just give it the argument multiple times
you said test and test again. So you see here format is a very, very easy to use function. You just give it the arguments. And so long as the number of arguments you give it match the number of braces or the sets of braces, it's going to be able to input that without any further, you, without any further input from you,
we're gonna go back into our iota pi
where we're going to say,
well, we're gonna return,
into this stir variable stir var,
and then we're going to do
Sorry, not stir Bardot format messing myself up here.
We're going to have a seven second variable,
which we will call prompted There. You know, I'm not getting back into order.
disturb our take input.
Now we're going to print
prompted a radio. Now we're cooking with grease
color at number of parentheses. Everything matches,
and we'll run our code and see if it works.
There you go. So that's how you can take input and give back out. Put in more formatted, more useful ways. You can use that to put numbers list strings, dictionaries, whatever you want into your strings. Just by using the format method, you will have more examples of that in the lab that's coming up. So please take your time, dig in and play with that just as much as you need to to get familiar with it.
Thank you for watching this video again. We discussed the ideas of taking input and writing better print statements.
I am old. I, as always, rather am your instructor, Joe Perry. And I'm thrilled that you came to watch this video and I can't wait for you to come back for a lesson seven. Where we're gonna talk about numbers. Thanks for watching Internet Python here on Cyber Eri on demand