In: Computer Science
Python has built-in methods to support different manipulations of string data types. Answer what the following code will print following each Python method.
Str = "Tennessee State University"
print(len(str)) print(str.lower()) print(str.upper())
substr = “State”
print (str.index(substr)) print (str.startswith(“State”)) print (str.split()) print (str.find(substr)) print (str.partition(“State”))
myList = str.split() for words in myList: print (words)
newStr = “TN, TX, NY, MA, VA, PA, LA, CA” myStates = newStr.split(‘,’) print (myStates) Show with examples if the above string operations are supported by C++ library OR the Java String class.
str = "Tennessee State University"
print(len(str)) ###prints length of string ie.26
print(str.lower())##prints all letters in lower case ie: tennessee
state university
print(str.upper())#prints TENNESSEE STATE UNIVERSITY
substr ="State"
print (str.index(substr))# prints 10
print (str.startswith("State")) #prints false
print (str.split())# prints ['Tennessee', 'State',
'University']
print (str.find(substr)) #prints 10
print (str.partition("State")) # prints ('Tennessee ', 'State', '
University')
myList = str.split()
for words in myList:
print (words) #prints Tennessee State University
newStr = "TN, TX, NY, MA, VA, PA, LA, CA"
myStates = newStr.split(',')
print (myStates) #prints ['TN', ' TX', ' NY', ' MA', ' VA', ' PA',
' LA', ' CA']
##############output:##########
26
tennessee state university
TENNESSEE STATE UNIVERSITY
10
False
['Tennessee', 'State', 'University']
10
('Tennessee ', 'State', ' University')
Tennessee
State
University
['TN', ' TX', ' NY', ' MA', ' VA', ' PA', ' LA', ' CA']
################ java code###########
public class Mystring {
public static void main(String[] args) {
String str = "Tennessee State
University";
System.out.println(str.length());
System.out.println(str.toLowerCase());
System.out.println(str.toUpperCase());
String substr="State";
System.out.println(str.indexOf(substr));
System.out.println(str.startsWith(substr));
String a[]=str.split(" ");
System.out.print("[");
for(int
i=0;i<a.length;i++)
System.out.print(a[i]+", ");
System.out.println("]");
System.out.println(str.indexOf(substr));
String
b[]=str.split("State");
System.out.print("(");
for(int
i=0;i<b.length;i++)
System.out.print(b[i]+", ");
System.out.println(")");
a=str.split(" ");
for(int
i=0;i<a.length;i++)
System.out.println(a[i]);
String newStr="TN, TX, NY, MA, VA,
PA, LA, CA";
a=str.split(" ");
System.out.print("[");
for(int
i=0;i<a.length;i++)
System.out.print(a[i]+", ");
System.out.println("]");
}
}