python字符串、元组和列表常用的一些方法
2012-02-29 15:29
417 查看
#coding=UTF-8
#the first method
print "\n"
#寻找字符串中第一个出现可以用find
#寻找由特定间隔符隔开的第一个可以用find
#需找特定间隔符隔开的第几个,先用split分割,然后用下标找
#判断一个元素是否在列表中,可以使用in很简单
file_object =open("c:\\sqltest.txt","r")
sqlquery=["select","show"]
sqlupdate=["insert","update","delete"]
sqldml=["create","drop"]
lines = file_object.readlines()
for line in lines:
sql = line
n=sql.find(" ")
sqltype = sql[0:n]
if sqltype in sqlquery:
print sqltype+" is a query sql"
elif sqltype in sqlupdate:
print sqltype+" is a update sql"
elif sqltype in sqldml:
print sqltype+" is a create/drop sql"
#print sql,
print "\n\nsuccess"
file_object.close()
字符串、元组和列表常用的几个函数:split、find、index、in、append、分片操作list[m:n],str[m:n]和两者的强制转化list()。遍历时候可以使用for…in…逐个判断。
#the first method
print "\n"
#寻找字符串中第一个出现可以用find
#寻找由特定间隔符隔开的第一个可以用find
#需找特定间隔符隔开的第几个,先用split分割,然后用下标找
#判断一个元素是否在列表中,可以使用in很简单
file_object =open("c:\\sqltest.txt","r")
sqlquery=["select","show"]
sqlupdate=["insert","update","delete"]
sqldml=["create","drop"]
lines = file_object.readlines()
for line in lines:
sql = line
n=sql.find(" ")
sqltype = sql[0:n]
if sqltype in sqlquery:
print sqltype+" is a query sql"
elif sqltype in sqlupdate:
print sqltype+" is a update sql"
elif sqltype in sqldml:
print sqltype+" is a create/drop sql"
#print sql,
print "\n\nsuccess"
file_object.close()
字符串、元组和列表常用的几个函数:split、find、index、in、append、分片操作list[m:n],str[m:n]和两者的强制转化list()。遍历时候可以使用for…in…逐个判断。
相关文章推荐
- python学习总结---列表、元组、字符串、字典中一些常用函数
- python字符串,列表,字符串,元组,集合的一些方法
- python中的一些遍历列表,元组,字符串等的方法,如:range,enumerate
- python实操(5):python数据类型及常用操作,数字、字符串、元组、列表、字典、集合
- python的列表,元组以及字典的一些内置方法与属性
- Python 字典<->元组<->列表<->字符串 互转方法
- Python字符串、元组、列表、字典互相转换的方法
- Python列表操作和字符串的常用方法
- Python 列表、元组、字典t的常用方法
- 2.python基础之—列表,元组,字典,集合,字符串的使用方法
- Python字符串、元组、列表、字典互相转换的方法
- Python字符串、元组、列表、字典互相转换的方法
- 列表,元组,字符串,字典,常用方法
- python判断变量是否为int、字符串、列表、元组、字典等方法
- 【学神-RHEL7】P4-Python列表操作和字符串的常用方法
- Python字符串、元组、列表、字典互相转换的方法
- python 字符串,列表,字典常用方法
- 序列(字符串,列表,元组)和字典常用方法
- python列表、元组、字典的介绍及常用方法
- Python 字符串常用方法