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())

转载于:https://www.cnblogs.com/f1443526266/p/6959647.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值