Python String

String is a group of one or more characters enclosed in Single or Double Quote.
Example: –

  • “Win”
  • ‘Corporate’
  • “A”
  • “W001”

String Operation

Concatenation – Joining the Two Text or String values using “+” Symbol.
Ex: fname=”Sanjay” + ” K”

String Length – Finding the No. of characters in the String
Ex:len(“Win”) = 3

Indexing – Returns the character from the specific position from the String
Ex:
sname=”Sanjay”
sname[0]=”S”

Slicing – Returns group of Characters from the specified position.
Ex:
sname=”Sanjay”
sname[0:3]=”San”

Repeation – prints the string value specified no. of times.
Ex: n=”Sanjay” * 20 [Sanjay will be printed 20 times]

#String Operation in Python
sname=”Sanjay is good boy”

fname=”Sanjay” + ” K”
print(“Concatenation : ” + fname)

print(“Indexing :” + sname[0])

print(“Slicing”, sname[3:6])

print(‘Number of characters’)
print(len(sname))

n=”*” * 20
print(“Repeation : ” + n)

Win Corporate Training
website: http://www.wincorptrg.com
View My Profile

Advertisements