Text Sequence Type in Python

Text Sequence Type in Python

Text Sequences are typically represented using the string data type. A string is a sequence of characters and is commonly used to store and manipulate text data. Strings are defined using single, double or triple quote.

What is text sequence types in python

Text Sequence Type

In python , text sequence are represented using string data type. String object is used to handle string or character data type. 

Strings are not mutable but Strings allow various type of operation to perform. 

  • ‘String using single quote’ .
  • “String using double quote”. 
  • ”’String using Triple quote”’.

Strings are not mutable but we can typecast the string into a list  and it becomes mutable.Latter we can use join keyword and print it as a string.

Example : 

  • slicing 
  • concat two or more strings 
  • Indexing
text sequence types in python

Operations : 

  • capitalize()
    • Convert first character of string into capital letter.
  • count(ch/str, start, end)
    • Return the number of occurrence of a  character or string.
  • find(ch/str, start, end)
    • Return the index value of the first occurance of string or character .
  • center(width, char)
    • It will return a new string which will be padded with specific character (default-space).
  • isalnum()
    • Check alphanumeric character.
  • format(*args, **kwargs)
    • Format the string to generate required output.
  • isalpha() 
    • Check the strings contains only alphabet.
  • isdigit()
    • Check digit characters.
  • isspace()
    • Retruns True if strings contains whitespace.
  • join(iterable)
    • Returns a string in which the elements of sequence have been joined by str separator.
  • ljust(width,char)
    • Returns  left aligned string expanding the given width.
  • rjust(width, char)
    • Returns  right aligned string expanding the given width.
  • lower()
    • Converts a string into lower case string.
  • upper()
    • Converts a string into upper case string.
  • split(sep=None, maxsplit=-1)
    • Returns a list of strings after breaking the given string by the specified separator.
  • strip(chars)
    • Returns a copy of the string with both leading and trailing characters removed.

  • swapcase()
    • Convert lowercase to uppercase and vice versa.
  • zfill(width)
    • Convert the string by adding leading zeros with it.
  • endswith()
    • Returns true if the string ends with the specified value. 
  • replace()
    • Returns a string where a specified value is replaced with a specified value.

Example :

Run
#pyhton program 
#capitalize 
s='prepInsta'
s=s.capitalize()
print('Capitalize-',s) 
#count 
x=s.count('P')
print('number of "P" :' , x)
#find
x=s.find('e')
print('First occurance of e :' , x)
#center
s=s.center(11,'x')
print('Center :' , s)
#isalnum 
print('Is s is alphanumerix :' , s.isalnum())
#format 
print('Hello {}'.format('Prepsters')) 
#isspace
print('String contains whitespace :' , s.isspace())
#join
list1 = ['P','r','e','p','I','n' ,'s','t','a']  
print("".join(list1))
#ljust 
print('string after ljust :' ,s.ljust(11,'x')) 
#upper 
s='PrepInsta'
print('Upper case of string :', s.upper()) 
#split 
s='Prep Insta'
print('After spliting :' , s.split()) 
#endswith
s='PrepInsta'
print('Prepinsta ends with a :' , s.endswith('a'))
Output :
Capitalize- Prepinsta
number of "P" : 1
First occurance of e : 2
Center : xPrepinstax
Is s is alphanumerix : True
Hello Prepsters
String contains whitespace : False
PrepInsta
string after ljust : xPrepinstax
Upper case of string : PREPINSTA
After spliting : ['Prep', 'Insta']
Prepinsta ends with a : True

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

One comment on “Text Sequence Type in Python”