小甲鱼 发表于 2021-2-21 01:10:55

已有 25 人购买  本主题需向作者支付 5 鱼币 才能浏览 购买主题

小古比鱼 发表于 2021-4-27 17:31:30

列表、元组和字符串统称为序列。序列分为可变序列和不可变序列,列表是可变序列,元组和字符串是不可变序列。本节主要谈的是能够作用于序列的运算符和函数,包括拼接运算符(+)、重复运算符(*)、同一性运算符(is、is not)、包含性运算符(in、not in)和用于删除指定对象或元素的del语句。期间还提到了内置函数id(),用于获取指定对象的唯一标识值;增量赋值后,可变序列的id值不改变,不可变序列的id值会改变,看起来很神奇!

痴我一拳 发表于 2021-5-22 19:05:20

+

>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>> '123'+'456'
'123456'
>>> *3

>>> (1,2,3)*3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> '123'*3
'123123123'
>>> s =
>>> id(s)
2044801898496
>>> s * =2
SyntaxError: invalid syntax
>>> s *=2
>>> s

>>> id(s)
2044801898496
>>> t =(1,2,3)
>>> id(t)
2044805233216
>>> t *=2
>>> t
(1, 2, 3, 1, 2, 3)
>>> id(t)
2044804326688
>>> x = "FishC"
>>> y = "FishC"
>>> x is y
True
>>> x =
>>> y =
>>> x is y
False
>>> "鱼"in"鱼C"
True
>>> "Fish" in "FishC"
True
>>> "C" not in "FishC"
False
>>> x = "FishC"
>>> y =
>>> del x,y
>>> x
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
    x
NameError: name 'x' is not defined
>>> y
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
    y
NameError: name 'y' is not defined
>>> x =
>>> del x
>>> x

>>> y =
>>> y=[]
>>> y

>>> x =
>>> del x[::2]
>>> x

>>> y =
>>> y[::2]=[]
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
    y[::2]=[]
ValueError: attempt to assign sequence of size 0 to extended slice of size 3
>>> x =
>>> x.clear()
>>> x
[]
>>> x =
>>> del x[:]
>>> x
[]
>>>

wangtuan 发表于 2021-12-2 19:21:56

>>>

>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>> "123"+"456"
'123456'
>>> *3

>>> (1,2,3)*3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> "123"*3
'123123123'
>>> s =
>>> id(s)
2183926584064
>>> s *= 2
>>> s

>>> id(s)
2183926584064
>>> c = ["其实,在python中,每一个对象都有三个基本属性,第一个是唯一标志,第二个是类型,第三个是值。 这个唯一标志是随着对象创建时就有的,是不可以被修改的,也不会有重复的值,只要这个对象一天在内存中,他这个值就不会有重复的。因此,可卡因把唯一标志理解为,对象的一张身份证。而id() 这个函数就是返回某个对象的唯一标志的整数值"]
>>> t = (1,2,3)
>>> id(t)
2183930156864
>>> t *= 2
>>> t
(1, 2, 3, 1, 2, 3)
>>> id(t)
2183929489920
>>> d = ["如果对象本身是一个不可变的序列,即元组,那么其变化后,就会产生一个新的对象,因此其id也会变"]
>>> x = "Fishc"
>>> y = "Fishc"
>>> x is y
True
>>> x =
>>> y =
>>> x is y
False
>>> e = ["is和is not 可以用来判断两个对象的id是否一样"]
>>> f = ["in用于判断某个运算符是否包含在序列中,而 not in 则恰恰相反"]
>>> "鱼" in "鱼c"
True
>>> "C" not in "FishC"
False
>>> g = ["del 语句用于删除一个或多个指定的对象"]
>>> x = "FishC"
>>> Y =
>>> del x,y
>>> x
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
    x
NameError: name 'x' is not defined
>>> y
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
    y
NameError: name 'y' is not defined
>>> x =
>>> del x
>>> x

>>> y =
>>> y = []
>>> y

>>> x =
>>> del x[::2]
>>> x

>>> y =
>>> y[::2] = []
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
    y[::2] = []
ValueError: attempt to assign sequence of size 0 to extended slice of size 3
>>> x =
>>> x.clear()
>>> x
[]
>>> x =
>>> del x[:]
>>> x
[]
>>>

wangtuan 发表于 2021-12-2 19:22:52

>>>

>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>> "123"+"456"
'123456'
>>> *3

