split切割字符


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> 等 作变量名赋值  导致报错。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值