Python if not in Multi-condition judgment code, pythonif

Source: Internet
Author: User

Python if not in Multi-condition judgment code, pythonif

Baidu homework help:

Python if not in Multi-condition judgment
S = ['1', '2'] Judgment Condition
Sta = "12345"
Normally,
If "1" not in sta and "2" not in sta:
Print sta

If we know that the conditions are okay, if there are many conditions, this method will certainly not work?
How can we use a formula to satisfy the above judgment?

Below is a pseudo code to familiarize you with it...
The requirement is that keywords such as "recruitment", "recruitment", and "social recruitment" are not allowed in the content. Only qualified keywords are printed ..

#! /Usr/bin/env python #-*-coding: gbk-*-#-*-coding: utf_8-*-# Date: # Created by dedicated wait # blog http://www.waitalone.cn/filters = ['recruitment ', 'hiring', 'social recruitment '] contents = ['dedicated waiting for security team hiring, http://www.bkjia.com /', 'Wait for security team recruitment, http://www.bkjia.com/', 'Wait for security team recruitment, http://www.bkjia.com/', 'Wait for information security blog, http://www.bkjia.com/', wait for content in contents: if any (keyword in content for keyword in filters): continue print content

Follow-up:
What does if all mean?
Answer:
All function test whether all conditions in the iteration object are true
All ([True, False, True]) returns False
Is there at least one condition for any testing?
Any ([True, False, False]) returns True

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.