格式化打印
1)%s:代表字符串
2)%d:代表整数
3)%f:代表浮点数
1.格式化打印1
name = "xiaoming" age = 29 job = "IT" print("I am %s,age:%d,job:%s" %(name,age,job))
2.格式化打印2
msg = ‘‘‘ Information of %s name: %s age: %d job: %s ‘‘‘ %(name,name,age,job) print(msg)
3.去除空白
strip(...) method of builtins.str instance S.strip([chars]) -> str Return a copy of the string S with leading and trailing whitespace removed. #去除字符串的开头和末尾的空格 If chars is given and not None, remove characters in chars instead. 实例: name = " xiaoming" age = 29 job = "IT" name = name.strip() print("I am %s,age:%d,job:%s" %(name,age,job))
时间: 2024-10-11 05:37:38