This_is_an_instance_of_a_string = "HeLlO wOrLd" help(str.upper) # mandatory arguments: 0 # type arguments: - '''explanation: .upper returns a copy of a string in only uppercase letters and thus changes the original string with both lower and uppercase letters to only uppercase letters''' # example with explanation above print This_is_an_instance_of_a_string.upper() help(str.title) # mandatory arguments: 0 # type arguments: - '''explanation: .title returns a copy of a string in which words start with an uppercase letter, but all remaining letters are lowercase''' # example with explanation above print This_is_an_instance_of_a_string.title() help(str.rfind) # mandatory arguments: 1 # type arguments: variable with string element(s) ''' explanation: .rfind returns an integer which represents the last location or highest index of a certain subelement of the original string. This subelement must be specified in a variable and cannot be entered as an argument by itself. Optional arguments allow you to tell the method at which index to start or start and end looking. The method is case sensitive.''' # example with explanation above sub = "L" # Here it finds the last "L" in "HeLlO wOrLd" print This_is_an_instance_of_a_string.rfind(sub) # Here it finds the first "L" in "HeLlO wOrLd" print This_is_an_instance_of_a_string.rfind(sub,0,4) help(str.startswith) # mandatory arguments: 1 # type arguments: string ''' explanation: .startswith returns a boolean value after checking if the string starts with a certain value as assigned in a variable. You can specifiy the start and endposition where the method starts to compare with the string. The method is case sensitive.''' # example with explanation above prefix = "w" # Here it checks whether 'HeLlO wOrLd' starts with 'w' print This_is_an_instance_of_a_string.startswith(prefix) # Here it checks whether 'wOrLd' starts with 'w' print This_is_an_instance_of_a_string.startswith(prefix,6) # Here it checks whether 'wOrLd' starts with 'W' prefixx = "W" print This_is_an_instance_of_a_string.startswith(prefixx,6) help(str.replace) # mandatory arguments: 2 # type arguments: string ''' explanation: this returns a copy of the string where all occurrences of a variable assigned a string value are replaced by a string value from a second variable. With the count parapmeter, you can specify for which first number of instances you want to use it. ''' # example with explanation above old = "O" new = "ooooo" print This_is_an_instance_of_a_string.replace(old, new) print This_is_an_instance_of_a_string.replace(old, new, 1) print This_is_an_instance_of_a_string.replace(old, new, 2) help(str.isalpha) # mandatory arguments: 0 # type arguments: - ''' explanation: this returns a boolean value after checking if the string only contains alphabetic characters, so letters ''' # example with explanation above print This_is_an_instance_of_a_string.isalpha() ALPstr = "Hello" print ALPstr.isalpha()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question