例如,如果我有一个名为add like的函数
def add(x,y):
return x+y
Run Code Online (Sandbox Code Playgroud)
我希望能够将字符串或输入转换为直接转换为该函数
w=raw_input('Please input the function you want to use')
Run Code Online (Sandbox Code Playgroud)
要么
w='add'
Run Code Online (Sandbox Code Playgroud)
有没有办法用w来引用函数add?
我在表单中有一个字符串,$string = 'London,Paris,Birmingham'我想搜索多个列以查找这些值的出现.
例如 WHERE events.name, events.cities, events.counties IN (".($string).")
有人可以推荐我一个简单而简短的方法来做这样的事情.
switch(type)
{
case 'home':
console.log('home switch');
break;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码没有写入控制台,以下内容也没有:
switch(type)
{
case "home":
console.log('home switch');
break;
}
Run Code Online (Sandbox Code Playgroud)
但是,以下内容:
if (type == 'home')
{
console.log('home if');
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么.这不是一个显示阻止,我可以使用该if声明,但我真的很好奇为什么会这样.
注意:这些声明是直接替换,此处无需考虑.范围没有变化,没有代码我没有提到可能会干扰价值type.
javascript if-statement switch-statement conditional-statements string-evaluation