python 去掉字符串最后面一个字符,字符分割方法使用
python 里面,遍历 list, dic 的方法 示例
python 去掉字符串最后面一个字符
#!/usr/bin/evn python import numpy as np import pandas as pd # 指标配置 ind_config = [ { 'name': 'DN_XGB_FACTOR_1', 'desc': '懂牛选股宝-仓位相关', 'fieldsDic':{ 'fieldsA': [ {'ind_id': 500, 'field': 'XG', 'name': 'ZJMR', 'comment': '周净买入', 'name2': 'ZJMR'}], "fieldsB": [ {'ind_id': 499, 'field': 'XG', 'name': 'YJMR', 'comment': '月净买入', 'name2': 'YJMR'} ], "fieldsC": [ {'ind_id': 498, 'field': 'XG', 'name': 'CJZC', 'comment': '建仓', 'name2': 'CREATEC'}], "fieldsD": [ {'ind_id': 497, 'field': 'XG', 'name': 'ZJZC', 'comment': '加仓', 'name2': 'ADDC'}], "fieldsE": [ {'ind_id': 496, 'field': 'XG', 'name': 'CWSG', 'comment': '仓位上攻', 'name2': 'CWSG'}], "fieldsF": [ {'ind_id': 495, 'field': 'XG', 'name': 'CWXG', 'comment': '仓位新高', 'name2': 'CWXG'}], "fieldsG": [ {'ind_id': 494, 'field': 'XG', 'name': 'NSMR', 'comment': '逆势买入', 'name2': 'NSMR'}], "fieldsH": [ {'ind_id': 493, 'field': 'XG', 'name': 'LXZC', 'comment': '连续增仓', 'name2': 'LXZC'}] } } ] lista = ["AA","BB","CC","DD"] dicb = {"keya":10, "keyb":20, "keyc":200, "keyd":123} print("lista:") for val in lista: print(val) print("dicb:") for val in dicb: print("key:",val,"val:",dicb[val]) #去掉字符串最后面一个字符 stra = "abcdefghijklmn" stra = stra[0:len(stra)-1] print("stra:", stra) ## for 遍历dic, list
python 是比较灵活的语法,
比如在某些格式化的字符串,统计里面数据个数。
示例:
# 某些格式化的字符串,统计里面数据个数 stra = "688819.SH|688777.SH|688599.SH|688596.SH|688560.SH|688536.SH|688408.SH" print("len:",len(stra.split("|")))