为什么 print(Fraction('b')) 不起作用是因为您要求python从字符“b”中创建一部分。你需要做的是得到b的字符串表示,它是str(b),所以 Fraction(str(b))
print(Fraction('b'))
Fraction(str(b))