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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Read the string "I am James Bond" and assign it to a variable a.
    1. Count the length of string.
    2. Count the occournace of letter ‘B”
    3. 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()

  1. Split the string "I am James Bond".
    1. 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”.

    1. Split based on the “,” delimited
    2. Split the string to the maximum of 0, 1, and 2 numbers. What do you observe?
    3. Hint: General formula is str.split(separator, maxsplit)  

      1. Use the a1.split(',') .
      2. a1.split(',' , 0)
Expert Solution
Python Program

#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

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education