# Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

## String-based python interview questions

A string is a collection of chars, we can store multiple characters set into String.

The base Index of String will be started from 0 to size-1 similar to LIST.but all elements of String is connected with each other.

we can write String is single quote (' '),double quote (" ") and triple quote (""").

a= 'hello'  ;  //Single Quote String

a = "hello"  //Double quote String

a= """hello""" //Triple quote String

s = "hello"

s= h
s= e
s=l
s=l
s=o

Q1) WAP to count the total vowel and consonant in String?

Solution:-

s = "hello"
c1=0
c2=0
for i in range(0,len(s)):
if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
c1=c1+1
else:
c2=c2+1
print("total vowel is ",c1," total consonent is ",c2)

Q2)  WAP to check that String is palindrome or not?

s= input("enter string")  #aaaaaa
size= len(s)-1
c=1
for i in range(0,(len(s))//2):
if s[i]!=s[size-i]:
c=0
print("not pallindrom")
break

if c==1:
print("pallindrom")

Q3)  WAP to find max char in String?

Solution:-
s = "hellop"
max=s
for i in range(1,len(s)):
if max<s[i]:
max=s[i]

print(max)

Q)WAP to validate email?

Solution:-
s = "@abcg.mailcom"
atpos=0
dotpos=0
for i in range(0,len(s)):
if s[i]=="@" :
atpos=i

if s[i]=="." :
dotpos=i

if atpos>0 and (dotpos-atpos)>=2:
print("valid email id")

else:
print("invalid email id")

WAP to validate the mobile number?

WAP to validate first name and last name?

1234 //w

12345//w

S@\$1234 //Strong

123s@\$123 //Strong

WAP to find the largest palindrome in String?

WAP to find max char in each string in a word?

WAP to replace white space with an underscore?

WAP to count total upper case, lower case, number, special char in String?

s = "abCA@\$_123"
sc=0
chkcase=0
for data in s:
if data in('@','\$','_','#','!'):
sc=sc+1
if ord(data)>=65 and ord(data)<=91:
chkcase=chkcase+1

if len(s)>5 and sc>2 and chkcase>1:

else:

WAP to reverse a string in words?

Predefine method of String in Python:-

MethodDescription
Python String capitalize()Converts first character to Capital Letter
Python String center()Pads string with specified character
Python String casefold()converts to casefolded strings
Python String count()returns occurrences of substring in string
Python String endswith()Checks if String Ends with the Specified Suffix
Python String expandtabs()Replaces Tab character With Spaces
Python String encode()returns encoded string of given string
Python String find()Returns the index of first occurrence of substring
Python String format()formats string into nicer output
Python String index()Returns Index of Substring
Python String isalnum()Checks Alphanumeric Character
Python String isalpha()Checks if All Characters are Alphabets
Python String isdecimal()Checks Decimal Characters
Python String isdigit()Checks Digit Characters
Python String isidentifier()Checks for Valid Identifier
Python String islower()Checks if all Alphabets in a String are Lowercase
Python String isnumeric()Checks Numeric Characters
Python String isprintable()Checks Printable Character
Python String isspace()Checks Whitespace Characters
Python String istitle()Checks for Titlecased String
Python String isupper()returns if all characters are uppercase characters
Python String join()Returns a Concatenated String
Python String ljust()returns left-justified string of given width
Python String rjust()returns right-justified string of given width
Python String lower()returns lowercased string
Python String upper()returns uppercased string
Python String swapcase()swap uppercase characters to lowercase; vice versa
Python String rstrip()Removes Trailing Characters
Python String strip()Removes Both Leading and Trailing Characters
Python String partition()Returns a Tuple
Python String maketrans()returns a translation table
Python String rpartition()Returns a Tuple
Python String translate()returns mapped charactered string
Python String replace()Replaces Substring Inside
Python String rfind()Returns the Highest Index of Substring
Python String rindex()Returns Highest Index of Substring
Python String split()Splits String from Left
Python String rsplit()Splits String From Right
Python String splitlines()Splits String at Line Boundaries
Python String startswith()Checks if String Starts with the Specified String
Python String title()Returns a Title Cased String
Python String zfill()Returns a Copy of The String Padded With Zeros
Python String format_map()Formats the String Using Dictionary
Python any()Checks if any Element of an Iterable is True
Python all()returns true when all elements in iterable is true
Python ascii()Returns String Containing Printable Representation
Python bool()Converts a Value to Boolean
Python bytearray()returns array of given byte size
Python bytes()returns immutable bytes object
Python compile()Returns a Python code object
Python complex()Creates a Complex Number
Python enumerate()Returns an Enumerate Object
Python filter()constructs iterator from elements which are true
Python float()returns floating point number from number, string
Python input()reads and returns a line of string
Python int()returns integer from a number or string
Python iter()returns iterator for an object
Python len()Returns Length of an Object
Python max()returns largest element
Python min()returns smallest element
Python map()Applies Function and Returns a List
Python ord()returns Unicode code point for Unicode character
Python reversed()returns reversed iterator of a sequence
Python slice()creates a slice object specified by range()
Python sorted()returns sorted list from a given iterable
Python sum()Add items of an Iterable
Python zip()Returns an Iterator of Tuples

If you have any doubt in programming or join online classes then you can contact us by comment .

1. s = "ssssss ram madam jjjjjjjjjj kkk ppp ram hari sdafdfsafds dzfv"
s1= s+ " ";
lst=[]
data=''
for i in range(0,len(s1)):

if s1[i]!= " ":
data=data+s1[i]
else:
lst.append(data)
data=''

#print(lst)
m=0
for i in range(0,len(lst)):
s2=lst[i]
for j in range (0 ,len(s2)//2):
if s2[j]!=s2[(len(s2)-1)-j]:
break
else:
if m<len(s2):
m=len(s2)
index=i

print(lst[index])