>>> (1,2,3)*3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> "123"*3
'123123123'
>>> s =
>>> id(s)
2183926584064
>>> s *= 2
>>> s

>>> id(s)
2183926584064
>>> c = ["其实,在python中,每一个对象都有三个基本属性,第一个是唯一标志,第二个是类型,第三个是值。 这个唯一标志是随着对象创建时就有的,是不可以被修改的,也不会有重复的值,只要这个对象一天在内存中,他这个值就不会有重复的。因此,可卡因把唯一标志理解为,对象的一张身份证。而id() 这个函数就是返回某个对象的唯一标志的整数值"]
>>> t = (1,2,3)
>>> id(t)
2183930156864
>>> t *= 2
>>> t
(1, 2, 3, 1, 2, 3)
>>> id(t)
2183929489920
>>> d = ["如果对象本身是一个不可变的序列,即元组,那么其变化后,就会产生一个新的对象,因此其id也会变"]
>>> x = "Fishc"
>>> y = "Fishc"
>>> x is y
True
>>> x =
>>> y =
>>> x is y
False
>>> e = ["is和is not 可以用来判断两个对象的id是否一样"]
>>> f = ["in用于判断某个运算符是否包含在序列中,而 not in 则恰恰相反"]
>>> "鱼" in "鱼c"
True
>>> "C" not in "FishC"
False
>>> g = ["del 语句用于删除一个或多个指定的对象"]
>>> x = "FishC"
>>> Y =
>>> del x,y
>>> x
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
    x
NameError: name 'x' is not defined
>>> y
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
    y
NameError: name 'y' is not defined
>>> x =
>>> del x
>>> x

>>> y =
>>> y = []
>>> y

>>> x =
>>> del x[::2]
>>> x

>>> y =
>>> y[::2] = []
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
    y[::2] = []
ValueError: attempt to assign sequence of size 0 to extended slice of size 3
>>> x =
>>> x.clear()
>>> x
[]
>>> x =
>>> del x[:]
>>> x
[]
>>>

Er3nYeager 发表于 2022-4-28 10:19:40

打卡

KinokoCC 发表于 2022-5-19 21:12:13

坚持学习

ctx111 发表于 2022-8-7 10:19:47

s=
id(s)
4469321280
s*=2
s

id(s)
4469321280
t=(1,2,3)
id(t)
4469493824
t*=3
t
(1, 2, 3, 1, 2, 3, 1, 2, 3)
id(t)
4467620464
a=
del a
a

a=a[]
SyntaxError: invalid syntax
a=[]
a

a=
a=[]
a

a=
a.append=['11']
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
    a.append=['11']
AttributeError: 'list' object attribute 'append' is read-only
a.append=('11')
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
    a.append=('11')
AttributeError: 'list' object attribute 'append' is read-only
a.append('11')
a

a=
a=['11']
a

a=
del a[::3]
a

a=
a[::3]=[]
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
    a[::3]=[]
ValueError: attempt to assign sequence of size 0 to extended slice of size 2
a=
a.clear()
a
[]
a=
del a[::]
a
[]
a=
del a[:]
a
[]

JZt2902019046 发表于 2022-8-14 19:30:21

打卡

元豪 发表于 2022-8-16 14:25:58

{:10_256:}

炎凉来寻 发表于 2022-9-2 11:34:25

{:10_257:}学习打卡

非同寻常 发表于 2022-9-23 11:14:49

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> oho =
>>> AA = len(oho)
>>> AA
5
>>> print(AA)
5
>>> for letter in 'Ptthon':
        print("当前字母: ")

       
当前字母:
当前字母:
当前字母:
当前字母:
当前字母:
当前字母:
>>> for letter in 'Python':
        print("当前字母: ")

       
当前字母:
当前字母:
当前字母:
当前字母:
当前字母:
当前字母:
>>> for letter in 'Python':
        print("当前字母: "letter)
       
SyntaxError: invalid syntax
>>> for letter in 'Python':
        print("当前字母: " letter)
       
SyntaxError: invalid syntax
>>> for letter in 'Python':
        print("当前字母: " % letter)

       
Traceback (most recent call last):
File "<pyshell#12>", line 2, in <module>
    print("当前字母: " % letter)
TypeError: not all arguments converted during string formatting
>>> for letter in 'Python':
        print("当前字母:" % letter)

       
