python的字符串截取、拼接

python的字符串截取

str =0123456789print str[0:3] #截取第一位到第三位的字符
print str[:] #截取字符串的全部字符
print str[6:] #截取第七个字符到结尾
print str[:-3] #截取从头开始到倒数第三个字符之前
print str[2] #截取第三个字符
print str[-1] #截取倒数第一个字符
print str[::-1] #创造一个与原字符串顺序相反的字符串
print str[-3:-1] #截取倒数第三位与倒数第一位之前的字符
print str[-3:] #截取倒数第三位到结尾
print str[:-5:-3] #逆序截取,具体啥意思没搞明白?
text[3:4]   #获取位置3,4,但是不包括位置4,那么只是去位置3上的字符
012
0123456789
6789
0123456
2
9
9876543210
78
789
96

Python 拼接字符串的几种方式

str_name1 = 'To'
str_name2 = 'ny'
str_name = str_name1 + str_name2
print(str_name)

项目相关

print('hello')
    print(opt.input_video)
    input_Name=opt.input_video
    gang="\\"
    videoname=input_Name[input_Name.rfind(gang)+1:]
    print(videoname.find('.'))
    index=videoname.find('.')
    print(videoname)
    video_pre=videoname[0:index]
    print(video_pre)
    last=video_pre[-1]
    print(last)
    suffix="_det.mp4"
    frame_suffix="_frame"
    whole_frame_save=video_pre+frame_suffix
    whole_Video_Name=video_pre+suffix
    txt_sufficx="_det.txt"
    whole_txt_Path=video_pre+txt_sufficx
    print(whole_Video_Name)
    print(whole_frame_save)
    print(whole_txt_Path)
    if last=="1":
        txt="H:\listen\calm\calm_txt\\"+whole_txt_Path
    if last=="2":
        txt="H:\listen\hurry\hurry_txt\\"+whole_txt_Path
    print(txt)
    print('world')
if opt.output_format == 'video':
        if last=="1":
            result_root2="H:\listen\calm\calm_det_video"
        if last=="2":
            result_root2="H:\listen\hurry\hurry_det_video"
        else:
            result_root2="H:\Tracking\Towards-Realtime-MOT-master\Towards-Realtime-MOT-master"
        output_video_path = osp.join(result_root2, whole_Video_Name)
        cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format(osp.join(result_root, whole_frame_save), output_video_path)
        os.system(cmd_str)

hello
H:\listen\calm\calm_video\1_1.mp4
3
1_1.mp4
1_1
1
1_1_det.mp4
1_1_frame
1_1_det.txt
H:\listen\calm\calm_txt\1_1_det.txt
world
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值