Monday, June 12, 2023

#PYTHON(DAY47)Example Programs

                                         #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

Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...