String Methods

0
3كيلو بايت

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

البحث
الأقسام
إقرأ المزيد
Computer Programming
Line breaks (<br>)
The <br> tag is used to insert a single line break in your HTML content. It's an empty...
بواسطة HTML PROGRAMMING LANGUAGE 2024-08-15 01:22:49 0 2كيلو بايت
Computer Programming
Dynamic Typing, Stubs, and Namespaces in Python
Here's a breakdown of these three concepts in Python: 1. Dynamic Typing: Python is a...
بواسطة Python for Everybody - Full University Python Course Code 2024-07-17 14:53:52 0 2كيلو بايت
Physics
MATIGO PHYSICS PAPER 1 2024
MATIGO UACE PHYSICS PAPER 1 2024
بواسطة Question Bank 2024-09-05 17:26:27 0 2كيلو بايت
Business
How to Start Selling on Amazon FBA: A Step-by-Step Guide
Are you looking to tap into the booming world of e-commerce? Selling on Amazon using Fulfillment...
بواسطة Mpatswe Francis 2024-09-18 20:21:05 0 2كيلو بايت
Computer Programming
Comparing Data Types and Conditional Expressions
Comparing Data Types: In Python, you can compare data types using the type() function. This...
بواسطة Python for Everybody - Full University Python Course Code 2024-07-16 21:47:48 0 2كيلو بايت