Python - Pass a range of float (without step) as an argument of a function -


i created function , able call set of keyworded-parameters call **criterias:

def actionbasedonparameters(**criterias):     # code 

inside set of parameters 1 of them called 'suminc' , pass range it. range of form of [1:15] or [1:] or [:15]. let me check whether variable in code greater boundary or lower boundary or both. in same way, these lines of codes do:

in [188]: 1 <= 15.98877 <= 15 out[188]: false  in [188]: 1 <= 15.98877  out[188]: true  in [188]: 15.98877 <= 15 out[188]: false 

but looking neater way pass both boundaries without having create parameter each , many if conditions things done.

something this:

in [189]: criterias = dict(suminc=[:15])  def actionbasedonparameters(**criterias):     if criterias['suminc'] not none:         if my_variable in criterias['suminc']:             #action1         else:             #action2 

is there of kind existing?

thanks tips,

something this?

criterias = dict(suminc=(1,15))  def actionbasedonparameters(**criterias):     if 'suminc' in criterias:         lower, upper = criterias['suminc']         if lower <= my_variable <= upper:             #action1         else:             #action2  infinity = float('inf') actionbasedonparameters(suminc=(1, 15)) actionbasedonparameters(suminc=(-infinity, 15)) actionbasedonparameters(suminc=(1, infinity)) 

also, you'd better use 'suminc' in criterias instead of criterias['suminc'] not none because in case if there no 'suminc' raise keyerror exception.


Comments