Traceback (most recent call last):
File "<pyshell#14>", line 2, in <module>
    print("当前字母:" % letter)
TypeError: not all arguments converted during string formatting
>>> for letter in 'Python':
        print("当前字母:%s"% letter)

       
当前字母:P
当前字母:y
当前字母:t
当前字母:h
当前字母:o
当前字母:n
>>> for letter in 'Python':
        print("当前字母:%s"letter)
       
SyntaxError: invalid syntax
>>> oho =
>>> len(oho)
5
>>> pange.len(oho)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
    pange.len(oho)
NameError: name 'pange' is not defined
>>> range(len(oho))
range(0, 5)
>>> range.len(oho)
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
    range.len(oho)
AttributeError: type object 'range' has no attribute 'len'
>>> range(len(oho))
range(0, 5)
>>> for i in range(len(oho))
SyntaxError: invalid syntax
>>> for i in range(len(oho)):
        oho=oho*2

       
>>> oho

>>> for i in range(len(oho)):
        oho=oho*2

       
>>> oho

>>> oho =
>>> x = * 2)]
>>> x

>>> x =
>>> x

>>> x =
>>> x

>>> x = []
>>> for i in range(10):
        x.append(i+1)

       
>>> x

>>> y =
Traceback (most recent call last):
File "<pyshell#46>", line 1, in <module>
    y =
NameError: name 'FishC' is not defined
>>> y =
>>> y
['F', 'i', 's', 'h', 'C']
>>> y=y82
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
    y=y82
NameError: name 'y82' is not defined
>>> y=y*2
>>> y
['F', 'i', 's', 'h', 'C', 'F', 'i', 's', 'h', 'C']
>>> y =
>>> y =
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
    y =
File "<pyshell#53>", line 1, in <listcomp>
    y =
TypeError: can only concatenate str (not "int") to str
>>> y =
Traceback (most recent call last):
File "<pyshell#54>", line 1, in <module>
    y =
File "<pyshell#54>", line 1, in <listcomp>
    y =
NameError: name 'c2' is not defined
>>> y =
>>> y
['FF', 'ii', 'ss', 'hh', 'CC']
>>> y =
>>> y
['FFF', 'iii', 'sss', 'hhh', 'CCC']
>>> AAA = ord(F)
Traceback (most recent call last):
File "<pyshell#59>", line 1, in <module>
    AAA = ord(F)
NameError: name 'F' is not defined
>>> AAA = ord('F')
>>> aaa
Traceback (most recent call last):
File "<pyshell#61>", line 1, in <module>
    aaa
NameError: name 'aaa' is not defined
>>> AAA
70
>>> >>> matrix = [,
...         ,
...         ]
>>> col2 = for row in matrix]
>>> col2

SyntaxError: invalid syntax
>>> >>> matrix = [,
...         ,
...         ]
>>> col2 = for row in matrix]
>>> col2
>>> matrix = [,
...         ,
...         ]
>>> col2 = for row in matrix]
>>> col2

SyntaxError: invalid syntax
>>> >>> matrix = [,
...         ,
...         ]
>>> col2 = for row in matrix]
>>> col2

SyntaxError: invalid syntax
>>> >>> matrix = [,
...         ,
...         ]
>>> col2 = for row in matrix]
>>> col2
matrix = [,
...         ,
...         ]
SyntaxError: invalid syntax
>>> matrix = [,
...         ,
...         ]
Traceback (most recent call last):
File "<pyshell#67>", line 2, in <module>
    ...         ,
TypeError: 'ellipsis' object is not subscriptable
>>> matrix = [,
         ,
         ]
>>> row
Traceback (most recent call last):
File "<pyshell#69>", line 1, in <module>
    row
NameError: name 'row' is not defined
>>> row
Traceback (most recent call last):
File "<pyshell#70>", line 1, in <module>
    row
NameError: name 'row' is not defined
>>> row
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
    row
NameError: name 'row' is not defined
>>> col2 = for row in matrix]
>>> col2

>>> row
Traceback (most recent call last):
File "<pyshell#74>", line 1, in <module>
    row
NameError: name 'row' is not defined
>>> col2

>>> matrix = [,
         ,
         ]
>>> for row in matrix
SyntaxError: invalid syntax
>>> for row in matrix:
        row

       
2
5
8
>>> for row in matrix:
        row

       
3
6
9
>>> for row in matrix:
        row

       
