2.3 Using Inputs Effectively Part 3

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *

Already have an account? Sign In »

Video Transcription
All right, So we're back and you are once again watching Intermediate Python here on Cyber Eri on demand. We're right in the middle of finishing up our interpreter here. So when we left off, the challenge we were still facing is that even though our interpreter is looking for numeric data,
we can see that it's still not actually giving us any. It still thinks that everything is a string,
and the reason for that is because the is numeric function here is seeing that white space and doesn't know how to interpret it as a number. So what we're gonna have to do is we're going to have to find a way to get rid of all of that white space. Fortunately, as usual, Python comes to the rescue with a really simple helper function. And all we need to do there is do i
dot strip
that is numeric.
And let's see exactly what that does for us.
And again, we'll just do tests.
sad food deaf. So I don't know what the world I was writing there in 5432
and you can see here that that is corrected it our string tokens now registers, too, with test and saddened. FedEx office and two numbers one and 5432 The reason that's happening and what we're gonna explore real fast here is we're going to have a quick look at what exactly split is doing. And to do that again, we're just going there are screen. We're gonna open our python interpreter
and you can see here we're going to run help
against stre dot split
not split. Sorry, sir dot stre dot strip
There we go. And you can see here that it returns a copy of the string with the leading and trailing white spaces removed. Now, if characters is given. So this argument right here, which we can see is a list instead of removing white space that will remove those characters from the leading and the trailing ends of the strength.
So it's a really great Python utility function that was the last sort of peace we needed
so real quick to go back over what we did in this video and the last video, we are going to look at
our interpreter here. We learned how to take input with the very simple input function, but More importantly, we learned how to properly interpreted that input. We figured out how we can split data. According to a DL emitter, we figured out how we can determine if data is numeric and how we can make quick corrections to the data in order to make it actually interpret herbal.
We applied that NATO, we put it into different list. So that way actually did some storage, some logic based upon that information.
And then we output that data with a nicely formatted string here. This is a pretty short, pretty simple program that we wrote. But it actually demonstrates a lot of the core concepts of Io and Python, so hopefully that's valuable to you. Hopefully, you feel comfortable and you'll understand again, this is the objective of this video was learning to use an interpreter input from the user
and our next video In the second half of lesson one,
we're gonna come back, and we're gonna learn how we can miss command line arguments and python and what people invoke our script can actually get use of the data they give us right there. So thank you for watching. I have been your instructor, Joe Perry, and I'm thrilled that you continue to take part in Intermediate Python here on Cyber Eri on demand
Up Next
2.4 Command-Line Arguments
2.5 File I/O - Opening, Writing and Closing
2.6 File I/O - Opening, Reading, and Closing
2.7 Interfacing with the OS
3.1 Implementing Classes Part 1