• 14、python基础


    一 标准数据类型
    1 整形和浮点形
    python2.*与python3.*关于整型的区别
    python2.*
    在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647

    在64位系统上,整数的位数为64位,取值范围为-2**63~2**63-1,即-9223372036854775808~9223372036854775807
    python3.*整形长度无限制
    查看方式:
    整形:   print(type(n))
    浮点形:  print(type(f))
     2 特点
       a.只能存放一个值
       b.一经定义,不可更改
       c.直接访问
    例:x=10
         print(id(x))
           x=11
          print(id(11))
    3字符串类型
    s=‘hello Word’ 
     
    二 字符串常用操作
    1 去掉空格:
    命令输入用户名:  name=input(‘username:   ’)
         去掉空格          name.strip()
    2 首字母大写
       x=‘hello’
       print(x.capitalize())
    3 所有字母大写
       x=‘hello’
       print(x.upper())
    4 居中显示
       x.‘hello’
       print(x.center(30,‘#’))
    5 统计某个字符的长度  空格也算字符
       x='hello love'
    print(x.count(l))      找到l位置
    print(x.count(‘1’,0,4))   #0 1 2 3 
    6 以()结尾
       x=‘hello’
       print(x.endswith())
    7 以()开头
       print(x.startswith())
    8 找相应索引的值
       x=‘hello’
       print(x.find())
    9 格式化字符串,和写入内容
       msg=‘Name:{},age:{},sex:{}’
       print(msg.format())
     10 查看某个字符的索引
       x=‘hello word’
       print(x.index() )
    11 显示处  判断结果为真
       x=‘123’
       print(x.isdigit())
    12 替换
       msg=‘hello alex’
       print(msg.replace(‘x’,‘X’))
    13 分割
       print(x.split())
  • 相关阅读:
    Mybatis Plus整合PageHelper分页的实现示例
    关于xlrd最新版本不支持.xlsx文件的解决办法
    mysql 错误解决大法 Specified key was too long; max key length is 767 bytes
    php连接redis
    flask通过request.path获取定义view函数的文件和行号
    使用bash内置命令complete来实现参数补全
    linux下对比两个文件夹下python文件的差异
    ssh登录后自动切换到原来的目录
    ssh &2>1 和重定向顺序问题
    wsl1(win10)中安装bochs
  • 原文地址:https://www.cnblogs.com/f1443526266/p/6959647.html
Copyright © 2020-2023  润新知