python--spring练习2

来源:互联网 发布:htc vive unity3d 编辑:程序博客网 时间:2024/05/18 01:19
#coding:utf-8# string clicea_string='my alpert  starts where your alphabet ends.'print a_string[3:21]print a_string[0:2]print a_string[:18]print a_string[18:]#by = b'abcd\x65'print by   #abcdeprint type (by)  #<type 'str'>print len(by) #5#by += b'\xff'#print byprint by[0]barr = bytearray(by)print barr  #abcde#常用的字符串方法s = ''' finish flies are the re0-sult of years of scientific ... study combined with the ... experice of yeaer.. '''s.splitlines()print s.splitlines()  ##r多行输入作为参数,返回一个字符串列表,列表的元素是原来的单行字符串print s.upper()print s.upper().count('F')query = 'user=test&database=master&password=123456'a_list = query.split('&')print a_list  #['user=test', 'database=master', 'password=123456']a_list_of_lists=[v.split('=',1) for v in a_list] print a_list_of_lists  #[['user', 'test'], ['database', 'master'], ['password', '123456']]a_dict = dict(a_list_of_lists) print a_dict   #{'password': '123456', 'user': 'test', 'database': 'master'}