zoukankan      html  css  js  c++  java
  • python 一些数据类型的方法

    
    
    #! /usr/bin/env python
    #! -*- cording:utf-8 -*-

    temp="alex"

    # chengbao=type(temp)
    #找出当前数据的类型
    # print (chengbao)
    # temp.upper()
    # #变大写
    # temp.lower()
    # #变小写
    #输出str

    #print (help(type(temp)))

    #先找到某个对象的类型,再用help列出其内部所有的方法
    n1=123
    n2=234

    #bb=type(n1)
    print(n1.__add__(n2))

    a1="alex"
    ret=a1.capitalize()
    #首字母变大写
    ret1=a1.center(20,'*')
    #字符串长度设置为20,用*填充
    print(ret1)

    a2="alex is alph"

    ret=a2.count('a',0,10)
    #0-10个字符位置范围内计数
    #计算子序列的个数
    print(ret)

    temp="hello"
    print(temp.endswith('x',0,2))
    #判断结尾字符是否为x,0-2位置

    content="hello 9999"
    print(content)
    print(content.expandtabs(20))
    #中间增加空格

    # 代表type键 制表符 换行符
    s="alex hello"
    print(s.find("l"))

    s="hello{0},age{1}"

    print(s)
    new1=s.format("alex",19)
    print(new1)

    #{0,}{1}表示占位符,把alex传入{0}19传入{1}

    #join,连接列表
    li=["alex","eric"]

    #元组也支持
    li2=("alex","eric")
    s="*".join(li)
    #用_,*连接两个字符串
    print(s)

    a=" alex "
    news=s.lstrip()#左空格
    news2=s.rstrip()#右空格
    print(news)

    #去掉字符左右空格

    # s="alex SB alex"
    #
    # ret=s.partition('SB')
    #
    # print(ret)

    #分割字符,元组类型

    s="alex SB alex"
    ret=s.replace("al","bb",1)
    print(ret)
    #替换字符,al为bb,1,为从左往右查找第一个替换

    s="alexalex"
    ret=s.split("e")
    print(ret)

    #分割
    s="aleX"
    print(s.swapcase())

    #大写变小写,小写变大写

    s="alex"

    #索引
    print(s[0])
    #s里的第一个字符
    ret=len(s)
    #数S的字符数
    print(ret)
    #0<= 0,1 <2
    print(s[0:2])

    #循环输出元组
    s="ddddddddddereregieutrieoreiore"
    # start=0
    # while start<len(s):
    # temp=s[start]
    # start+=1
    # print(temp)
    #
    for item in s:
    print(item)

    #循环输出
     
  • 相关阅读:
    Linux磁盘分区、挂载
    crond任务调度
    Form组件使用
    Django路由系统
    Django中模板简单使用
    ORM常用操作
    IO多路复用
    vscode必装插件
    Flask-RESTful扩展
    flask-caching
  • 原文地址:https://www.cnblogs.com/aqiuarcadia/p/7294314.html
Copyright © 2011-2022 走看看