鱼C论坛

 找回密码
 立即注册
查看: 8548|回复: 28

[知识点备忘] 第033讲:序列(上)

[复制链接]
发表于 2021-2-21 01:10:55 | 显示全部楼层 |阅读模式
购买主题 已有 25 人购买  本主题需向作者支付 5 鱼币 才能浏览
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-27 17:31:30 | 显示全部楼层
列表、元组和字符串统称为序列。序列分为可变序列和不可变序列,列表是可变序列,元组和字符串是不可变序列。本节主要谈的是能够作用于序列的运算符和函数,包括拼接运算符(+)、重复运算符(*)、同一性运算符(is、is not)、包含性运算符(in、not in)和用于删除指定对象或元素的del语句。期间还提到了内置函数id(),用于获取指定对象的唯一标识值;增量赋值后,可变序列的id值不改变,不可变序列的id值会改变,看起来很神奇!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-5-22 19:05:20 | 显示全部楼层
[1,2,3]+[4,5,6]
[1, 2, 3, 4, 5, 6]
>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>> '123'+'456'
'123456'
>>> [1,2,3]*3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> (1,2,3)*3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> '123'*3
'123123123'
>>> s = [1,2,3]
>>> id(s)
2044801898496
>>> s * =2
SyntaxError: invalid syntax
>>> s *=2
>>> s
[1, 2, 3, 1, 2, 3]
>>> 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 =[1,2,3]
>>> y =[1,2,3]
>>> x is y
False
>>> "鱼"in"鱼C"
True
>>> "Fish" in "FishC"
True
>>> "C" not in "FishC"
False
>>> x = "FishC"
>>> y = [1,2,3]
>>> 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 = [1,2,3,4,5]
>>> del x[1:4]
>>> x
[1, 5]
>>> y = [1,2,3,4,5]
>>> y[1:4]=[]
>>> y
[1, 5]
>>> x = [1,2,3,4,5]
>>> del x[::2]
>>> x
[2, 4]
>>> y = [1,2,3,4,5]
>>> 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 = [1,2,3,4,5]
>>> x.clear()
>>> x
[]
>>> x = [1,2,3,4,5]
>>> del x[:]
>>> x
[]
>>>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-2 19:21:56 | 显示全部楼层
  1. >>> [1,2,3,4,5,6]
  2. [1, 2, 3, 4, 5, 6]
  3. >>> (1,2,3)+(4,5,6)
  4. (1, 2, 3, 4, 5, 6)
  5. >>> "123"+"456"
  6. '123456'
  7. >>> [1,2,3]*3
  8. [1, 2, 3, 1, 2, 3, 1, 2, 3]
  9. >>> (1,2,3)*3
  10. (1, 2, 3, 1, 2, 3, 1, 2, 3)
  11. >>> "123"*3
  12. '123123123'
  13. >>> s = [1,2,3]
  14. >>> id(s)
  15. 2183926584064
  16. >>> s *= 2
  17. >>> s
  18. [1, 2, 3, 1, 2, 3]
  19. >>> id(s)
  20. 2183926584064
  21. >>> c = ["其实,在python中,每一个对象都有三个基本属性,第一个是唯一标志,第二个是类型,第三个是值。 这个唯一标志是随着对象创建时就有的,是不可以被修改的,也不会有重复的值,只要这个对象一天在内存中,他这个值就不会有重复的。因此,可卡因把唯一标志理解为,对象的一张身份证。而id() 这个函数就是返回某个对象的唯一标志的整数值"]
  22. >>> t = (1,2,3)
  23. >>> id(t)
  24. 2183930156864
  25. >>> t *= 2
  26. >>> t
  27. (1, 2, 3, 1, 2, 3)
  28. >>> id(t)
  29. 2183929489920
  30. >>> d = ["如果对象本身是一个不可变的序列,即元组,那么其变化后,就会产生一个新的对象,因此其id也会变"]
  31. >>> x = "Fishc"
  32. >>> y = "Fishc"
  33. >>> x is y
  34. True
  35. >>> x = [1,2,3]
  36. >>> y = [1,2,3]
  37. >>> x is y
  38. False
  39. >>> e = ["is  和  is not 可以用来判断两个对象的id是否一样"]
  40. >>> f = ["in  用于判断某个运算符是否包含在序列中,而 not in 则恰恰相反"]
  41. >>> "鱼" in "鱼c"
  42. True
  43. >>> "C" not in "FishC"
  44. False
  45. >>> g = ["del 语句用于删除一个或多个指定的对象"]
  46. >>> x = "FishC"
  47. >>> Y = [1,2,3]
  48. >>> del x,y
  49. >>> x
  50. Traceback (most recent call last):
  51.   File "<pyshell#32>", line 1, in <module>
  52.     x
  53. NameError: name 'x' is not defined
  54. >>> y
  55. Traceback (most recent call last):
  56.   File "<pyshell#33>", line 1, in <module>
  57.     y
  58. NameError: name 'y' is not defined
  59. >>> x = [1,2,3,4,5]
  60. >>> del x[1:4]
  61. >>> x
  62. [1, 5]
  63. >>> y = [1,2,3,4,5]
  64. >>> y[1:4] = []
  65. >>> y
  66. [1, 5]
  67. >>> x = [1,2,3,4,5]
  68. >>> del x[::2]
  69. >>> x
  70. [2, 4]
  71. >>> y = [1,2,3,4,5]
  72. >>> y[::2] = []
  73. Traceback (most recent call last):
  74.   File "<pyshell#44>", line 1, in <module>
  75.     y[::2] = []
  76. ValueError: attempt to assign sequence of size 0 to extended slice of size 3
  77. >>> x = [1,2,3,4,5]
  78. >>> x.clear()
  79. >>> x
  80. []
  81. >>> x = [1,2,3,4,5]
  82. >>> del x[:]
  83. >>> x
  84. []
  85. >>>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-2 19:22:52 | 显示全部楼层
  1. >>> [1,2,3,4,5,6]
  2. [1, 2, 3, 4, 5, 6]
  3. >>> (1,2,3)+(4,5,6)
  4. (1, 2, 3, 4, 5, 6)
  5. >>> "123"+"456"
  6. '123456'
  7. >>> [1,2,3]*3
  8. [1, 2, 3, 1, 2, 3, 1, 2, 3]
  9. >>> (1,2,3)*3
  10. (1, 2, 3, 1, 2, 3, 1, 2, 3)
  11. >>> "123"*3
  12. '123123123'
  13. >>> s = [1,2,3]
  14. >>> id(s)
  15. 2183926584064
  16. >>> s *= 2
  17. >>> s
  18. [1, 2, 3, 1, 2, 3]
  19. >>> id(s)
  20. 2183926584064
  21. >>> c = ["其实,在python中,每一个对象都有三个基本属性,第一个是唯一标志,第二个是类型,第三个是值。 这个唯一标志是随着对象创建时就有的,是不可以被修改的,也不会有重复的值,只要这个对象一天在内存中,他这个值就不会有重复的。因此,可卡因把唯一标志理解为,对象的一张身份证。而id() 这个函数就是返回某个对象的唯一标志的整数值"]
  22. >>> t = (1,2,3)
  23. >>> id(t)
  24. 2183930156864
  25. >>> t *= 2
  26. >>> t
  27. (1, 2, 3, 1, 2, 3)
  28. >>> id(t)
  29. 2183929489920
  30. >>> d = ["如果对象本身是一个不可变的序列,即元组,那么其变化后,就会产生一个新的对象,因此其id也会变"]
  31. >>> x = "Fishc"
  32. >>> y = "Fishc"
  33. >>> x is y
  34. True
  35. >>> x = [1,2,3]
  36. >>> y = [1,2,3]
  37. >>> x is y
  38. False
  39. >>> e = ["is  和  is not 可以用来判断两个对象的id是否一样"]
  40. >>> f = ["in  用于判断某个运算符是否包含在序列中,而 not in 则恰恰相反"]
  41. >>> "鱼" in "鱼c"
  42. True
  43. >>> "C" not in "FishC"
  44. False
  45. >>> g = ["del 语句用于删除一个或多个指定的对象"]
  46. >>> x = "FishC"
  47. >>> Y = [1,2,3]
  48. >>> del x,y
  49. >>> x
  50. Traceback (most recent call last):
  51.   File "<pyshell#32>", line 1, in <module>
  52.     x
  53. NameError: name 'x' is not defined
  54. >>> y
  55. Traceback (most recent call last):
  56.   File "<pyshell#33>", line 1, in <module>
  57.     y
  58. NameError: name 'y' is not defined
  59. >>> x = [1,2,3,4,5]
  60. >>> del x[1:4]
  61. >>> x
  62. [1, 5]
  63. >>> y = [1,2,3,4,5]
  64. >>> y[1:4] = []
  65. >>> y
  66. [1, 5]
  67. >>> x = [1,2,3,4,5]
  68. >>> del x[::2]
  69. >>> x
  70. [2, 4]
  71. >>> y = [1,2,3,4,5]
  72. >>> y[::2] = []
  73. Traceback (most recent call last):
  74.   File "<pyshell#44>", line 1, in <module>
  75.     y[::2] = []
  76. ValueError: attempt to assign sequence of size 0 to extended slice of size 3
  77. >>> x = [1,2,3,4,5]
  78. >>> x.clear()
  79. >>> x
  80. []
  81. >>> x = [1,2,3,4,5]
  82. >>> del x[:]
  83. >>> x
  84. []
  85. >>>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-4-28 10:19:40 | 显示全部楼层
