python 字符串和字典】的更多相关文章

python字符串/列表/字典互相转换 目录 字符串与列表 字符串与字典 列表与字典 字符串与列表 字符串转列表 1.整体转换 str1 = 'hello world' print(str1.split('这里传任何字符串中没有的分割单位都可以,但是不能为空')) # 输出:['helloworld'] 2.分割 str2 = "hello world" list2 = list(str2) print(list2) #输出:['h', 'e', 'l', 'l', 'o', ' ',…
一.需求 为了处理从redis中拿到的value,如下 {"appId":"ct","crawlSts":false,"health":"0","heartTime":"2018-12-10 00:23:57","localeIp":"129.204.161.75","loginNo":"13061…
字符串转换成字典 json越来越流行,通过python获取到json格式的字符串后,可以通过eval函数转换成dict格式: >>> a='{"name":"yct","age":10}' >>> eval(a) {'age': 10, 'name': 'yct'} 支持字符串和数字,其余格式的好像不支持: 字符串转换成列表和元组 使用list >>>a='1234' >>>…
本篇内容 字符串的常用方法 列表的常用方法 字典的常用方法 字符串的常用方法 center 字符居中显示,指定字符串长度,填充指定的填充字符 string = "40kuai" print(string.center(50,'*')) # 输入 #----------------------40kuai---------------------- count 返回字符串中出现指定字符的个数,可选参数中解释为开始和结束符号. string = '40kuai' ') # 输出 # fin…
一.字符串操作 name = "my name is \t {name} and i am {year} years old" 1.首字母大写 print(name.capitalize()) 2.统计字符串中相同的字符 print(name.count("n")) 3.格式化字符串 print(name.center(50,"-")) #打印50个-,把name的值放中间 4.判断字符串以什么结尾,返回true或false print(name…
python基础(一): 运算符: 算术运算: 除了基本的+ - * / 以外,还需要知道 :  // 为取整除 返回的市商的整数部分 例如: 9 // 2  ---> 4  , 9.0 //  2.0 --->4.0   %  为取余数  返回的是除法的余数  没有余数则为0  例如: 3 % 3 ---> 0 , 有余数:6 % 3 --->2 逻辑运算符: and , or , not 比较运算符: == 判断两个数是否相等 , != 判断两个数是否不相等 ,  > ,…
今天学习内容如下: 1.学习昨天练习题目的解题新方法 #1.使用while循环输入 1 2 3 4 5 6 8 9 10 ''' count = 0 while count < 10: count += 1 # count = count + 1 if count == 7: print(' ') else: print(count) count = 0 while count < 10: count += 1 # count = count + 1 if count == 7: contin…
方法一: 通过内置函数eval str_info = '{"name": "test", "age": 18}' dict_info = eval(str_info) print("string info type is -->: %s" % (type(str_info))) print("dict info type is -->: %s" % (type(dict_info))) prin…
经常会遇到字典样式字符串的处理,这里做一下记录. load load针对的是文件,即将文件内的json内容转换为dict import json test_json = json.load(open("test.json"), "r") loads loads是直接将字符串对象转换为了dict import json test = '{"a":123, "b":456}' test_json = json.loads(test…
一.python字符串的处理方法 >>> str = ' linzhong LongXIA ' >>> str.upper() #字符串str全部大写 ' LINZHONG LONGXIA >>> str.lower() #字符串str全部小写 ' linzhong longxia ' >>> str.swapcase() #字符串str大小写反转 ' LINZHONG lONGxia ' >>> str.title…