为了账号安全,请及时绑定邮箱和手机立即绑定

Python笔记

标签:
Python

1、字符串
str='Hello World!'
1)取值print str[0],得到:H
2)分割str.split('o'),得到:['Hell', ' w', 'rd']

2、列表List
list=['qq',''ww',''ee']
1)追加list.append('rr'),得到:['qq', 'ww', 'ee', 'rr']
2)删除del list[1],得到:['qq', 'ee', 'rr']
3)个数len(list)
4)反转list.reverse()

3、字典Dictionary
dict={'name':'mangmang','age':24}
1)取值print dict['age'],得到:24
2)修改dict['age']=25,得到:25
3)删除del dict['age'],得到:{'name': 'mangmang'}

4、For循环
1)字符串循环

for word in 'Hello world!':
    print word

2)循环List

//第一种
list是=['qq', 'ww', 'ee', 'rr']
for list in lists:
    print list
//第二种通过序列索引迭代
//range取值范围是0~3
for num in range(len(lists):
    print lists[num]

5、数据库连接
1)使用流程
-引入 API 模块。
-获取与数据库的连接。
-执行SQL语句和存储过程。
-关闭数据库连接。
2)连接数据库
db = MySQLdb.connect("localhost","testuser","test123","库名称" )
3)获取操作游标/切换库操作
cursor = db.cursor()
cursor.select_db('database name')
4)执行sql语句
cursor.execute("SELECT VERSION()")
5)获取数据
data = cursor.fetchone()
6)关闭数据库
db.close()
7)提交事务,除查询外的操作使用
db.commit()
8)获取所有数据
cursor.fetchall()
9)返回执行execute()方法后影响的行数
cursor.rowcount()

点击查看更多内容
4人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
软件测试工程师
手记
粉丝
172
获赞与收藏
904

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消