Traceback (most recent call last):
File "<pyshell#84>", line 2, in <module>
    row
IndexError: list index out of range
>>> for row in matrix:
        row

       
3
6
9
>>> for row in matrix:
        row

       
1
4
7
>>> for row in matrix:
        row

       
Traceback (most recent call last):
File "<pyshell#90>", line 2, in <module>
    row
TypeError: 'int' object is not subscriptable
>>> matrix = [,
         ,
         ]
>>> matrix
Traceback (most recent call last):
File "<pyshell#92>", line 1, in <module>
    matrix
IndexError: list index out of range
>>> dd = matrix
Traceback (most recent call last):
File "<pyshell#93>", line 1, in <module>
    dd = matrix
IndexError: list index out of range
>>> len(matrix)
3
>>> range(len(matrix))
      
SyntaxError: invalid character in identifier
>>> range(len(matrix))
range(0, 3)
>>> matrix
[, , ]
>>> range(len(matrix))
range(0, 3)
>>> AAA = for q in range(0, 3)]
>>> aaa
Traceback (most recent call last):
File "<pyshell#100>", line 1, in <module>
    aaa
NameError: name 'aaa' is not defined
>>> AAA

>>> rhy = (1,2,3,4,5,"上山打老虎")
>>> rhy
(1, 2, 3, 4, 5, '上山打老虎')
>>> rhyme = (1,2,3,4,5,"上山打老虎")
>>> rhyme
(1, 2, 3, 4, 5, '上山打老虎')
>>> rhyme
(1, 2, 3, 4, 5, '上山打老虎')
>>> rhyme = 1,2,3,4,5,"上山打老虎"
>>> rhyme
(1, 2, 3, 4, 5, '上山打老虎')
>>> rhyme
'上山打老虎'
>>> rhyme[-1]
'上山打老虎'
>>>x = "12321"

SyntaxError: unexpected indent
>>> x = "12321"
>>> x
'12321'
>>> x='12321'
>>> x
'12321'
>>> x[::-]
SyntaxError: invalid syntax
>>> x[::-1]
'12321'
>>> x = "12321"
>>> x = "12345"
>>> x[::-1]
'54321'
>>> x = "12321"
>>> if x == x[::-1]:
        "是回文数"
    else
   
SyntaxError: unindent does not match any outer indentation level
>>> if x == x[::-1]:
        "是回文数"
    else:
   
SyntaxError: unindent does not match any outer indentation level
>>> if x == x[::-1]:
        "是回文数"
    else:
   
SyntaxError: unindent does not match any outer indentation level
>>> if x == x[::-1]:
        "是回文数"
    else "不是回文数"
   
SyntaxError: unindent does not match any outer indentation level
>>> "是回文数" if x == x[::-1] else "不是回文数"
'是回文数'
>>> x = "12345"
>>> "是回文数" if x == x[::-1] else "不是回文数"
'不是回文数'
>>> x = "上海自来水来自海上"
>>> x.count("海")
2
>>> x.count("海",0,2)
SyntaxError: invalid character in identifier
>>> x.count("海",0, 2)
SyntaxError: invalid character in identifier
>>> x.count("海",0,2)
1
>>> x.count("海",0,9)
2
>>> x.count("海",0)
2
>>> x.count("海", ,9)
SyntaxError: invalid syntax
>>> x.count("海", -1)
0
>>> x.find("海")
1
>>> x.rfind("海")
7
>>> "在吗?我在你家楼下,快点下来!!".replace("在吗","想你")
'想你?我在你家楼下,快点下来!!'
>>> 在吗?我在你家楼下,快点下来!!
SyntaxError: invalid character in identifier
>>> "在吗?我在你家楼下,快点下来!!"
'在吗?我在你家楼下,快点下来!!'
>>> "在吗?我在你家楼下,快点下来!!".replace("在吗","想你")
'想你?我在你家楼下,快点下来!!'
>>> x = "我爱Python"
>>> x.startwith("小甲鱼")
Traceback (most recent call last):
File "<pyshell#147>", line 1, in <module>
    x.startwith("小甲鱼")
AttributeError: 'str' object has no attribute 'startwith'
>>> x.startwith("我")
Traceback (most recent call last):
File "<pyshell#148>", line 1, in <module>
    x.startwith("我")
