String Methods

String split() and join()

It’s a common programming task is to take a large string and break it down into a bunch of substrings. The split() splits a string into a list of substrings called tokens. All the tokens combined form the larger string if put together.  A separator character indicated where to split up the string, to create the tokens. 

The join() method performs the opposite of split() by joining a list of strings together to create a big string.

The split() and join() methods are sometimes used together.

Other string methods

There are several useful string methods

  • replace(old, newcount) - replace all old with new characters (up to count times)
  • find(x, start, end– find x, starting at start ending at end
  • rfind(x) – reverse version of find()
  • count(x) – returns number of occurrences of x
  • isalnum() – returns True if all characters are numbers or letters only
  • isdigit() – returns True if all characters are the numbers
  • islower() – returns True if all letters are lowercase
  • isupper() – return True if characters are uppercase
  • isspace() – Return True if all characters are whitespace
  • startswith(x) – return True if the string starts with x
  • endswith(x) – return True if the string ends with x
  • capitalize() – Returns a copy of the string with the first character capitalized and the rest lowercase
  • lower() – Returns a copy of the string with all lowercase characters
  • upper() – Returns a copy of the string with all uppercase characters
  • strip() – Returns a copy of the string with leading and trailing whitespace removed
  • title() – Returns a copy of the string as a title, with first letters of words capitalized

The arguments not in bold, that are italicized, are optional

String objects may be compared using relational operators (<, <=, >, >=), equality operators (==, !=), membership operators (in, not in), and identity operators (is, is not).

Site içinde arama yapın
Kategoriler
Read More
EĞİTİM BİLGİLERİ
The Chisholm Trail
By Modern American History 2024-08-02 16:32:50 0 2K
Computer Programming
Bold Text in HTML
To make text bold in HTML, you can use either the <b> or <strong> element. Both...
By HTML PROGRAMMING LANGUAGE 2024-08-29 01:49:28 0 2K
Computer Programming
HTML Table Styling
HTML Table Styling You can use CSS to style HTML tables and their elements, providing greater...
By HTML PROGRAMMING LANGUAGE 2024-09-06 01:39:01 0 2K
EĞİTİM BİLGİLERİ
A MUST KNOW FOR A'LEVEL HISTORY STUDENTS
https://acrobat.adobe.com/id/urn:aaid:sc:EU:7c45002b-2e38-426f-a0b9-8447c474993b
By Landus Mumbere Expedito 2024-07-15 19:08:17 0 3K
Chemistry
S.4 CHEMISTRY WAKATA PRE MOCK QUESTIONS 2
https://acrobat.adobe.com/id/urn:aaid:sc:EU:85bd6cfc-45b5-4737-b430-d0e1fce698e9
By Landus Mumbere Expedito 2024-07-19 23:27:53 0 2K