samedi 6 février 2016

How to handle if statement along with and operator in python?

if instanceType == instance_type and operatingSystem == operating_system and tenancy == tenancy_db:
    sku_list.append(key)

In this if statement these variables, instanceType, operatingSystem and tenancy, are user input, how to handle not to check if any user input is None.

e.g. if instanceType is None, i would like to check

if operatingSystem == operating_system and tenancy == tenancy_db:
    sku_list.append(key)

e.g. if operatingSystem is None, i would like to check

if instanceType == instance_type and tenancy == tenancy_db:
    sku_list.append(key)

e.g. if both tenancy and instanceType is None, I would like to check:

if operatingSystem == operating_system:
    sku_list.append(key)

Simliarly, it depends on whether user input in None or something else, is there any other way to do this, or i have to implement nested if else?

Aucun commentaire:

Enregistrer un commentaire