今天记两个注意点
print('he said "Today\'s weather is good."')
注意:如果不加‘\’会报错,因为print会按顺序执行前两个单引号的内容
print("{:.3f}".format(3.1415926))
注意:输出3.142(四舍五入)
操作远程数据库 3/14
import mysql.connector
mydb = mysql.connector.connect( #连接数据库
host = " ", # 数据库主机地址
user = " ", # 数据库用户名
passwd = " ", # 数据库密码
database = " "
)
def liketel(tel1,tel2):
try:
mycursor = mydb.cursor() //游标
mycursor.execute("select * from table where volumn like '"+tel1+"%' and Tel like '%"+tel2+"';") //执行
myresult = mycursor.fetchall() //返回
if len(myresult) == 0:
print('没有找到')
for element in myresult:
print(element)
except:
print('Error.')
liketel( , )