一.字符串操作 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…
type()查看类型 //取整除 **幂 成员运算符: in x在y序列中,就返回true 反之 not in 身份运算符: is is not 逻辑运算符 and or not 字符编码 问题 通用序列操作 索引 >>> 'hello'[1]'e'>>> 'hello'[-2]'l'>>> 分片 >>> 'hello'[2:4]'ll' [a:b] 相当于a<=x<b >>> number=[1,…
方法一: 通过内置函数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…