zoukankan      html  css  js  c++  java
  • Python之字符串小代码解析

    本篇只是拿一段代码来对python中的字符串的一些使用做解释,来让大家更加了解python

    Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32

    Type "copyright", "credits" or "license()" for more information.

    >>> pystr='python'    #定义变量pystr

    >>> iscool='is cool'      #定义变量iscool

    >>> pystr[0]       #获取pystr中0位置的字符

    'p'     #打印出来是P

    >>> pystr[:]    #[:]用于得到子字符串,不加限制就是全部

    'python'

    >>> pystr[2:5]     #获取位置在>=2,且<5的字符串内容.2<=字符串<5

    'tho'                         #输出结果

    >>> pystr[3:]              #3<=字符串<结束的字符串

    'hon'                #输出结果

    >>> pystr[1:3]      #1<=字符串<3

    'yt'

    >>> iscool[:2]              #0<=字符串<2

    'is'                

    >>> pystr[-1]                #[-1]获取最后一位的字符

    'n'

    >>> pystr+iscool                 #两个字符串的变量相加

    'pythonis cool'

    >>> pystr+' '+iscool       #两个字符串的变量相加,可以加上空格,以显得更加好看

    'python is cool'

    >>> pystr*2                      #两个字符串的变量相乘,就是字符串的重复输出

    'pythonpython'

    >>> '_'*80

    '________________________________________________________________________________'    #输出直线

    >>>

    >>> pystr='''python....is cool'''    #字符串可以用单引号,双引号或者三个单引号进行诠释

    >>> pystr

    'python....is cool'

    >>> print(pystr)     #打印出即输出字符串的变量

    python....is cool

    >>>

  • 相关阅读:
    为什么说http协议是无状态协议
    LR中获取当前系统时间的方法
    在Ubuntu Server下配置LAMP环境
    服务器性能监控
    性能测试:过程和重要指标
    LR中线程和进程的区别
    怎样获取Windows平台下SQL server性能计数器值
    用Excel创建SQL server性能报告
    Windows下部署Appium教程(Android App自动化测试框架搭建)
    性能测试指标
  • 原文地址:https://www.cnblogs.com/szy123618/p/4264452.html
Copyright © 2011-2022 走看看