我用c ++编写了一个程序,它应该采用几个命令行参数,第一个是整数,其余三个是浮点数.处理它的代码部分看起来像这样:
_tmain(__in int argc, __in PZPWSTR argv)
{
USHORT X, Y, Z, ZR, XR; // Position of several axes
JOYSTICK_POSITION iReport; // The structure that holds the full position data
BYTE id=1; // ID of the target vjoy device (Default is 1)
UINT iInterface=1; // Default target vJoy device
BOOL ContinuousPOV=FALSE; // Continuous POV hat (or 4-direction POV Hat)
int count=0;
DOUBLE Xr, Yr, Zr;
// Get the ID of the target vJoy device
if (argc>1 && wcslen(argv[1]))
sscanf_s((char …Run Code Online (Sandbox Code Playgroud) 所以,在我的代码中,我有一个字典,我用来计算我以前没有知道的项目:
if a_thing not in my_dict:
my_dict[a_thing] = 0
else:
my_dict[a_thing] += 1
Run Code Online (Sandbox Code Playgroud)
显然,我不能增加一个尚不存在的值的条目.出于某种原因,我有一种感觉(在我仍然缺乏Python经验的大脑中)可能存在更多的Pythonic方法,例如,一些构造允许将表达式的结果分配给某个东西,如果不可能的话否则在一个声明中.
那么,Python中是否存在类似的内容?