Python upper() and lower() Method

Using the upper() and lower() methods is helpful when you need to compare strings that do not need to be case-sensitive. For example, maybe you need to accept a variable that is the name of an interface such as "FastEthernet1/1" but want to also allow the user to enter “fastethernet1/1”. The best way to compare these are to use upper() or lower()

>>> interface = 'FastEthernet1/1'
>>> print interface
FastEthernet1/1
>>> interface.lower()
'fastethernet1/1'
>>> interface.upper()
'FASTETHERNET1/1'

You also have the ability to assign it as the value to a new or existing variable.

>>> intlow = interface.lower()
>>> intlow
'fastethernet1/1'
>>>
>>> intupp = interface.upper()
>>> intupp
'FASTETHERNET1/1'


Tulis komentar anda... Conversion Conversion Emoticon Emoticon

Thanks for your comment