Skip to content

Latest commit

 

History

History
101 lines (99 loc) · 1.87 KB

41. Unit 4 - Lesson 2.md

File metadata and controls

101 lines (99 loc) · 1.87 KB

Built-in String Methods

Q1. 1,2,6
Q2.

str1 = input("str: ")
# make string str1 into all upper case letters.
print(str1.upper())
print(str1.title())
# make string str1 into only every word of first letter into upper case.
# split every word of a string str1 with space.
print(str1.split())
# fill str1 with '%' special characer 25 width
print(str1.center(25,"%"))
# make string str1 into small letters.
print(str1.lower())
str2 = '@'
print(str2.join(str1))
print(str1.replace("Strings","Tuples"))
# join string str2 with str1
# replace a word 'Strings' with 'Tuples'.

Q3. 2,3,4
Q4.

a=input("str1: ")
b=input("str2: ")
print(a*3 +b)

Q5.

print("Python provides built-in libraries\nUsing Python we can implement more and more applications\n\tPython is Robust")

Q6.

#use len() to find length of String
str1=input("str1: ")
str2=input("str2: ")
if len(str1)>len(str2):
	print(str2+str1+str2)
elif len(str2)>len(str1):
	print(str1+str2+str1)
else:
	print("strings are same length")

Q7.

a=input("str: ")
if (a.startswith('Python')) and (a.endswith('programming')):
	print("valid")
else:
	print("invalid")
print("character with min val:",min(a))
print("character with max val:",max(a))

Q8.

# Note: Python and python are different.
a=input("str: ")
if a.startswith('Python'):
	print("str is:",a)
else:
	print("str after adding 'Python':","Python "+a)

Q9.

# Take a string input form the user
a=input("str: ")
# Reverse the string using slicing operator
print(a[::-1])

Q10. Need Solution
Q11. Need Solution
Q12.

# write a program to print the every character in the given string twice
a=input("str: ")
res=""
for i in a:
	res=res+i*2
print("result: ",res)

Q13. Need Solution
Q14. Need Solution
Q15. Need Solution
Q16. Need Solution
Q17. Need Solution
Q18. Need Solution
Q19. Need Solution