在 Python 中字符串连接有多种方式,这里简单做个总结,应该是比较全面的了,方便以后查阅. 加号连接 第一种,通过+号的形式: >>> a, b = 'hello', ' world' >>> a + b 'hello world' 逗号连接 第二种,通过,逗号的形式: >>> a, b = 'hello', ' world' >>> print(a, b) hello world 但是,使用,逗号形式要注意一点,就是只能用于pr…
在使用pymysql模块时,在使用字符串拼接的注意事项错误用法1 sql='select * from where id="%d" and name="%s" ' %(id,name) cursor.execute(sql)错误用法2 sql="select * from test where id=" + str(id) + " and name='' + name cursor.execute(sql)正确用法 sq…
字符串拼接: %s表示可以传任意类型的值,%d表示只能传数字 test = "my name is %s,age %d" %("xyp",19) print(test) 结果: 或者: test = "my name is %(name)s,age %(age)d" %{'name':'xyy','age':19} print(test) // 这种方式传的值只能是字典 结果: %f后面接的是浮点数(小数)默认小数点后面是六位数,不够的用0补 t…