Python returns fake (true or false) tips _python

Source: Internet
Author: User
Tags in python

In yesterday's blog about substring has the following code:

Perhaps you've found that in Python 3 there is a way to complete a function in just one line:

Copy Code code as follows:

>>> def isSubstring2 (S1,S2):
Return True if S2.find (S1)!=-1 else False

But... Could it be simpler?

How do you use Python to express conditional statements more simply, just for fun:)

One approach is to use a list index:

Copy Code code as follows:

>>> def isSubstring2 (S1,S2):
return [False,true][s2.find (S1)!=-1]

The principle is simple, the Boolean value TRUE is evaluated as 1, and false equals 0. Could it be simpler? Leave a message for 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.