打卡
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-5-19 21:12:13 | 显示全部楼层
坚持学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-8-7 10:19:47 | 显示全部楼层
s=[1,2,3]
id(s)
4469321280
s*=2
s
[1, 2, 3, 1, 2, 3]
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=[1,2,3,4,5]
del a[1:3]
a
[1, 4, 5]
a[1:3]=a[]
SyntaxError: invalid syntax
a[1:3]=[]
a
[1]
a=[1,2,3,4,5]
a[1:3]=[]
a
[1, 4, 5]
a=[1,2,3,4,5]
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
[1, 2, 3, 4, 5, '11']
a=[1,2,3,4,5]
a[len(s):]=['11']
a
[1, 2, 3, 4, 5, '11']
a=[1,2,3,4,5]
del a[::3]
a
[2, 3, 5]
a=[1,2,3,4,5]
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=[1,2,3]
a.clear()
a
[]
a=[1,2,3]
del a[::]
a
[]
a=[1,4]
del a[:]
a
[]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-8-14 19:30:21 | 显示全部楼层
打卡
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-8-16 14:25:58 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-9-2 11:34:25 | 显示全部楼层
学习打卡
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-23 11:14:49 | 显示全部楼层
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> oho =[1,2,3,4,5]
>>> 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 =[1,2,3,4,5]
>>> 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[i]=oho[i]*2

       
>>> oho
[2, 4, 6, 8, 10]
>>> for i in range(len(oho)):
        oho[i]=oho[i]*2

       