AttributeError: 'str' object has no attribute 'startwith'
>>> x.startswith("我")
True
>>> x.startswith("我")
True
>>> x.startswith("xiaojiayu")
False
>>> x.startswith("小甲鱼")
False
>>> x.endwicth("小甲鱼")
Traceback (most recent call last):
File "<pyshell#153>", line 1, in <module>
    x.endwicth("小甲鱼")
AttributeError: 'str' object has no attribute 'endwicth'
>>> x.endwith("小甲鱼")
Traceback (most recent call last):
File "<pyshell#154>", line 1, in <module>
    x.endwith("小甲鱼")
AttributeError: 'str' object has no attribute 'endwith'
>>> x.endswith("小甲鱼")
False
>>> x.endswith("Python")
True
>>> x.endswith("n")
True
>>> x.startswith("小甲鱼",)
False
>>> x.startswith("小甲鱼",1,8)
False
>>> x.startswith("爱",1,8)
True
>>> year = 2010
>>> "鱼C工作室成立于year年"
'鱼C工作室成立于year年'
>>> "鱼C工作室成立于{}年".format(year)
'鱼C工作室成立于2010年'
>>> "1+2={},2的平方是{},3的立方是{}".format(1+2,2+2,3*3*3)
'1+2=3,2的平方是4,3的立方是27'
>>> >>> "{1}看到{0}就很激动!".format("小甲鱼", "漂亮的小姐姐")
'漂亮的小姐姐看到小甲鱼就很激动!'
SyntaxError: invalid syntax
>>> "{1}看到{0}就很激动!".format("小甲鱼", "漂亮的小姐姐")
'漂亮的小姐姐看到小甲鱼就很激动!'
SyntaxError: multiple statements found while compiling a single statement
>>> "{1}看到{0}就很激动!".format("小甲鱼", "漂亮的小姐姐")

'漂亮的小姐姐看到小甲鱼就很激动!'
>>> "{1}看到{0}就很激动!".format("小甲鱼", "漂亮的小姐姐")
'漂亮的小姐姐看到小甲鱼就很激动!'
>>> >>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")

SyntaxError: invalid syntax
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
'我叫小甲鱼,我爱python。喜爱python的人,运气都不会太差^o^'
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
'我叫小甲鱼,我爱python。喜爱python的人,运气都不会太差^o^'
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
'我叫小甲鱼,我爱python。喜爱python的人,运气都不会太差^o^,我叫小甲鱼,我爱python。喜爱python的人,运气都不会太差^o^'
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#173>", line 1, in <module>
    "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#174>", line 1, in <module>
    "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#175>", line 1, in <module>
    "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我叫{1},我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> "我叫{name},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
'我叫小甲鱼,我爱python。喜爱python的人,运气都不会太差^o^,我爱python。喜爱python的人,运气都不会太差^o^'
>>> "我叫{name},我爱{0},我爱{1}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#177>", line 1, in <module>
    "我叫{name},我爱{0},我爱{1}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> "我叫{name},我爱{0},我爱{0}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
'我叫小甲鱼,我爱python,我爱python。喜爱python的人,运气都不会太差^o^,我爱python。喜爱python的人,运气都不会太差^o^'
>>> "我叫{name},我爱{0},我爱{1}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#179>", line 1, in <module>
    "我叫{name},我爱{0},我爱{1}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> "我叫{name},我爱{},我爱{}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
Traceback (most recent call last):
File "<pyshell#180>", line 1, in <module>
    "我叫{name},我爱{},我爱{}。喜爱{0}的人,运气都不会太差^o^,我爱{0}。喜爱{0}的人,运气都不会太差^o^".format("python", name="小甲鱼")
