The print function is used to print characters, and there are several ways to write them; the following is the most recommended way of writing, which is to use the format method to format strings:
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))
Placeholder | replace content |
---|---|
%d | integer |
%f | floating point number |
%s | string |
%x | hex integer |
print("This is {} value {:.1f}".format('PI', 3.1415926)) print('{0}'s weight is {1:.2f}'.format('Aniu', 99.786))
This is PI value 3.1 A cow's weight is 99.79
input with input:
var_input = input() print(var_input)