Python string programs
Python string programs
# using len
str = "geeks"
print(len(str))
# Python code
# input string
s = string.split()[::-1]
l = []
for i in s:
l.append(i)
print(" ".join(l))
# initializing string
test_str = 'geeksforgeeks 33 is best'
# printing result
print("The Characters Frequency avoiding spaces : " + str(res))
Python program to print even length words in a string
# Python code
# To print even length words in string
#input string
n="This is a python language"
#splitting the words in a given string
s=n.split(" ")
for i in s:
#checking the length of words
if len(i)%2==0:
print(i)
# initializing string
test_str = 'geeksforgeeks'
res = ''
for idx in range(len(test_str)):
# uppercasing later half
if idx >= hlf_idx:
res += test_str[idx].upper()
else:
res += test_str[idx]
# printing result
print("The resultant string : " + str(res))
Python program to capitalize the first and last character of each word in a string
# Python program to capitalize
# first and last character of
# each word of a String
# Driver's code
s = "welcome to geeksforgeeks"
print("String before:", s)
print("String after:", word_both_cap(str))
Python program to check if a string has at least one letter and one number
def checkString(str):
string = string.lower()
# Driver code
if __name__ == "__main__" :
string = "SEEquoiaL"
# calling function
check(string)
Python | Count the Number of matching characters in a pair of string
// C++ code to count number of matching
// characters in a pair of strings
# include <bits/stdc++.h>
using namespace std
// Driver code
int main()
{
string str1 = "aabcddekll12@"
string str2 = "bb2211@55k"
count(str1, str2)
}
Python program to count number of vowels using sets in given string
string = "GeekforGeeks!"
vowels = "aeiouAEIOU"
# Driver program
if __name__ == "__main__":
str = "geeksforgeeks"
print ("Without Order = ",removeDupWithoutOrder(str))
print ("With Order = ",removeDupWithOrder(str))
Python – Least Frequent Character in String
# Python 3 code to demonstrate
# Least Frequent Character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing result
print ("The minimum of all characters in GeeksforGeeks is : " + str(res))
Python | Maximum frequency character in String
# Python 3 code to demonstrate
# Maximum frequency character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing result
print ("The maximum of all characters in GeeksforGeeks is : " + str(res))