今天忽然想了解一下字符串的格式化的方法,總結了一下:html
name = input("name:") age = int(input("age:")) salary = int(input("salary:")) job = input("job:") """ info = ''' ===============info of %s============== name: %s age: %d salary: %d job: %s ''' % (name,name,age,salary,job) print(info)
name = input("name:") age = int(input("age:")) salary = int(input("salary:")) job = input("job:") info2 = ''' ===============info of {_name}============= name: {_name} age: {_age} salary: {_salary} job: {_job} '''.format(_name = name, _age = age, _salary=salary, _job=job) print(info2)
name = input("name:") age = int(input("age:")) salary = int(input("salary:")) job = input("job:") info3 = ''' ============info of {0}================= name: {0} age: {1} salary: {2} job: {3} '''.format(name, age, salary, job) print(info3)
參考:https://www.cnblogs.com/chuckzeng/p/8010699.htmlweb