<jupyter_start><jupyter_text>6.1 A string is a sequence of characters 6.2 Getting the length of a string using _len_<jupyter_code>fruit = "banana"
len(fruit)<jupyter_output><empty_output><jupyter_text>6.3 Traversal through a string with a loop<jupyter_code>index = 0
while index < len(fruit):
    letter = fruit[index]
    print(letter)
    index = index + 1
for char in fruit:
    print(char)<jupyter_output>b
a
n
a
n
a<jupyter_text>6.4 String slices<jupyter_code>s= "Monty Python"
print(s[0:5])
print(s[:5])
print(s[5:])
print(s[:])<jupyter_output>Monty Python<jupyter_text>6.5 Strings are immutable<jupyter_code>greeting ="Hello, world!"
greeting[0]="J"
new_greeting = 'J'+ greeting[1:]
print(new_greeting)<jupyter_output>Jello, world!<jupyter_text>6.6 Looping and counting 6.7 The _in_ operator<jupyter_code>"a" in "banana"<jupyter_output><empty_output><jupyter_text>6.8 String comparison<jupyter_code>word = "banana"
if word == "banana":
    print('Yes, banana')
word ="Pineapple"
if word < "banana":
    print("Your word, "+ word + ", comes before banana")
elif word > "banana":
    print("Your word, "+ word + ", comes after banana")
else:
    print("All right, bananas")<jupyter_output>Your word,Pineapple, comes before banana<jupyter_text>All the uppercase letters come before all the lowercase letters. 6.9 _string_ methods_dir_ function shows the available methods.<jupyter_code>type(word)
dir(word)
help(str.upper)<jupyter_output>Help on method_descriptor:

upper(self, /)
    Return a copy of the string converted to uppercase.<jupyter_text>6.10 Parsing strings<jupyter_code>data = "From <EMAIL> Sat Jan 5 09:14:16 2008"
atpos = data.find("@")
sppos = data.find(" ",atpos)
host  = data[atpos+1:sppos]
print(host)<jupyter_output>uct.ac.za<jupyter_text>6.11 Format operator<jupyter_code>camels = 42
"%d" % camels
"%d %d %d" % (1,2,3)<jupyter_output><empty_output><jupyter_text>6.12 Debugging 6.13 Glossary 6.14 Exercises<jupyter_code># exe 6.5
Mystr = "X-DSPAM-Confidence:0.8475"
idx_comm = Mystr.find(":")
float(Mystr[idx_comm+1:])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13796430294259526, 'fraction_numerical': 0.03183791606367583, 'mean_word_length': 6.597069597069597, 'pattern_counts': {'":': 4, '<': 38, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '171125', 'license': 'MIT', 'n_tokens_mistral': 863, 'n_tokens_neox': 823, 'n_words': 180, 'path': 'Python4Every1/Chapter 6 Strings.ipynb', 'repo_name': 'qiyangjie/Python4Every1-KeyNotes', 'size': '2092'}