|
发表于 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)
>>> |
|