String methods in Python

#----------------------------- 1- Upper & Lower conversion  --------------------------

# Converting a string to uppercase and lowercase
string = "Hello, World!"
upper = string.upper()  # converts all string to lowercase
lower = string.lower()  # converts all string to uppercase
print("Upper :",upper)
print("Lower : ",lower)
#----------------------------- 2-  Stripping in String------------------------------


# Removing leading and trailing whitespace from a string
string = "   Python Programming  in Webgapp "
strip = string.strip()   # Removes the unwanted white spacses in a string
print(strip)
#----------------------------- 3- Splitting in String ------------------------------


# Splitting a string into a list of words
web = "Learn , Python , from WebGapp"
split = web.split("a") # Removes all 'a' and splits as before and after 'a'
print(split)  # ['Le', 'rn , Python , from WebG', 'pp']
#----------------------------- 4- Joining in String ------------------------------


# Joining a list of strings into one
web = ["Hello", "Programs","- by","WebGapp"]
join = " ".join(web)  # Joins all word in the list with " "
print(join)
#----------------------------- 5- Replacing in String ------------------------------


# Replacing text in a string
web = "Python is Easy!"
replace = web.replace("Easy", "awesome") # Easy is replaced by awesome
print(replace)
#----------------------------- 6- Finding in String ------------------------------


# Finding the first occurrence of a substring
web = "Python is easy, Python is fun!"
index = web.find("easy") # returns the index of first occurrance of the text
print(index)
#----------------------------- 7- Counting in String ------------------------------


# Counting the occurrences of a substring
web = "Python is easy, Python is fun!, Python is is is so good"
count = web.count("is")  #  counts the number of times the string is repeated
print(count)
#----------------------------- 8- Startwith & Endwith in String ----------------------


# Checking if a string starts or ends with a specified substring
web = "Hello, World! Welcome"
starts = web.startswith("Webgapp") # True if string starts with the given  string is same
ends = web.endswith("Welcome")     # True if string ends with the given string is same
print(starts) # Fals
print(ends)   # True
#----------------------------- 9- isalpha, isdigit, isalphanum in String -------------


# Checking if a string consists of digits, alphabetic characters, or alphanumeric characters
number = "12345"
string = "abc"
alphanum = "abc123"
numeric = number.isdigit()  # True if string is a number 
alpha = string.isalpha()    # True if string is alphabets
alphanumeric = alphanum.isalnum() # True if string contains both number and alphabets
print(numeric)
print(alpha)
print(alphanumeric)
#----------------------------- 10- Capitalize & Title in string ----------------------


# Capitalizing the first letter of a string and converting to title case
web = "python programming is fun with WebGapp"
capitalized = web.capitalize() # makes the first letter upper case in a string
title = web.title()   # makes every first letter after white spaces as uppercase
print(capitalized)
print(title)
#----------------------------- 11- SwapCase in String ------------------------------


# Swapping the case of characters in a string
web = "PyThOn Is FuN"
swapped = web.swapcase()  # converts all upeer to lower and lower to upper case
print(swapped)

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available