Wednesday, 20 July 2016

String in python

String  in python is  a sequence of characters .  This is the most popular data type in python. We create the string simply using quotes .In python single quote or double quote  both have the same behaviour . If you define a string using single quote python will treat this like as string and if you also  define any string using double quote python will also treat this  like as  string  also.

For example :

var1=”hello”
var2=’python’

String Concatenation :

String also have operation symbols . That means  if you want to  add two strings  you can easily concatenate two strings using (+) operator. For example :

>>> a='very'
>>> b='cool'
>>> print a+b
verycool

Accessing value in string :

Pythondoes not support a character type . These are treated as string  of length one that’s why this considered as a substring . For accessing substring we will  use square brackets for slicing along with the index or indices to obtain your substring .
For exaple:

var1=’hello python’
var2=’python world’

print var1[0]
print var2[3]

>> output would be ;   h
>>output would be:    h
softcrayons is a python training institute in Ghaziabad/Noida.

No comments:

Post a Comment