>>> oho
[4, 8, 12, 16, 20]
>>> oho =[1,2,3,4,5]
>>> x = [i for i in range(oho[4] * 2)]
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x = [i for i in range(10)]
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x = [i+1 for i in range(10)]
>>> x
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> x = []
>>> for i in range(10):
        x.append(i+1)

       
>>> x
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> y = [c for c in FishC]
Traceback (most recent call last):
  File "<pyshell#46>", line 1, in <module>
    y = [c for c in FishC]
NameError: name 'FishC' is not defined
>>> y = [c for c in "FishC"]
>>> 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 = [c for c in "FishC"]
>>> y = [c+1 for c in "FishC"]
Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    y = [c+1 for c in "FishC"]
  File "<pyshell#53>", line 1, in <listcomp>
    y = [c+1 for c in "FishC"]
TypeError: can only concatenate str (not "int") to str
>>> y = [c2 for c in "FishC"]
Traceback (most recent call last):
  File "<pyshell#54>", line 1, in <module>
    y = [c2 for c in "FishC"]
  File "<pyshell#54>", line 1, in <listcomp>
    y = [c2 for c in "FishC"]
NameError: name 'c2' is not defined
>>> y = [c*2 for c in "FishC"]
>>> y
['FF', 'ii', 'ss', 'hh', 'CC']
>>> y = [c*3 for c in "FishC"]
>>> 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 = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
>>> col2 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]
SyntaxError: invalid syntax
>>> >>> matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
>>> col2 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]>>> matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
>>> col2 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]
SyntaxError: invalid syntax
>>> >>> matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
>>> col2 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]
SyntaxError: invalid syntax
>>> >>> matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
>>> col2 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
SyntaxError: invalid syntax
>>> matrix = [[1, 2, 3],
...           [4, 5, 6],
...           [7, 8, 9]]
Traceback (most recent call last):
  File "<pyshell#67>", line 2, in <module>
    ...           [4, 5, 6],
