![]() |
| Python Center String Method |
Title : Python Center String Method
Duration : 04:54
Channel : Master Code Online
Label : Python Tutorial, Learn Python, Python (Programming Language), Programming Language (Software Genre), String, Method, Python Center String Method, Learn Python 3, Python 3 Tutorial, Python String Method, Python String, Best Python Tutorial, Best way to learn python, learn python the hard way, learn python the easy way, Center string method, learn to use the python center string method, how to center string method, onestopprogramming, thenewboston, sentdex, Learning Python
Duration : 04:54
Channel : Master Code Online
Label : Python Tutorial, Learn Python, Python (Programming Language), Programming Language (Software Genre), String, Method, Python Center String Method, Learn Python 3, Python 3 Tutorial, Python String Method, Python String, Best Python Tutorial, Best way to learn python, learn python the hard way, learn python the easy way, Center string method, learn to use the python center string method, how to center string method, onestopprogramming, thenewboston, sentdex, Learning Python
![]() |
![]() |
![]() |
| Python Center String Method |
See our full tutorial series at http://mastercode.online/unit/python-center-string-method/?id=2654 Python Center String Method In this Python tutorial, we will look at the Python center string method. The center string method allows us to center our strings around a set amount index spots(width) and we can also choose what type of character(fillchar) or symbol fill the space around the string. If the index(width) is less or equal to size of the string then the string itself will be shown. The default character(fillchar) is a space. Examples Of The Python Center String Method Example 1: a = 'This is our String' a.center(30) ' This is our String ' Example 2: a.center(30, '-') '------This is our String------' Example 3: a = a.center(50, '+') a '++++++++++++++++This is our String++++++++++++++++' Examples Explained Example 1: a = 'This is our String' - We create a new string object and we assign a name(variable) of 'a' to that string obect. a.center(30)- We call our string object via the variable and call the center string method. With an argument of a 30 index spots. ' This is our String ' - A new string object is returned to us and as you can see the new string object is center in the default spaces Python provided us. Example 2: a.center(30, '-')- We use the prior string we call our string object via the variable and then call the center string method on our object. This time, we still use 30 index spots totally, but we change the character to a '-'. Note that the character must be contained in quotes. '------This is our String------'- We now have a new string object that spans 30 index spots and new index spots that we have created are now represented by hyphens. Example 3: a = a.center(50, '+') - This time we call our string object and call the center string method on our string object and reassign the variable a to our new string object. Our new center string method has two arguments span 50 index spaces and replace the default spaces with a +. '++++++++++++++++This is our String++++++++++++++++'- We get a new string object returned to us. That spans 50 spaces and the empty spaces are now replaced with +. Conclusion In this Python tutorial, we have looked at how to use the Python center string method. If you have a questions about this tutorial leave a comment below.




No comments:
Post a Comment