方式一:字符串拼接
host=input("please input your host:")
hostname=input("please input your hostname:")
ip=input("please input your ip:")
ns=input("please input your ns:")
hotel='''-----------host:'''+host+'''-----------
host:'''+host+'''
hostname:'''+hostname+'''
ip:'''+ip+'''
ns:'''+ns
print(hotel)
方式二:带格式输出
host=input("please input your host:")
hostname=input("please input your hostname:")
ip=input("please input your ip:")
ns=input("please input your ns:")
hotel='''-----------host: %s -----------
host:%s
hostname:%s
ip:%s
ns:%s
'''%(host,host,hostname,ip,ns)
print(hotel)
方式三:format函数变量映射
host=input("please input your host:")
hostname=input("please input your hostname:")
ip=input("please input your ip:")
ns=input("please input your ns:")
hotel='''-----------host:{_host}-----------
host:{_host}
hostname:{_hostname}
ip:{_ip}
ns:{_ns}
'''.format(_host=host,
_hostname=hostname,
_ip=ip,
_ns=ns
)
print(hotel)
或
host=input("please input your host:")
hostname=input("please input your hostname:")
ip=input("please input your ip:")
ns=input("please input your ns:")
hotel='''-----------host:{0}-----------
host:{0}
hostname:{1}
ip:{2}
ns:{3}
'''.format(host,hostname,ip,ns)
print(hotel)