● 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
留言列表