0% found this document useful (0 votes)
3 views8 pages

String

The document contains various string manipulation techniques implemented in Python, including reversing strings, checking for palindromes, counting characters, and identifying special characters. It also demonstrates how to manipulate cases, find substrings, and print patterns without nested loops. Additionally, the document provides examples for handling user input and processing strings in different ways.

Uploaded by

gsbarashidkhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

String

The document contains various string manipulation techniques implemented in Python, including reversing strings, checking for palindromes, counting characters, and identifying special characters. It also demonstrates how to manipulate cases, find substrings, and print patterns without nested loops. Additionally, the document provides examples for handling user input and processing strings in different ways.

Uploaded by

gsbarashidkhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

STRING MANUPLIATION

#reversing a digit
str1=input("enter a string:")
for i in range(-1,-len(str1)-1,-1):
print(str1[i])
for i in range(len(str1)-1,-1,-1):
print(str1[i])
print(str1[::-1])
print(str1[-1::-1])
'''
'''
#straight and opposite
str1=input("enter a string:")
a=0
for i in range(len(str1)-1,-1,-1):
print(str1[a],str1[i],sep=" ")
a+=1
'''
'''
#checking 0
count=0
str1=input("enter a string:")
for i in range(len(str1)):
if str1[i]=='0':
count+=1
if count>0:
print("Zero is there")
else:
print("Zero is not there")
#checking 0
str1=int(input("enter a string:"))
num=str(str1)
if '0' in num:
print("zero is there")
else:
print("zero is not there")
'''
'''
#printing pattern without using nested loop
for a in range(1, 6):
print('#' * a)
str1='#'
pattern=""
for a in range(5):
pattern+=str1
print(pattern)
'''
'''
#To check a string palindrome
str1=input("enter a string1:")
if str1==str1[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
#To check a number palindrome
str2=int(input("Enter a number:"))
if str(str2)==str(str2)[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
# Non- overlapping count
a=str("abracadabra")
print([Link]("ab",0,5))
#Overlapping count
a='aaaa'
count=0
for i in range(len(a)):
if a[i:i+2]=="aa":
count+=1
print(count)
'''
#Function of count using find or to find the occurance of a given
substring in a string
str1=input("Enter a string")
sub=input("Enter substring")
count=0
pos=[Link](sub)
while pos!=-1:
count+=1
pos=[Link](sub,pos+len(sub))
print(count)
'''
#To check if there are spaces and special characters in a string and
find their index
count=0
str1=input("Enter a string")
for i in range(0,len(str1)):
if str1[i].isalnum()!=True:
print("The speical character is at index",i)
count+=1
print("There are total",count,"special characters present")
'''
#Lower characters to upper and upper characters to lower-swapcase
str1=input("Enter a string")
str2=''
for i in range(len(str1)):
if str1[i].islower()==True:
str2+=str1[i].upper()
else:
str2+=str1[i].lower()
print(str2)
'''
str1 = input("Enter a string: ")
uppercount, lowercount, alphacount, digcount, symcount = 0, 0, 0, 0,
0
for i in range(len(str1)):
if str1[i].isupper():
uppercount += 1
if str1[i].islower():
lowercount += 1
if str1[i].isalpha():
alphacount += 1
if str1[i].isdigit():
digcount += 1
if not str1[i].isalnum() and str1[i] != " ":
symcount += 1

print("The number of uppercase:", uppercount)


print("The number of lowercase:", lowercount)
print("The number of alphabets:", alphacount)
print("The number of digits:", digcount)
print("The number of symbols:", symcount)'''
'''
num=float(input("enter a decimal number"))
num1=str(num)
part=([Link]('.'))
print(part[2])
'''
'''
print("Enter your school motto one by one")
c=2
b=input("Enter 1st word:")
motto=b
while True:
print("more words?")
a=input()
if [Link]()=="yes":
print("Enter word:",c)
a1=input()
c+=1
motto= motto+" "+a1
or
[Link](a1)
else:
break
motto = " ".join(words)
print(motto)
'''
'''
str1=input("Enter a string")
split1=[Link](" ")
str2=""
for i in range(len(split1)):
s=split1[i].capitalize()
str2+=s+" "
print(str2)'''
'''
str1=input("Enter a string")
maxs=""
sub=""
for ch in str1:
if ch not in "AEIOUaeiou":
sub+=ch
else:
if len(sub)>len(maxs):
maxs=sub
sub=" "
if len(sub)>len(maxs):
maxs=sub
print("The longest chain of subtring of consonants is:", maxs)
'''
'''
str1=input("enter a string:")
str2=''
for i in range(len(str1)):
if i%2==0:
str2+=str1[i].capitalize()
else:
str2+=str1[i]
print(str2)
s = input("enter a string: ")
a = input("enter a letter from the string: ")
s1=''
for i in range(len(s)):
if s[i] == a:
s1+=str(i)+','
positions=[Link](",")
print("The places at which the letter is occurring is",
positions)'''
'''
s = input("enter a string: ")
for i in s:
print(i*2, end="")
'''
'''
s = input("enter a string: ")
a = ""
for i in s:
if i == ",":
continue
elif [Link]()==True:
a += [Link]()
else:
a += i
print(a)
'''
'''
s = input("enter a string: ")
count=0
for i in s:
if [Link]()==True:
count+=1
else:
count+=0
if count>0:
print("Digit is there")
else:
print("Digits are not there")'''
'''
s = input("enter a string: ")
a=[Link](" ")

for i in a:
if [Link]()!=True:
continue
else:
print(i,end=" ")'''
'''
s = input("enter a string: ")
s1=""
for i in s:
if i in "AEIOUaeiou":
i="*"
s1+=i
else:
s1+=i
print(s1)
'''

You might also like