String Methods

0
12KB

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).

Suche
Kategorien
Mehr lesen
Technology
INDEX and MATCH Functions
The combination of INDEX and MATCH functions in Excel is a powerful way to perform lookups. This...
Von Microsoft Excel Tips 2024-10-16 01:02:42 0 15KB
Computer Programming
Dynamic Typing, Stubs, and Namespaces
Dynamic Typing: In Python, variables don't have a pre-defined data type associated with...
Technology
Transaction Processing Systems (TPS)
These are information systems that manage and process data from business transactions. A...
Von Business Information Systems (BIS) Course 2024-07-31 18:42:51 0 9KB
Andere
I Am Fixing Myself Because I Understand I Am the Problem Too
In a world that often encourages us to seek external causes for our difficulties, embracing the...
Von ALAGAI AUGUSTEN 2024-08-15 17:13:23 0 10KB
Ausbildung
Interactive Learning Boosts Retention by 75%
Did You Know? Interactive Learning Boosts Retention by 75%! Engage with Your Studies and See the...
Von ALAGAI AUGUSTEN 2024-07-21 19:12:20 0 18KB
Talksphare https://talksphare.com