 Hey, what's going on guys? Root of the Null here coming back at you with another Python tutorial. Let's fire up idle and let's get to programming I'm gonna create a new script here save this as a file.python USR bin environment Python we get our shebang line started create a new class Define a constructor Initialize this with the self keyword passing as a parameter as always Let's go test if this is the current script if name is equal to main And now we can create a new object and We can start programming. All right. I'm going to create a string variable I'm going to call the self dot string and then set its value to a this string Has random Cases There you go All right now the function that I want to show you guys today is Evidently called swap case and what this will do is it will swap every lower case letter that you see in your string for an Upper case letter and every upper case letter you see in your string into a lower case letter So if we print out our original string first of all print out self dot string Let's concatenate on some new line characters here. So our code is a little bit free and Now we can print out the The function self dot string it's always going to be your strings name as a variable You can use your dot selector and then run swap case Now luckily swap case does not take any parameters. It just gets the job done So now that H has been turned to a capital H the the I is in the S's have been turned into lower case and Then everything everything in the string has been changed from a capital at least lower case and eat the capital Nd and that sort of thing you can see there's an evident difference here But it doesn't touch any of our spaces or our exclamation points or anything that isn't a letter So we better be able to make up for that and outside of our own function and let's go ahead and start writing our own Let's Define it's with our DEF keyword. I'm gonna call mine swap case I'm passing the cell variable as always and the string to swap All right, let's get our code block started and now we're gonna use a new string This is gonna be a blank string for now But this is what we're gonna return because we can't modify the string that we've been passed to it So we have to create a new one and let's get the length of the alphabet because we're gonna have to loop through something So alphabet length equals the length of the le and function of string And then you can pass in either ASCII uppercase or ASCII lowercase I'm gonna pass in lowercase and now remember we're using this string module here So we have to go up go up to the top of our script and type in import string So we can have access to everything that's inside that module now We can begin to loop through all through all the things inside of our string. So for character in string to swap We can sort of create code block here and then we can test if the character is In string dots ASCII lowercase. So if it's a lowercase Letter what we're gonna do is we're gonna begin to loop through all of those things that are inside the lowercase So we can do for I in range And we'll pass in the length of the alphabet so we can start counting and we can index with I Whatever letter we need so now we can test once more if string Let's see dot ASCII lowercase Since that's the one we're testing for this time I is equal to the current character that we're looking at Character what we can do is We can add from new string We can append on their string dot ASCII uppercase so we can switch The the case of the letter and we're gonna pass in that I variable as an index here So that way we get the current character just the uppercase form of it And then we can break out of the for loop that we're going in right now And now we're gonna want to create this as a new case So if you can we can test else at the uppermost if statement that we have here if the character is an ASCII lowercase We're gonna want to test if the character is a is inside the string dot ASCII uppercase So we're just gonna do the same thing here, but reverse So now we can do a for loop for I in range alphabet length Get a new code block Test if the String dot ASCII uppercase The current I variable is equal to the character that we're looking at if it is we can add on New string plus equals string dot ASCII Lowercase and Then pass an I Now it can break out of our current for loop and we should be done here But now once we have this elf statement We've tested for things that are lowercase and then for cut for uppercase So now we should do is test for it's not if it's an uppercase or lowercase So if it's a if it's a space or that exclamation park that we had so we're going to do is have the if that's inside This L statement will add an L statement on to there So if it's neither lowercase or uppercase if it's not a letter Then what we're gonna have to do is new string and then add the current character And now we're done looping So when we break out of this topmost loop here what we can do is we can return The new string that we've created So if we go up here, and we we go back into our constructor when we run this Self dot swap case remember we name that function and now we can pass in self dot string So we can run this and we have the exact same output as the swap case that we ran beforehand So now we can change some of the cases in here this string has random cases And that sort of thing it'll still change it the way appropriate to change it the way it should So look what we've done. This is created a interesting function here It solves the same thing that the original swap case function would do but we've taken a look at it and see how it works on the back end and We're using the string module to be able to test for uppercase and lowercase letters and that sort of thing So thank you guys for watching. I hope you enjoyed this. I know this one is a little bit simple The more easy the better. Thank you guys for watching again, and I will see you in the next tutorial. Bye