Basic Strings
Basic Strings
"
print(len(astring))
O/P
sprint(astring.index("o")) OP 4
afewwords = astring.split("l")
print(afewwords)
out
['He', '', 'o wor', 'd!']
CODE
<script.py> output:
Length of s = 20
The first occurrence of the letter a = 8
a occurs 2 times
The first five characters are 'Strin'
The next five characters are 'gs ar'
The thirteenth character is 'a'
The characters with odd index are 'tig r wsm!'
The last five characters are 'some!'
String in uppercase: STRINGS ARE AWESOME!
String in lowercase: strings are awesome!
String starts with 'Str'. Good!
String ends with 'ome!'. Good!
Split the words of the string: ['Strings', 'are', 'awesome!']
In [1]:
CODE 1
s = "Hey there! what should this string be?"
# Length should be 20
print("Length of s = %d" % len(s))
OUTPUT
<script.py> output:
Length of s = 38
The first occurrence of the letter a = 13
a occurs 1 times
The first five characters are 'Hey t'
The next five characters are 'here!'
The thirteenth character is 'h'
The characters with odd index are 'e hr!wa hudti tigb?'
The last five characters are 'g be?'
String in uppercase: HEY THERE! WHAT SHOULD THIS STRING BE?
String in lowercase: hey there! what should this string be?
Split the words of the string: ['Hey', 'there!', 'what', 'should', 'this', 'string', 'be?']