For details about whether an instance exists in the python query string, refer to the python instance.

Source: Internet
Author: User

For details about whether an instance exists in the python query string, refer to the python instance.

The following describes how to search for a specified string in python:

Code

# Query def selStr (): sStr1 = 'jsjtt. com 'sstr2 = 'com' # index to query a string, returns the index nPos = sStr1.index (sStr2) if (nPos> = 0 ): print 'sstr1 contains the character 'print nPos # find 'in sStr2. If the find method is not found,-1 nPos2 = sStr1.find ('abc') is returned ') print nPos2 # the position where the returned characters are located. print sStr1.find ('com ') selStr ();

Python delimiter

Def split (): sStr1 = 'AB, cde, fgh, ijk 'sstr2 =', '# Use find to find the index location where the comma is located sStr1 = sStr1 [sStr1.find (sStr2) + 1:] print sStr1 # Use the split function to split the string s = 'AB, cde, fgh, ijk' result = s. split (',') print (result [0]) split ();

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.