-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusingsplit.py
More file actions
24 lines (18 loc) · 826 Bytes
/
usingsplit.py
File metadata and controls
24 lines (18 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This program will demonstrate the Python split() function.
# It will split a phrase in a string into words
# create string with phrase
hamlet = "To be or not to be, that is the question."
# print the string as entered
print ("The string as entered is:", hamlet)
# split the string and place it into a list called "hamletsplit"
hamletsplit = hamlet.split()
# print out the new list which is the phrase split up by word
print ("The phrase split up is:", hamletsplit)
# print blank line
print ()
# using the len() function, find out how long the list "hamletsplit" is
# then print out each element of the list on its own line, ie:
# hamletsplit[0], hamletsplit[1], hamletsplit[2] etc.
print ("Now we are going to print each element on its own line:")
for alpha in range(len(hamletsplit)):
print (hamletsplit[alpha])