Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Python has an extremely rich set of string methods, over 40 of them last I counted. What we've covered here are the essential ones. And I'd like show you how to find the rest of them and how to use them. It's really quite straightforward. Here we have the Python documentation page or the Python Standard Library. And we'll notice this is section 5, Built-in Types. And down here we see this link of 5.6.1 String Methods. And here's a complete list of all the string methods. Like for example, here is this center one.
And we see that center it takes with and an optional fill character and it returns a centered string of length width. And padding is done using this specified fill character. Default is a space. So if I had a string, 'this is a string', and I wanted to center it on say 80 character string, I would simply say new = s.center(80) like that. And now I have a new string. And we see that this new string is 80 characters wide. I can check if I want to. length of new is 80.
And we see that the string from my original string is centered there. Like I said, there are over 40 of these different methods. And here's the entire list and they are all very well documented. It's really simple. It's not in a terribly technical language. And so I encourage you to take the time and at least read through this one and get an idea for what is available. And then refer to it when you need one. That makes it really easy for you to have these tools at your disposal without having to memorize everything, without having to go through a lot of detail on the ones that you are not going to use very often.
So use the documentation in this case. There is a great wealth of string methods available. And I encourage you to become familiar with them and use them.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97442 Viewers
61 Video lessons · 84668 Viewers
71 Video lessons · 68871 Viewers
56 Video lessons · 101326 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.