Str Data-type in Python

String Data-type 

In python string is collection of characters under single or double or triple quotes. 

In python there is nothing like character data type , a single character is a string with length 1. The string is an immutable data type in python means we can’t append or remove item or element from the string variable.

str-datatype in python

String data-type in Python programming language :

  • We can perform many operations on String.
  • We can add two string data-type using ‘+’ operator.
  •  We can convert a string into a list then we can append or remove element from them.
  • String supports indexing.
use of str in python

Example :

#python
#creating a string
 
print(‘single quotes :’)
s=‘Hello Prepsters welcome to PrepInsta’
print(s)
 
print(“doubel quotes :”)
s=“Hello Prepsters welcome to PrepInsta” 
print(s)
 
print(”’triple quotes :”’)
s=”’Hello Prepsters welcome to PrepInsta”’
print(s)
 
print(‘add operation :’
s1= ‘Hello Prepsters ‘ 
s2=‘welcom to PrepInsta’
s=s1+s2 
print(s) 
 
print(‘conver string into list:’)
x=list(s)
print(type(x)) 
 
print(‘Indexing :’)
s=‘abcdef’
print(‘first charcter is ;’,s[0])
print(‘last charcter is :’ ,s[-1])
Output:

single quotes :
Hello Prepsters welcome to PrepInsta
doubel quotes :
Hello Prepsters welcome to PrepInsta
triple quotes :
Hello Prepsters welcome to PrepInsta
add operation :
Hello Prepsters welcom to PrepInsta
conver string into list:
<class 'list'>
Indexing :
first charcter is ; a
last charcter is : f