#PYTHON(DAY47)
Example programs
1) Python Program to Capitalize the First Character of a String
my_string = "programiz is Lit"
print(my_string[0].upper() + my_string[1:])
And the output is:
Programiz is Lit
2) Python Program to Count the Number of Occurrence of a Character in String
count = 0
my_string = "Programiz"
my_char = "r"
for i in my_string:
if i == my_char:
count += 1
print(count)
And the output is:
2
3) Python Program to Trim Whitespace From a String
my_string = " Python "
print(my_string.strip())
And the output is:
Python
No comments:
Post a Comment