我想要反转一个列表,我设法这样做,但在工作的中间我发现了一些奇怪的东西.以下程序按预期工作,但是不可见的行list_reversed [i] = list [len(list)-1-i]和print(list [i])(当然评论最后一行)导致列表中的更改.我没看到什么?我的Python版本是3.3.3.先感谢您.
list=[1,2,3,4,5,6]
list_reversed=list
for i in range(0,len(list)):
#list_reversed[i]=list[len(list)-1-i]
#print(list[i])
print(list[len(list)-1-i])
Run Code Online (Sandbox Code Playgroud) 目前,我有两个文件,index.htm和accessdata.php。这是我在index.htm中拥有的:
<html>
<head>
<script>
function postData() {
var xmlhttp=new XMLHttpRequest();
var url = "accessdata.php";
var checkBoxes_formData = new FormData(document.getElementById("checkBoxes"));
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(checkBoxes_formData);
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
}
</script>
</head>
<body>
<button type="button" onclick="postData()">POST</button>
<form id=checkBoxes>
<table>
<tr><input type="checkbox" name="opt1" value="blue" checked> Blue</td>
<tr><input type="checkbox" name="opt2" value="yellow"> Yellow</td>
</table>
</form>
<p id="result"></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这就是我在accessdata.php中拥有的内容:
<?php
$opt1=$_POST['opt1'];
echo $opt1;
echo "bla";
?>
Run Code Online (Sandbox Code Playgroud)
从今起
<p id="result"></p>
Run Code Online (Sandbox Code Playgroud)
显示“ bla”,但不显示“ blue”或“ yellow”。
我究竟做错了什么?
正确的HTML代码如下!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"> …Run Code Online (Sandbox Code Playgroud)