del如下。pop弹出元素并返回。
代码语言:javascript复制print(x)
[1, 2, 5, 6, 8, 4, 3, 5]
del x[3]
print(x)
[1, 2, 5, 8, 4, 3, 5]
y=x.pop()
print(y)
5
x
print(x)
[1, 2, 5, 8, 4, 3]
代码语言:javascript复制print(x)
[1, 2, 5, 8, 4, 3]
x
z=x.pop(3)
print(x)
[1, 2, 5, 4, 3]
z
print(z)
8
代码语言:javascript复制x1=(1,2,"aaaa")
x2=(3,4,"bbbb")
x1,x2
print(x1,x2)
(1, 2, 'aaaa') (3, 4, 'bbbb')
x1
(1, 2, 'aaaa')
x2
x2
(3, 4, 'bbbb')
print(x1[0],x1[1])
1 2
print(x2[2],x1[1])
bbbb 2
```python
str='1234n5aaaaa'
print(str)
str="123n45'aaaa'a"
print(str)
代码语言:javascript复制1234
5aaaaa
123
45'aaaa'a
代码语言:javascript复制str="""
adfdf
{asdf}
//2qerffasda
"""
print(str)
str='''adfdf
{asdf}
//2qerffasda'''
print(str)
代码语言:javascript复制adfdf
{asdf}
//2qerffasda
adfdf
{asdf}
//2qerffasda
代码语言:javascript复制str="""123n45'aaaa'a"""
print(str)
str='''123n45'aaaa'a'''
print(str)
str='''
123n45'aaaa'a
'''
print(str)
代码语言:javascript复制123
45'aaaa'a
123
45'aaaa'a
123
45'aaaa'a
代码语言:javascript复制str='''
123n
45'aaaa'a
'''
print(str)
代码语言:javascript复制123
45'aaaa'a
可见三引号中转义字符还是有作用,但使用r则可以消除转义字符的作用
代码语言:javascript复制str='''
123n
45'aaaa'a
aa\
bb
'''
print(str)
str=r'''
123n
45'aaaa'a
aa\
bb
'''
print(str)
代码语言:javascript复制123
45'aaaa'a
aa
bb
123n
45'aaaa'a
aa\
bb
代码语言:javascript复制s="ssadf"
print(s)
del s
print(s)
代码语言:javascript复制ssadf
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3dfd4f621ec7> in <module>
2 print(s)
3 del s
----> 4 print(s)
NameError: name 's' is not defined
print(x) x3=tuple(x) print(x3) [1, 2, 5, 4, 3, 10, 20, [1, 2]] (1, 2, 5, 4, 3, 10, 20, [1, 2])
print(x3[5],x3[6]) 10 20
1 print(x[7][0]) print(x[7][1]) 1 2
代码语言:javascript复制