Python tips-True or false

Source: Internet
Author: User

The following code was found in yesterday's blog about substring:

You may have discovered that in Python 3, there is actually a way to complete the function with only one row:

>>> Def issubstring2 (S1, S2 ):
Return true if s2.find (S1 )! =-1 else false

But... Can it be simpler?

How can we use python to express conditional statements more easily? Just for fun

One way is to use the List Index:

>>> Def issubstring2 (S1, S2 ):
Return [false, true] [s2.find (S1 )! =-1]

The principle is very simple. If the Boolean value true is evaluated as 1 by the index, and false is equal to 0, can it be simpler? Leave a message to me

Related Article

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.