我想在for循环中创建一个var,例如
for(int i; i<=10;i++)
{
string s+i = "abc";
}
Run Code Online (Sandbox Code Playgroud)
这应该创建变量s0,s1,s2 ...到s10.
我最近发现了如何通过这个方法在python中动态创建变量:
vars()['my_variable'] = 'Some Value'
Run Code Online (Sandbox Code Playgroud)
从而创建变量my_variable.
我的问题是,这是一个好主意吗?或者我应该提前声明变量吗?
说我有一个字符串 -
my_str = "From {country} with Love"
变量country目前不可用,稍后将设置为
country = "Russia".
现在我可以用动态解析的内联变量值打印字符串吗?就像是 -
print(f"{my_str}")
这将输出
From Russia with Love
我尝试使用 eval() 但没有帮助。
在此 php 代码中,在while循环期间,我希望使用稍后的 3 个变量$menu_1,称为$menu_2、 和$menu_3。这在 PHP 中可能吗?
while($parent_row = mysql_fetch_array($parent_result)){
$menu_ = "";
$menu_ . $i = "\n\t$('#menu_" . $i . "').hover(function () {";
}
echo $menu_1;
echo $menu_2;
echo $menu_3;
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚 eval() 在 AngularJS 中是如何工作的,但我似乎无法理解它。
我有以下内容:
$scope.salaryRate, $scope.priceRate = {
number: undefined,
type: undefined,
from: undefined,
to: undefined,
rate: undefined
}
$scope.addRate = function (variable) {
eval('$scope.' + variable).push({
'number': eval('$scope.' + variable + 'Rate').number,
'type': eval('$scope.' + variable + 'Rate').type,
'days': {
'days': eval('$scope.' + variable + 'SelectedDay'),
'daynames': displayDayNames($scope.dayNames, eval('$scope.' + variable + 'SelectedDay'))},
'from': eval('$scope.' + variable + 'Rate').from,
'to': eval('$scope.' + variable + 'Rate').to,
'rate': eval('$scope.' + variable + 'Rate').rate,
'id': eval(variable + 'Number')
});
eval('$scope.' …Run Code Online (Sandbox Code Playgroud) python ×2
angularjs ×1
c# ×1
eval ×1
f-string ×1
javascript ×1
php ×1
python-3.5 ×1
string ×1
variables ×1