In [4]: #string concatenation
firstname="saran"
lastname="raj"
fullname=firstname+lastname
print(fullname)
fullname=firstname+" "+lastname
print(fullname)
print(firstname,lastname)
fullname=firstname-lastname
saranraj
saran raj
saran raj
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 9
7 print(fullname)
8 print(firstname,lastname)
----> 9 fullname=firstname-lastname
TypeError: unsupported operand type(s) for -: 'str' and 'str'
In [6]: firstname="saran"
lastname="raj"
fullname=firstname*lastname
print(fullname)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], line 3
1 firstname="saran"
2 lastname="raj"
----> 3 fullname=firstname*lastname
4 print(fullname)
TypeError: can't multiply sequence by non-int of type 'str'
In [8]: firstname="saran"
result=firstname*4
print(result)
saransaransaransaran
In [14]: #printing the string statements
a="learning python"
b="gurukula"
print("you are " +a+" in "+b)
print("you are {a} in {b}".format(a=a,b=b))
print("you are {} in {}".format(a,b))
you are learning python in gurukula
you are learning python in gurukula
you are learning python in gurukula
In [16]: #string indexing
a= "hello"
a[0],a[1],a[2],a[3],a[4],
Out[16]: ('h', 'e', 'l', 'l', 'o')
In [17]: #string indexing - negative indexing
a= "hello"
a[-5],a[-1],a[-2],a[-3],a[-4]
Out[17]: ('h', 'o', 'l', 'l', 'e')
In [19]: #string slicing [start:end-1]
a= "hello"
a[0:4]
a[0:5]
Out[19]: 'hello'
In [22]: #string slicing [start:end-1]
a= "hello"
a[1:4]
a[1:5]
Out[22]: 'ello'
In [23]: #string slicing [start:end-1]
a= "hello"
a[:5]
Out[23]: 'hello'
In [24]: #string slicing [start:end-1]
a= "hello"
a[:]
Out[24]: 'hello'
In [25]: #negative slicing [start:end-1]
a= "hello"
a[-5:-1]
Out[25]: 'hell'
In [26]: #negative slicing [start:end-1]
a= "hello"
a[-5:]
Out[26]: 'hello'
In [27]: #negative slicing [start:end-1]
a= "hello"
a[:]
Out[27]: 'hello'
In [28]: # back progpagation is not possible
a[3:0]
Out[28]: ''
In [32]: # step argument [start:end:step]
a="happy learning"
a[0::2]
a[0::3]
a[0::1]
a[0::4]
Out[32]: 'hyan'