溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python3-列表與字符串

發(fā)布時(shí)間:2020-04-04 11:42:14 來源:網(wǎng)絡(luò) 閱讀:200 作者:myhaspl 欄目:編程語言

del如下。pop彈出元素并返回。

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]
print(x)
[1, 2, 5, 8, 4, 3]

x
z=x.pop(3)
print(x)
[1, 2, 5, 4, 3]

z
print(z)
8
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='1234\n5aaaaa'
print(str)
str="123\n45'aaaa'a"
print(str)

1234
5aaaaa
123
45'aaaa'a
str="""
adfdf
{asdf}
//2qerffasda
"""
print(str)
str='''adfdf
{asdf}
//2qerffasda'''
print(str)
adfdf
{asdf}
//2qerffasda

adfdf
{asdf}
//2qerffasda
str="""123\n45'aaaa'a"""
print(str)
str='''123\n45'aaaa'a'''
print(str)
str='''
123\n45'aaaa'a
'''
print(str)
123
45'aaaa'a
123
45'aaaa'a

123
45'aaaa'a
str='''
123\n
45'aaaa'a
'''
print(str)
123

45'aaaa'a

可見三引號(hào)中轉(zhuǎn)義字符還是有作用,但使用r則可以消除轉(zhuǎn)義字符的作用

str='''
123\n
45'aaaa'a
aa\\
bb
'''
print(str)
str=r'''
123\n
45'aaaa'a
aa\\
bb
'''
print(str)
123

45'aaaa'a
aa\
bb

123\n
45'aaaa'a
aa\\
bb
s="ssadf"
print(s)
del s
print(s)
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

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI