我是Python的新手,试图理解可变对象和不可变对象之间的区别。Python中的可变类型之一是列表。假设L = [1,2,3],则L具有指向对象[1,2,3]的ID。如果[1,2,3]的内容被修改,则L仍保留相同的id。换句话说,即使对象的大小和内容已更改,L仍与同一对象关联。
对于不可变的对象,我的理解是不允许修改对象。因此,如果使用新值重新分配了变量,则该变量将绑定到具有不同ID的新对象。我希望字符串的行为类似。但是我尝试修改一个字符串,但是字符串id并没有改变。
string = "blue"
for i in range(10):
string = string + str(i)
print("string id after {}th iteration: {}".format(i,id(string)))
string id after 0th iteration: 46958272
string id after 1th iteration: 46958272
string id after 2th iteration: 46958272
string id after 3th iteration: 47077400
string id after 4th iteration: 47077400
string id after 5th iteration: 47077400
string id after 6th iteration: 47077400
string id after 7th iteration: 47077400
string id after 8th iteration: 47077400
string id after 9th …Run Code Online (Sandbox Code Playgroud) 我有一些关于 css 选择器的问题。请帮忙。在下面的代码中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
selector {
color: blue;
}
</style>
</head>
<body>
<section>
<p id="apple">apple
<div class="orange">orange</div>
</p>
<p class="mango"> mango
<div>banana</div>
</p>
</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果选择器是部分,则所有部分的子项都会继承颜色属性。为什么当选择器是p时不是这样呢?
选择器=节p,目标节内的所有p元素。为什么当selector = p div 时不起作用?
Selector = section #apple,按预期定位 id="apple" 的 p 元素。
但 Selector = section #apple .orange 不起作用。先感谢您!
如何利用用户与 html 元素的交互来删除伪元素?我有一个带有伪元素的元素,其宽度为 50% 并且绝对定位。我想在用户与其父元素交互后永久删除伪元素。
.test {
position: relative;
background: blue;
}
.test::before {
content: "some text";
background: red;
width: 50%;
position: absolute;
}Run Code Online (Sandbox Code Playgroud)
<div class="test">Lorem ipsum dolor sit.</div>Run Code Online (Sandbox Code Playgroud)
在父级上使用 :hover、:active 和 :focus 不起作用。谢谢。