st = '1-3万/月' # 变量名不要用str 之类
ret1 = st.split('/')[0]
ret2 = ret1.split('-')
result1 = ret2[0]
result2 = ret2[1]
ret3 = result2[-1:]
ret4 = result2[:-1]
if ret3 == 'k' or ret3 == '千':
result3 = float(result1)*1000
result4 = float(ret4)*1000
elif ret3 == '万':
result3 = float(result1) * 10000
result4 = float(ret4) * 10000
else:
pass
print(ret3)
print(type(ret3))
print(result3)
print(result4)
*******************************
针对 0.4-7万/月 10-24万/年
st = item['salary'] # pos_item['salary']
ret1 = st.split('/')[0]
ret2 = ret1.split('-')
ret5 = st.split('/')[1]
result1 = ret2[0]
result2 = ret2[1]
ret3 = result2[-1:]
ret4 = result2[:-1]
if ret3 == 'k' or ret3 == '千':
result3 = float(result1) * 1000
result4 = float(ret4) * 1000
elif ret3 == '万' and ret5 == '月':
result3 = float(result1) * 10000
result4 = float(ret4) * 10000
elif ret3 == '万' and ret5 == '年':
result3 = float(result1) / 12 * 10000
result4 = float(ret4) / 12 * 10000
# #####################################
st = '150元/小时' # 150元/天 # 14元/小时
ret1 = st.split('/')[0]
ret2 = st.split('/')[1]#
result2 = ret1[:-1]
if ret2 == '天' :
result3 = int(result2) * 30 # 30天
elif ret2 == '小时':
result3 = int(result2) * 8 * 30
else:
pass
print(result3)
不能 用 < str >\<int> 等 作变量名赋值 导致报错。