python looks for an instance detail of a string

  • 2020-05-24 05:46:28
  • OfStack

The method to find the specified string in python is as follows:

code


# The query 
def selStr():
  sStr1 = 'jsjtt.com'
  sStr2 = 'com'
  #index Query a string and return the index 
  nPos = sStr1.index(sStr2)
  if(nPos >=0):
    print 'sStr1 Included in the sStr2 The characters in '
  print nPos
   
  #find  Method if no query is returned -1
  nPos2 = sStr1.find('abc')
  print nPos2
  # Query to the location of the return character 
  print sStr1.find('com')
   
selStr();

python splits strings


def split():
  sStr1 = 'ab,cde,fgh,ijk'
  sStr2 = ','
  # with find Find the index location where the comma is 
  sStr1 = sStr1[sStr1.find(sStr2) + 1:]
  print sStr1
  # use split Function splits a string 
  s = 'ab,cde,fgh,ijk'
  result = s.split(',')
  print(result)
  print(result[0])
split();

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: