Optional parameters are passed as a # character so that place counting is preserved.
So you could test for the value being == '#' to see if it was not set.
That's what I thought and what I remember from ArcGIS 9x, but it seems to be empty strings now not '#'. Actually, I just tested this and it's an empy string '' when using GetParameterAsText(n) and '#' when using sys.argvFor a script tool with 3 parameters, 2 optional (and not entered when I ran it).import sys,arcpy
for i,arg in enumerate(sys.argv[1:]):
arcpy.AddMessage("argv %s=%s"%(i,repr(arg)))
arcpy.AddMessage("param %s=%s"%(i,repr(arcpy.GetParameterAsText(i))))
Executing: Script Layer1 # #
Start Time: Mon May 14 12:33:51 2012
Running script Script...
argv 0='Layer1'
param 0=u'Layer1'
argv 1='#'
param 1=''
argv 2='#'
param 2=''
Completed script Script...
Succeeded at Mon May 14 12:33:52 2012 (Elapsed Time: 1.00 seconds)