In [10]:
word = 'computer'
#print first letter of word
print word[0]
print word[1]
print word[7]
print word[-1]
print word[-2]
print word[1:5]
print word[3:-1]
print word[1:-2]
print word[3:]
print word[:4]
In [11]:
print "The length of word is", len(word)
In [12]:
word = raw_input("Please type a word: ")
print "The word you entered is", len(word), "characters long!"
In [15]:
#take a string from the user
#print out each character individually
word = raw_input("Please give me a word: ")
count = len(word)
x = 0
while x < count:
print word[x]
x = x + 1
In [17]:
word = raw_input("Please give me a word: ")
for character in word:
print character
In [19]:
word = raw_input("Please give me a word: ")
for character in word:
print character
if character == 'g':
break
In [20]:
word = 'fluffy'
word[0] = 'x'
In [21]:
word = 'bob'
word = 'B' + word[1:]
print word
In [22]:
def find(word, letter):
index = 0
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
print find( "puppy dog", "y" )
In [25]:
phrase = "puppy dog"
space = find( phrase, " " )
print phrase[:space]
print phrase[space+1:]
In [30]:
def find(word, letter, index):
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
print find( "puppy dog", "y", 5 )
In [31]:
word = "banana"
print word.upper()
In [32]:
print word.find('a')
In [33]:
print "dog".upper()
In [ ]: