""" author:claire data:2022 year 06 month 23 title: Sum of two numbers """
num1 = 1.5
num2 = 3.8
sum = num1+num2
print("%f + %f = %f" % (num1,num2,sum ))
Pay attention to what
The front is %f %d such
No comma after , after % There should be commas inside
format() The function is mainly used to format strings
pycharm Comment lines ctrl+/
str = " My name is {}, My nationality is {}".format(" Zhang San "," China ")
print(str)
str = " My name is {0}, My nationality is {1}".format(" Zhang San "," China ")
print(str)
str = " My name is {1}, My nationality is {0}".format(" Zhang San "," China ")
print(str)
print(" The websites :{name}, Address {url}".format(name="cc",url="123"))
site = {
"name":"cai","url":"123"}
print(" The websites :{name}, Address {url}".format(**site))
list = ["IT Private school ","www.t"]
str = " Website name :{0[0]}, website :{0[1]}, Time :{1}".format(list,2020)
print(str)
name = " Zhang San "
age = 18
print(f" Hello ,{
name} This year, {
age} Year old ")