YDOOK:Python 格式化字符串 {变量名} 使用

tech2022-09-12  94

Python 格式化字符串 {变量名} 使用

需要加 f

def printStr(str): print(f'The input str = {str}') printStr('123abc')

结果

The input str = {str} Process finished with exit code 0

不加 f :

def printStr(str): print('The input str = {str}') printStr('123abc')

结果

The input str = {str} Process finished with exit code 0

结论

不加 f 无法格式化字符串。

最新回复(0)