python 输出语句的写法

时间:2023-03-09 01:48:00
python 输出语句的写法

总结:

1、类似于C语言的格式化输出,先写转换符,再写待转换的对象。

2、与C语言不同的是,转换符和待转换的对象之间,不能用逗号分隔。

 #!/usr/bin/env python

 #print digital variable
p = 10
x = 20
print("p=%d x=%d" %(p,x)) #print string object
format = "Hello , %s. %s enough for ya?"
values = ('world', 'Hot')
print(format%values) #print dictionary object
phonenum = {'Beth': '', 'Alice':'', 'Cecil':''}
print("Cecil's phone number is %(Cecil)s"%phonenum)