close

● Strings are immutable

● Crearing triple-quoted string

  ''' Here's where you want to put your string '''

● Using a Backslash

  \' = '
  \" = "
  \\ = \
  \a = bell
  \b = backspace
  \n = new line
  \t = tab

● String with operators

  "One" + "One" = "OneOne"
  "One" * 5 = "OneOneOneOneOne"

● String Methods

  ◎ s = "coseTte Chiang"

   s.upper() = "COSETTE CHIANG"
   s.lower() = "cosette chiang"
   s.swapcase() = "COSEtTE cHIANG"
   s.capitalize() = "Cosette chiang"
   s.title() = Cosette Chiang

  ◎ s = " ABCDE WXYZ "

   s.strip() = "ABCDE WXYZ"

  ◎ s = "ABCDE ABCDE ABCDE"

   s.replace("BCD", "MNO", 0) = "ABCDE ABCDE ABCDE"
   s.replace("BCD", "MNO", 1) = "AMNOE ABCDE ABCDE"
   s.replace("BCD", "MNO", 2) = "AMNOE AMNOE ABCDE"

    Note: number is the limits for how many replacement

  ◎ s = "ABCDEFGHIJKLMNO"

   s[3] = D
   s[3:] = DEFGHIJKLMNO
   s[4:9] = EFGHI
   s[-3] = M
   s[-3:] = MNO

  Note: minus index meaning index counting from back


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 cosette119 的頭像
    cosette119

    怪女孩‧蛻變中

    cosette119 發表在 痞客邦 留言(0) 人氣()