Answers for "set python variable if not none"

5

pythonhow to check if value is None

# How to check if a variable is None

var = None
# variable is None in this example

if var is None:
  # if var is None
  
  print("var is None")
  # code...
  
else:
  # if var is not None
  
  print("var is not None")
  # code...

# result of above example "var is None"



var = "sometext"
# variable is not None in this example

if var is None:
  # if var is None
  
  print("var is None")
  # code...
  
else:
  # if var is not None
  
  print("var is not None")
  # code...

# result of above example "var is not None"
Posted by: Guest on November-03-2020
0

python: if null give a value if not null concatenate

def concat_fields(field1, field2):
    if field1.strip() == "" or field2.strip() == "":
        return ""
    else:
        return field1 + field2
Posted by: Guest on July-01-2020

Code answers related to "set python variable if not none"

Python Answers by Framework

Browse Popular Code Answers by Language