当前位置:首页 > Python > 正文内容

索引运算符【】

Doraemon4年前 (2020-02-16)Python3840

选择字符串的子序列

语法【start:finish】

        start:子序列开始位置的索引值

        finish:子序列结束位置的下一个字符的索引值

如果不提供start或者finish,默认start为第一个字符,finish为最后一个字符。

例如

>>>my_str='hello world'
>>>my_str[6:10]
'worl'
>>>my_str[6:]
'world'
>>>my_str[:6]
'hello'
>>>

接收三个参数

start:finish:countBy

默认countBy为1

>>>my_str='hello world'
>>>my_str[0:11:2]
'hlowrd'

获得逆字符串

>>>my_str='spam'
>>>reverse_str=my_str[::-1]
>>>print(reverse_str)
maps


扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://myfpga.cn/index.php/post/130.html

分享给朋友:
返回列表

上一篇:for循环

下一篇:搜索字符串

“ 索引运算符【】” 的相关文章

搜索字符串

搜索字符串

常用搜索字符串中子串的方法str.count(substring)      返回str中substring子串出现的无覆盖的次数str.find(s1)                    返回s1在这个字符串的最低下标,如果字符串中不存在s1,则返回-1str.rfind(s1)       ...

Python自动清理错误图片,深度学习训练数据集准备

Python自动清理错误图片,深度学习训练数据集准备

使用python运行from PIL import Image from pathlib import Path import os   path = r'.'  ...

(原创)使用Python对任意网站图片进行爬取,仅用于学习

(原创)使用Python对任意网站图片进行爬取,仅用于学习

import os import time import argparse import requests import re import io from urllib.parse import ...

(原创)使用Python递归获取网页内的所有URL,并进行清洗

(原创)使用Python递归获取网页内的所有URL,并进行清洗

import argparse import time from urllib.parse import urljoin, urlparse from selenium import webdriver...

(原创)使用Python提取ISE工程的RTL代码

(原创)使用Python提取ISE工程的RTL代码

在工程文件夹下运行Python程序即可 #Author       : / #Description  : 从ISE的项目文件夹中提取rtl文件,用于LEDA调试 #Time ...