我是Python新手。我发现自己做了很多这样的事情:
listItemService.get(position).getScheduleOn().startwith(DateofTodayorTomorrow)
Calendar c=Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
String dateOfToday=c.get(Calendar.YEAR)+"-"+(c.get(Calendar.MONTH)+1)+"-"+c.get(Calendar.DAY_OF_MONTH);
c.add(Calendar.DAY_OF_MONTH, 1);
String dateOfTomorrow=c.get(Calendar.YEAR)+"-"+(c.get(Calendar.MONTH)+1)+"-"+c.get(Calendar.DAY_OF_MONTH);
我使用它作为在PHP中检查$ _GET变量的等价物:
if 'input_url' in inputparams and inputparams['input_url']:
# do something with inputparams['input_url']
if 'output_url' in inputparams and inputparams['output_url']:
# do something with inputparams['output_url']
在Python中有更好的方法吗?
答案 0 :(得分:2)
dict.get(key)
会返回None
。因此,如果inputparams
是dict
,那么
if 'input_url' in inputparams and inputparams['input_url']:
可以简化为:
if inputparams.get('input_url'):