String Data-type in Python

Strings

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. String Data-type in Python is  immutable data type which means after assigning value to a variable we can’t modify data  from the string variable.

str-datatype in python

String data-type in Python programming language :

  • For string data type we use str() keyword 
  • 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.
  • There are several in built functions for strings , namely , replace(), isupper(), islower(), join(), and so on..  
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