zoukankan      html  css  js  c++  java
  • 变量

    变量
    当你不知到内容是什么的时候
    当一串内容很长时
    当发生重用的时候
    #: bool , str . dict. list.set, int   一些形式
    # strip,rstrip,lstrip  
    # s = '   hello  '  
    # print(s)
    # re = s.strip()
    # re2 = re.lstrip('h')     #:strip能去除多余的空格
    #:print(r2)       #:lstrip能去除字符串的开头和结尾的字母但不能去中间
                 
    # startswith,endswith
    # s = '   hello  '
    # re = s.strip()
    # print(re.startswith('h')) #:startswi方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False
    # print(s.endswith(' '))  #: endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False
    #:replace
    # s = 'hello alex,age is 18,myname is alex'
    # re = s.replace('alex','egon')     #:replace 具有取代的功能 
    # re = s.replace('alex','egon',1)   #:后面的数字的用途就是当一时改一个名字当数字是几位就改几个
    # print(re)
     
    #name = input('your name :')
    # print(name)    #:%s的作用就是格式化字符串吧name变量的内容替换到%s处打印
    #print('hello %s,age is %s'%(name,18))
    #print('hello {},age is {}'.format(name,18))  
    #print('hello {0},age is {1}'.format(name,18))
    #print('hello {name},age is {name}'.format(name=name,age=18))
     
    # split
    #:s = 'hello alex,age is 18,myname is alex'
    #:l = s.split() #=s.split(' ')
    #print(type(l))       #:把字符串变成列表的形式
    #:print(l)
    # l2 = s.split(',')     
    # print(type(l2))   #:查看其属性
    # print(l2)    
    #:t = tuple(l)    #:把列表的形式转化字符串
    #:s2 = ' '.join(t)
  • 相关阅读:
    Leetcode(11)-盛最多水的容器
    Leetcode(10)-正则表达式匹配
    Leetcode(104)-二叉树的最大深度
    Leetcode(106)-从中序与后序遍历序列构造二叉树
    Ubuntu多系统安装注意事项
    openstack安装、卸载与启动
    基于数据存储管理的带有头尾指针的双向链表创建实例
    JQuery右键菜单contextMenu插件
    jQuery判断当前浏览器类型
    后台获取登录的IP地址
  • 原文地址:https://www.cnblogs.com/nupecs/p/6773785.html
Copyright © 2011-2022 走看看