IndexError: Replacement index 1 out of range for positional args tuple
>>> >>> "{}, {}, {}".format(1, "{}", 2)
'1, {}, 2'
>>> "{}, {{}}, {}".format(1, 2)
'1, {}, 2'
SyntaxError: invalid syntax
>>> "{}, {}, {}".format(1, "{}", 2)
'1, {}, 2'
>>> "{}, {{}}, {}".format(1, 2)
'1, {}, 2'
>>> format_spec   ::=[align][#][.precision]
fill            ::=<any character>
align         ::="<" | ">" | "=" | "^"
sign            ::="+" | "-" | " "
width         ::=digit+
grouping_option ::="_" | ","
precision       ::=digit+
type            ::="b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
SyntaxError: invalid syntax
>>> format_spec   ::=[align][#][.precision]
       
SyntaxError: invalid syntax
>>> "{:^}".format(250)
'250'
>>>"{:^10}".format(250)

SyntaxError: unexpected indent
>>> "{:^10}".format(250)
'   250    '
>>> "{1:>10}{0:<10}".format(520, 250)
'       250520       '
>>> "{1:<10}{0:>10}".format(520, 250)
'250            520'
>>> "{:=} {:-}".format(520,-250)
'520 -250'
>>> "{:=} {:}".format(520,-250)
'520 -250'
>>> "{:=} {:=}".format(520,-250)
'520 -250'
>>> "{:+} {:}".format(520,-250)
'+520 -250'
>>> "{:+} {:}".format(5210,-1250)
'+5210 -1250'
>>> "{:,} {:}".format(5210,-1250)
'5,210 -1250'
>>> "{:,} {:,}".format(5210,-1250)
'5,210 -1,250'
>>> "{:_} {:,}".format(5210,-1250)
'5_210 -1,250'
>>> "{:_} {:_}".format(5210,-1250)
'5_210 -1_250'
>>> +

>>> (1, 2, 3) + (4, 5, 6)
(1, 2, 3, 4, 5, 6)
>>> "123" + "456"
'123456'
>>> * 3

>>> (1, 2, 3) * 3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>>"123" * 3

SyntaxError: unexpected indent
>>>123" * 3SyntaxError: unexpected indent"123" * 3

SyntaxError: unexpected indent
>>> "123" * 3
'123123123'
>>> s =
>>> s

>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> s *= 2
>>> s

>>> id(s)
3205915134272
>>> a = 'runoob'
>>> id(a)
3205915141744
>>> b = 1
>>> b = 1
>>> id(b)
140710244828832
>>> t = (1, 2, 3)
>>> id(t)
3205915157632
>>> t *= 2
>>> t
(1, 2, 3, 1, 2, 3)
>>> id(t)
3205915277152
>>> t *= 2
>>> id(t)
3205915299408
>>> x = "FishC"
>>> y = "FishC"
>>> x is y
True
>>> x =
>>> y =
>>> x is not y
True
>>> "Fish" in "FishC"
True
>>> True
True
>>> "鱼" in "鱼C"
True
>>>"C" not in "FishC"

SyntaxError: unexpected indent
>>>"C" not in "FishC"

SyntaxError: unexpected indent
>>> "C" not in "FishC"
False
>>> False
False
>>> x = "FishC"
>>> y =
>>> del x, y
>>> x
Traceback (most recent call last):
File "<pyshell#247>", line 1, in <module>
    x
NameError: name 'x' is not defined
>>> y
Traceback (most recent call last):
File "<pyshell#248>", line 1, in <module>
    y
NameError: name 'y' is not defined
>>> +

>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>>

chenjinchao 发表于 2022-9-25 16:43:21

知识点太多了,要是可以知识点与知识点之间,间隔再插入一些运用知识点的游戏或者其他什么的,就好了

migu_sm1 发表于 2022-11-4 11:31:11

Learning...

jgz1818 发表于 2022-11-23 20:26:36

del y[::]可以的吗?

dearfish 发表于 2022-11-29 03:00:17

请教,如下:r、s字符串的id值为何一样,x、y列表的id值为何不一样,m、n元组的id值为何不一样?谢谢
>>>r="love"
>>>id(r)
1606768261424
>>>s="love"
>>>id(s)
1606768261424
>>>r *= 2
>>>r
'lovelove'
>>>id(r)
1606760559920
                                          
>>>x =
>>>y =
>>>x is not y
True
>>>id(x)
1606768127168
>>>id(y)
1606768096192
>>>x *= 2
>>>x

>>>id(x)
1606768127168
                                          
>>>m = (1, 2, 3)
>>>id(m)
1606768198976
>>>n = (1, 2, 3)
>>>id(n)
1606768251200
>>>m*=2
>>>m
(1, 2, 3, 1, 2, 3)
>>>id(m)
1606761443488

xxxx.xxxx 发表于 2022-12-3 16:01:22

学习,多练习,有时候会被小问题搞半天

andyleesh 发表于 2022-12-27 15:08:41

打卡坚持学习

xiaoxiangx 发表于 2023-1-11 19:59:52

打卡

weiliao 发表于 2023-1-29 14:30:08

做啥呢
页: [1] 2
查看完整版本: 第033讲:序列(上)