>>> word = "Python"

>>> word[:2]  # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:]  # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters from the second-last (included) to the end
'on'

>>> word[:2]  # 从开始到2位置
'Py'
>>> word[4:]  # 从4到末尾
'on'
>>> word[-2:] # 从-2到末尾
'on'

| P | y |  t |  h | o | n |
 0   1   2   3   4   5    6
-6  -5  -4  -3  -2  -1

Python字符串图解的更多相关文章

  1. Python 简明教程 --- 7,Python 字符串

    微信公众号:码农充电站pro 个人主页:https://codeshellme.github.io 过早的优化代码是罪恶之源. -- Donald Knuth 目录 无论哪种编程语言,字符串处理都是最 ...

  2. 关于python字符串连接的操作

    python字符串连接的N种方式 注:本文转自http://www.cnblogs.com/dream397/p/3925436.html 这是一篇不错的文章 故转 python中有很多字符串连接方式 ...

  3. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  4. Python 字符串

    Python访问字符串中的值 Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. Python访问子字符串,可以使用方括号来截取字符串,如下实例: #!/usr/bin/py ...

  5. python字符串方法的简单使用

    学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...

  6. python字符串基础知识

    1.python字符串可以用"aaa",'aaa',"""aaa""这三种方式来表示 2.python中的转义字符串为" ...

  7. Python 字符串格式化

    Python 字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存 一 ...

  8. Python 字符串操作

    Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...

  9. 【C++实现python字符串函数库】strip、lstrip、rstrip方法

    [C++实现python字符串函数库]strip.lstrip.rstrip方法 这三个方法用于删除字符串首尾处指定的字符,默认删除空白符(包括'\n', '\r', '\t', ' '). s.st ...

随机推荐

  1. 【Java.Regex】用正则表达式查找Java文件里的字符串

    代码: import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; imp ...

  2. autoComplete TextView

    这个比较简单,只是将AutoCompleteTextView绑定一个ArrayAdapter就可以了. 界面布局: <?xml version="1.0" encoding= ...

  3. Spark ML 中 VectorIndexer, StringIndexer等用法(转载)

    VectorIndexer 主要作用:提高决策树或随机森林等ML方法的分类效果.VectorIndexer是对数据集特征向量中的类别(离散值)特征(index categorical features ...

  4. Nginx之https配置 - 运维笔记 (http->https强转)

    一.Nginx安装(略)安装的时候需要注意加上 --with-http_ssl_module,因为http_ssl_module不属于Nginx的基本模块.Nginx安装方法: # ./configu ...

  5. pytorch 计算图像数据集的均值和标准差

    在使用 torchvision.transforms进行数据处理时我们经常进行的操作是: transforms.Normalize((0.485,0.456,0.406), (0.229,0.224, ...

  6. pytorch Containers的Module部分

    参考:https://pytorch.org/docs/stable/nn.html Containers Module CLASS torch.nn.Module 所有神经网络模块的基类 你定义的模 ...

  7. pytorch求范数函数——torch.norm

    torch.norm(input, p='fro', dim=None, keepdim=False, out=None, dtype=None) 返回所给tensor的矩阵范数或向量范数 参数: i ...

  8. WPF ChromiumWebBrowser 网页背景透明

    网页中添加下面样式即可: <style> html, body { margin: 0px; height: %; width: %; overflow: hidden; backgrou ...

  9. 软件定义网络基础---SDN的核心思想

    一:SDN包含的核心思想:解耦,抽象,可编程 二:解耦 (一)SDN网络解耦思想 解耦是指将控制平面和数据平面进行分离,主要为了解决传统网络中控制平面和数据平面在物理上紧耦合导致的问题 控制平面和数据 ...

  10. 中标麒麟+Qt+mysql解决驱动无法加载的问题

    问题描述:都安装了Qt,Mysql之后,发现Qt始终不能连接Mysql 1.安装Qt 2.写程序直接连接QMysql 打印QSqlDatabase: * driver not loaded ,进入/h ...