python如何在一个字符串中使用两个占位符

2025-02-27 09:23:37
推荐回答(1个)
回答1:

1. 使用连接符: +

12

world = "World"print "Hello " + world + " ! "

2. 使用占位符来内插

world = "World"print "Hello %s !" % world

3. 使用函数

li = ['my','name','is','bob']mystr = ' '.join(li)print mystr

上面的语句中字符串是作为参数传入的,可以直接用变量替换:

begin_date = '2012-04-06 00:00:00'end_date = '2012-04-06 23:59:59'select * from usb where time between to_date(begin_date,'YYYY-MM-DD HH24:MI:SS') and to_date(end_date,'YYYY-MM-DD HH24:MI:SS')