Slice
A
segment of string is called slice.

str = "banana"
print(str[0:2])
print(str[:2])
print(str[2:])
Immutable
Strings are
immutable, you can't change them.

str = "Hello World"
str[0] = "J"
Key
To
search in a string, use a loop through string.

def find_key(str, ch):
i = 0
while i < len(str):
if str[i] == ch:
return i
i = i + 1
return -1
print(find_key("Hello World", "o"))
File
Open
words.txt and search through words list.

import os
file = os.path.dirname(__file__) + "/words.txt"
rows = open(file)
def has_no_e(word):
for letter in word:
if letter == "e":
return False
return True
W = []
E = []
for row in rows:
word = row.strip()
W.append(word)
if (has_no_e(word)):
E.append(word)
print("W: " + repr(len(W)))
print("E: " + repr(len(E)))
Build-in
Strings provide
methods for various operations.

str = "Hello World"
str = str.upper()
print(str)
index = str.find("W")
print(index)