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 *
or

Already have an account? Sign In »

Difficulty
Intermediate
Video Transcription
00:00
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,
00:16
we can see that it's still not actually giving us any. It still thinks that everything is a string,
00:20
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
00:40
dot strip
00:43
that is numeric.
00:45
And let's see exactly what that does for us.
00:53
And again, we'll just do tests.
00:56
One
00:57
sad food deaf. So I don't know what the world I was writing there in 5432
01:03
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
01:23
and you can see here we're going to run help
01:26
against stre dot split
01:32
not split. Sorry, sir dot stre dot strip
01:38
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.
01:57
So it's a really great Python utility function that was the last sort of peace we needed
02:01
so real quick to go back over what we did in this video and the last video, we are going to look at
02:09
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.
02:28
We applied that NATO, we put it into different list. So that way actually did some storage, some logic based upon that information.
02:34
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
02:54
and our next video In the second half of lesson one,
02:58
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