Python Online String

4792

Table of Contents

Python Online String Tool:

Using the Python Online String tool, you can test various Python string functions online. You can write the Python code and test various Python string functions online.

 

 

Examples of Various Python String Functions that can be tested using: Online Python String Tool

capitalize() string method

 Converts the first character to upper case

casefold() string method

Converts string into lower case

center() string method

Will center align the string, using a specified character (space is the default) as the fill character.

count() string method

Returns the number of times a specified value occurs in a string

encode() string method

method encodes the string, using the specified encoding.

If no encoding is specified, UTF-8 will be used.

endswith() string method

returns True if the string ends with the specified value, otherwise False.

expandtabs() string method

sets the tab size to the specified number of whitespaces.

find() string method

  • finds the first occurrence of the specified value.
  • find() method returns -1 if the value is not found.
  • find() method is almost the same as the index() method, the only difference is that the index() method raises an exception if the value is not found.

index() string method

  • The index() method finds the first occurrence of the specified value.
  • The index() method raises an exception if the value is not found.
  • The index() method is almost the same as the find() method, the only difference is that the find() method returns -1 if the value is not found.

isalnum() string Method

  •  returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9).

isdecimal() string Method

  • isdecimal() method returns True if all the characters are decimals (0-9). This method is used on unicode objects.

isdigit() string Method

  • isdigit() method returns True if all the characters are digits, otherwise False. Exponents, like ², are also considered to be a digit.

isidentifier() string Method

  • isidentifier() method returns True if the string is a valid identifier, otherwise False.A string is considered a valid identifier if it only contains alphanumeric letters (a-z) and (0-9), or underscores (_). A valid identifier cannot start with a number, or contain any spaces.

islower() string Method

  • The islower() method returns True if all the characters are in lower case, otherwise False.Numbers, symbols and spaces are not checked, only alphabet characters.

isnumeric() string Method

  • The isnumeric() method returns True if all the characters are numeric (0-9), otherwise False.Exponents, like ² and ¾ are also considered to be numeric values.

isprintable() string Method

  • The isprintable() method returns True if all the characters are printable, otherwise False.Examples of none printable characters can be carriage return and line feed.

isspace() string Method

  • The isspace() method returns True if all the characters in a string are whitespaces, otherwise False.

istitle() string Method

  • The istitle() method returns True if all words in a text start with a upper case letter, AND the rest of the word are lower case letters, otherwise False.Symbols and numbers are ignored.

isupper() string Method

  • The isupper() method returns True if all the characters are in upper case, otherwise False.Numbers, symbols and spaces are not checked, only alphabet characters.

join() string Method

  • The join() method takes all items in an iterable and joins them into one string.A string must be specified as the separator.

ljust() string Method

  • The ljust() method will left align the string, using a specified character (space is default) as the fill character.

lower() string Method

  • The lower() method returns a string where all characters are lower case. Symbols and Numbers are ignored.

lstrip() string Method

  • The lstrip() method removes any leading characters (space is the default leading character to remove)

partition() string Method

  • The partition() method searches for a specified string and splits the string into a tuple containing three elements.The first element contains the part before the specified string.The second element contains the specified string.The third element contains the part after the string.Note: This method search for the first occurrence of the specified string.

replace() string Method

  • The replace() method replaces a specified phrase with another specified phrase.Note: All occurrences of the specified phrase will be replaced if nothing else is specified.

rfind() string Method

  • The rfind() method finds the last occurrence of the specified value.The rfind() method returns -1 if the value is not found.The rfind() method is almost the same as the rindex() method.

rjust() string Method

  • The rjust() method will right-align the string, using a specified character (space is the default) as the fill character.

rpartition() string Method

  • The rpartition() method searches for the last occurrence of a specified string, and splits the string into a tuple containing three elements.The first element contains the part before the specified string.The second element contains the specified string.The third element contains the part after the string.

rsplit() string Method

  • The rsplit() method splits a string into a list, starting from the right.If no “max” is specified, this method will return the same as the split() method.Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

rstrip() string Method

  • The rstrip() method removes any trailing characters (characters at the end a string), space is the default trailing character to remove.

split() string Method

  • The split() method splits a string into a list.You can specify the separator, default separator is any whitespace.Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

splitlines() string Method

  • The splitlines() method splits a string into a list. The splitting is done at line breaks.

startswith() string Method

  • The startswith() method returns True if the string starts with the specified value, otherwise False.

swapcase() string Method

  • The swapcase() method returns a string where all the upper case letters are lower case and vice versa.

title() string Method

  • The title() method returns a string where the first character in every word is upper case. Like a header, or a title.If the word contains a number or a symbol, the first letter after that will be converted to upper case.

upper() string Method

  • The upper() method returns a string where all characters are in upper case.Symbols and Numbers are ignored.

zfill() string Method

  • The zfill() method adds zeros (0) at the beginning of the string, until it reaches the specified length.If the value of the len parameter is less than the length of the string, no filling is done.