在python输出语句中,我们常用到“%s”符号。%s作用是将对象传到str()方法中进行处理,输出字符串。例如:
.format() format()函数用来收集其后的位置参数和关键字段参数,并用他们的值填充字符串中的占位符。通常format()函数配合print()函数达到强格式化的输出能力.例子如下:
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
from sklearn.svm import SVC
iris=load_iris()
X_train,X_test,y_train,y_test=train_test_split(iris.data,iris.target,random_state=0)
print('Size of training set:{} size of testing set:{}'.format(X_train.shape[0],X_test.shape[0]))
print("Size of training set:%s,size of testing set:%s" %
(X_train.shape[0], X_test.shape[0]))
out:
Size of training set:112 size of testing set:38
Size of training set:112,size of testing set:38