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

    >>>

  • 相关阅读:
    [Gym
    [Codeforces995C]Leaving the Bar 瞎搞
    [hdu3685]Rotational Painting 凸包 重心
    [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
    [hdu4667]Building Fence 计算几何 瞎瘠薄搞
    [hdu3934] 凸包 旋转卡壳
    [Codeforces50C]Happy Farm 5 凸包
    [Codeforces166B]Polygons 凸包
    mex(线段树+离散化)
    CF798D 糖果(思维题)
  • 原文地址:https://www.cnblogs.com/szy123618/p/4264452.html
Copyright © 2011-2022 走看看