ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
1、format(),为要插入的变量留出一个空间 ``` greeting = "Good {},{}.How are you doing" name = "sanqian" time = "morning" print greeting.format(name,time) ``` 2、format(),加入带有键的花括号 ``` specials_text = "Good {time}! Today's specials are:{special} and {special2}" time = "afternoon" food1 = "spam with eggs" food2 = "eggs with spam" print specials_text.format(time = time,special = food1,special2 = food2) ``` 3、format(),变量位置用整数来填充![] ``` line = "cities with python meeet-ups:{0},{1},{2}" print line.format("district of columbia","portland","and many more!") ```