Read the string "I am James Bond" and assign it to a variable a. Count the length of string. Count the occournace of letter ‘B” Count the total number of characters without the space in the above string. Hint: use the len(a) function to identify the length. a.count(‘B’) to identify the occurance a.count(‘ ’) to find out the space. 2.Convert the string "I am James Bond" to all uppercase and lowercase characters. Hint: use the a.upper() and a.lower() Split the string "I am James Bond". What is the type of output? Hint: use the split() function. 3. print(type(a.split())) 4. Create a new variable a1, and assign “he , is, a, good, boy”. Split based on the “,” delimited Split the string to the maximum of 0, 1, and 2 numbers. What do you observe? Hint: General formula is str.split(separator, maxsplit) Use the a1.split(',') . a1.split(',' , 0)
- Read the string "I am James Bond" and assign it to a variable a.
- Count the length of string.
- Count the occournace of letter ‘B”
- Count the total number of characters without the space in the above string.
Hint: use the len(a) function to identify the length.
a.count(‘B’) to identify the occurance
a.count(‘ ’) to find out the space.
2.Convert the string "I am James Bond" to all uppercase and lowercase characters.
Hint: use the a.upper() and a.lower()
- Split the string "I am James Bond".
- What is the type of output?
Hint: use the split() function.
3. print(type(a.split()))
4. Create a new variable a1, and assign “he , is, a, good, boy”.
-
- Split based on the “,” delimited
- Split the string to the maximum of 0, 1, and 2 numbers. What do you observe?
-
Hint: General formula is str.split(separator, maxsplit)
- Use the a1.split(',') .
- a1.split(',' , 0)
#1.
a = input()
#Count the length of string.
length = len(a)
print("Length:", length)
#Count the occournace of letter ‘B”
occ = a.count('B')
print("Occurances of 'B':", occ)
#Count the total number of characters without the space in the above string.
sp = a.count(' ')
print("Number of characters without the space:", (length - sp))
print()
#2.
#Convert the string "I am James Bond" to all uppercase and lowercase characters.
x = a.upper()
y = a.lower()
print(x)
print(y)
#Split the string "I am James Bond"
lst = a.split()
print(lst)
print()
#3.
print(type(a.split()))
print()
#4.
#Create a new variable a1, and assign “he , is, a, good, boy”.
a1 = "he , is, a, good, boy"
#Split based on the “,” delimited
x1 = a1.split(',')
print(x1)
#Split the string to the maximum of 0, 1, and 2 numbers.
j = a1.split(',' , 0)
k = a1.split(',' , 1)
l = a1.split(',' , 2)
print(j)
print(k)
print(l)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images