Be sure to like, share and comment to show your support for our tutorials.
=======================================
Channel - https://goo.gl/pnKLqE
Playlist For This Tutorial - https://goo.gl/EyZFti
Latest Video - https://goo.gl/atWRkF
Facebook - / mastercodeonline
Twitter - https://twitter.com/mastercodeonlin?l...
Website - http://mastercode.online
======================================
Python Casefold String Method
In this Python tutorial, we are going to discuss the Python casefold string method. The casefold string method is similar the lower string method and the only difference is that casefold removes any reference to case distinction in a Python string. This means that there is no upper or lower case character in the new string object after calling the casefold string method on a string.
Examples of Casefold String Method
In these examples we are going to remove any case declaration in a string with the casefold method in Python.
#Example 1
a = 'This is a new Python String'
a.casefold()
'this is a new python string'
#example 2
b = 'This String Is A Title and We Want To Reassign The String'
b = b.casefold()
b
'this string is a title and we want to reassign the string'
#example 3
'We can use casefold like this as well'.casefold()
'we can use casefold like this as well'
#example 4
print('We can use casefold in a print statement too'.casefold())
we can use casefold in a print statement too
#example 5
c = 'THIS IS A BUNCH OF CHARACTERS WITH CAP LOCK ON'
print(c.casefold())
this is a bunch of characters with cap lock on
Examples Explained
Example 1:
a = 'This is a new Python String' - We create a new string object with some capitalized characters in the string. This string is assigned the variable 'a'.
a.casefold() - We then take the string object via the variable and call the casefold string method on the string object.
'this is a new python string' - We are returned a string that contains no case information. We have no capitalized characters.
Example 2:
b = 'This String Is A Title and We Want To Reassign The String' - We create a new string object and assign the variable 'b' to the string object.
b = b.casefold() - We now take our string object call the casefold string method on the string object and reassign the b variable to the string method.
b 'this string is a title and we want to reassign the string' - We now call the variable b and have a string returned to us with no case declaration.
Example 3:
'We can use casefold like this as well'.casefold()- We create a string object and call casefold on the object all in one line.
'we can use casefold like this as well' - We are returned a new string object with no case information.
Example 4:
c = 'THIS IS A BUNCH OF CHARACTERS WITH CAP LOCK ON'- We create a new string object and assign the variable c to the string object with cap lock on.
print(c.casefold()) - We then call a print statement on our string object that is represented by the variable c and call the string method of casefold on our string method.
this is a bunch of characters with cap lock on - We are returned a string with no cap declaration
Conclusion
In this Python tutorial we have looked at how to remove capitalized information from a string. The Python casefold string method is similar to the lower string method but casefold removes all case information from a string object. If you have any questions please leave a comment below.
En esta página del sitio puede ver el video en línea Python Casefold String Method de Duración hora minuto segunda en buena calidad , que subió el usuario Code master 22 septiembre 2015, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 5,707 veces y le gustó 59 a los espectadores. Disfruta viendo!