37,742
社区成员
发帖
与我相关
我的任务
分享
ValueError: unsupported format character 'b' (0x62) at index 9
SyntaxError: invalid character in identifier
weight))
weight))
# Function:
# 演示错误的代码,应该如何改为正确的代码
# Qpython3-CSDN论坛
# https://bbs.csdn.net/topics/395926666
# Author: Crifan Li
# Update: 20200225
age=3
# name=("tom") # 看起来像是tuple元祖,实际上不是
# print("type(name)=%s" % type(name)) # type(name)=<class 'str'>
# normlTupleValue = ("tom", "tony")
# print("type(normlTupleValue)=%s" % type(normlTupleValue)) # type(normlTupleValue)=<class 'tuple'>
name="tom" # 显示指明是str字符串
# weight=55
# print("type(weight)=%s" % type(weight)) # type(weight)=<class 'int'>
weight=55.0 # 显示指明是float浮点数
# print("type(weight)=%s" % type(weight)) # type(weight)=<class 'float'>
# print("我叫%s,我今年%b岁,我的体重是%.2f公斤"%(name,age,weight))
# ValueError: unsupported format character 'b' (0x62) at index 9
# %d 用于格式化 integer整数
print("我叫%s,我今年%d岁,我的体重是%.2f公斤"%(name,age,weight))
# 我叫tom,我今年3岁,我的体重是55.00公斤