TypeError: 'ellipsis' object is not subscriptable
>>> matrix = [[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]]
>>> row[1]
Traceback (most recent call last):
  File "<pyshell#69>", line 1, in <module>
    row[1]
NameError: name 'row' is not defined
>>> row[1]
Traceback (most recent call last):
  File "<pyshell#70>", line 1, in <module>
    row[1]
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 = [row[1] for row in matrix]
>>> col2
[2, 5, 8]
>>> row[1]
Traceback (most recent call last):
  File "<pyshell#74>", line 1, in <module>
    row[1]
NameError: name 'row' is not defined
>>> col2
[2, 5, 8]
>>> matrix = [[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]]
>>> for row in matrix
SyntaxError: invalid syntax
>>> for row in matrix:
        row[1]

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

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

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

       
3
6
9
>>> for row in matrix:
        row[0]

       
1
4
7
>>> for row in matrix:
        row[0][0]

       
Traceback (most recent call last):
  File "<pyshell#90>", line 2, in <module>
    row[0][0]
TypeError: 'int' object is not subscriptable
>>> matrix = [[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]]
>>> matrix[i][i]
Traceback (most recent call last):
  File "<pyshell#92>", line 1, in <module>
    matrix[i][i]
IndexError: list index out of range
>>> dd = matrix[i][i]
Traceback (most recent call last):
  File "<pyshell#93>", line 1, in <module>
    dd = matrix[i][i]
IndexError: list index out of range
>>> len(matrix)
3
>>> range(len(matrix))
      
SyntaxError: invalid character in identifier
>>> range(len(matrix))
range(0, 3)
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> range(len(matrix))
range(0, 3)
>>> AAA = [matrix[q][q] 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
[1, 5, 9]
>>> 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[5]
'上山打老虎'
>>> 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     ::=  [[fill]align][sign][#][0][width][grouping_option][.precision][type]
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     ::=  [[fill]align][sign][#][0][width][grouping_option][.precision][type]
       
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]
>>> (1, 2, 3) + (4, 5, 6)
(1, 2, 3, 4, 5, 6)
>>> "123" + "456"
'123456'
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 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 = [1, 2, 3]
>>> s
[1, 2, 3]
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> id(s)
3205915134272
>>> s *= 2
>>> s
[1, 2, 3, 1, 2, 3]
>>> 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 = [1, 2, 3]
>>> y = [1, 2, 3]
>>> 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 = [1, 2, 3]
>>> 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]
>>> (1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
>>>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-25 16:43:21 | 显示全部楼层
知识点太多了,要是可以知识点与知识点之间,间隔再插入一些运用知识点的游戏或者其他什么的,就好了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-4 11:31:11 | 显示全部楼层
Learning...
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-23 20:26:36 | 显示全部楼层
del y[::]可以的吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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 = [1, 2, 3]
>>>y = [1, 2, 3]
>>>x is not y
True
>>>id(x)
1606768127168
>>>id(y)
1606768096192
>>>x *= 2
>>>x
[1, 2, 3, 1, 2, 3]
>>>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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-3 16:01:22 | 显示全部楼层
学习,多练习,有时候会被小问题搞半天

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-27 15:08:41 | 显示全部楼层
打卡坚持学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-11 19:59:52 | 显示全部楼层
打卡
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-29 14:30:08 | 显示全部楼层
做啥呢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-12 11:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表