print功能用来打印字符,有好几种写法;下面是目前最为推荐的写法,是使用format方法格式化字符串:
print("xxxxx{}, yyyyy{}".format(a, b))。
my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = 'Blue'
my_teeth = 'White'
my_hair = 'Brown'
print("Let's talk about {}".format(my_name ))
print("He's {} inches tall.".format(my_height))
print("He's {} pounds heavy.".format(my_weight))
print("Acutally that's not too heavy.")
print("He's got {} eyes and {}.".format(my_eyes,my_hair))
print("His teeth are usually {} depending on the coffee".format(my_teeth))
# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print("If I add {},{}, and {} I get {}".format(my_age,my_height,my_weight,total))
占位符 | 替换内容 |
---|---|
%d | 整数 |
%f | 浮点数 |
%s | 字符串 |
%x | 十六进制整数 |
print("This is {} value {:.1f}".format('PI', 3.1415926))
print('{0}的体重为{1:.2f}'.format('阿牛', 99.786))
This is PI value 3.1
阿牛的体重为99.79
输入用input:
var_input = input()
print(var_input)