当前位置: 首页 > news >正文

对整型、浮点型、字符串类型的认识

整型(int)
基本认识:
用途:记录年龄、等级、号码等
定义方式:age=18
类型总结:存一个值且为不可变类型
浮点型(float)
用途:记录身高、体重、薪资
定义方式:salary=3.1
类型总结:存一个值且为不可变类型
字符串类型(str)
一:基本使用

1 用途:记录描述性的状态,如人的名字,地址,性别

2 定义方式:在'',"",""""""内包含一系列的字符
msg='hello'#相当于msg=str('hello')
a1=str(1)
a2=str([1,2,3])
print(type(a1),type(a2))
优先掌握的操作:
1、按索引取值(正向取+反向取) :只能取
msg='hello world'
print(msg[4])
print(msg[-1])
2、切片(顾头不顾尾,步长)
msg='hello world'#就是从一个大的字符串中切除一个全新的子字符串
print(msg[0:5])
print(msg)
print(msg[::-1])
print(msg[0:5:2])
print(msg[5:0:-1])
print(msg[-1::-1])

3、长度len1
msg = 'hello world'
print(len(msg))
4、成员运算in和not in是为了判断一个子字符串是否在一个大字符串中
msg = 'hello world'
print('hello'in'hello world')
print('h'in'hello world')
print('h'not in'hello world')
5、移除空白strip是去掉字符串左右两边的字符strip,不管中间的
asd=' * liu - / + '
print(asd.strip())
print(asd.strip(' * - / +'))
age=input('>>').strip()
if age=='liu':
print('hello')
6、切分:针对按照某种分隔符组织的字符串,可以用split将其切分成列表,进而进行取值
msg='hello|world'
x=msg.split('|')
print(x)
s,d=msg.split('|')
7、循环
msg='hello'
for i in msg:
print(i)
补充:1.strip,lstrip,rstrip
msg='****hello****'
print(msg.strip("*"))
print(msg.lstrip("*"))
print(msg.rstrip("*"))
2.lower,upper
msg='ADSxc'
print(msg.lower())
print(msg.upper())
3.startswith,endswith
msg='alex is dsb'
print(msg.startswith('alex'))
print(msg.endswith('d'))
print(msg.endswith('sb'))
4.format的三种玩法
print('my name is %s my age is %s' %('egon',18))
print('my name is {name} my age is {age}'.format(name='egon',age=18))
5.split,rsplit
print(('my |name|is').rsplit('|',1))
print(('my |name|is').split('|',1))
6.join
msg='my|name|is'
print(msg.rsplit("|"))
msg1='|'.join(msg.rsplit('|'))
print(msg)
7、replace
msg='alex say i have one tesla,alex is alex hahaha'
print(msg.replace('alex','sb'))
print(msg)
8、isdigit # 判断字符串中包含的是否为纯数字
print('10.1'.isdigit())
3 常用操作+内置的方法
二:该类型总结
1 只能存一个值且存的值是任意类型。


2 有序

3 不可变

 

不可变:值变,id就变。不可变==可hash

 

转载于:https://www.cnblogs.com/ageliu/p/9360420.html

相关文章:

  • DNS域名解析中A、AAAA、CNAME、MX、NS、TXT、SRV、SOA、PTR各项记录的作用
  • 交互式数据处理
  • 在项目中直接执行里面的文件
  • Redis监听回调
  • P1064 金明的预算方案
  • windows C:\documents and settings拒绝访问
  • 枚举+最短路 poj1062
  • Python——requests模块
  • GitLab领取任务+建立分支+本地修改+上传分支+合并分支详细步骤
  • Win10应用商店缓存信息多如何去清理?
  • [数位DP][CQOI2016]手机号码(附数位DP模板)
  • SpringBoot | 第十一章:Redis的集成和简单使用
  • 搭建简单的单个Mybatis框架
  • Day 14:FileInputStream、FileOutputStream
  • 导出csv xls文件数字会自动变科学计数法的解决方式
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • Angular 2 DI - IoC DI - 1
  • EOS是什么
  • Java IO学习笔记一
  • Java读取Properties文件的六种方法
  • JS学习笔记——闭包
  • LeetCode541. Reverse String II -- 按步长反转字符串
  • Logstash 参考指南(目录)
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • Python 使用 Tornado 框架实现 WebHook 自动部署 Git 项目
  • React16时代,该用什么姿势写 React ?
  • unity如何实现一个固定宽度的orthagraphic相机
  • weex踩坑之旅第一弹 ~ 搭建具有入口文件的weex脚手架
  • 彻底搞懂浏览器Event-loop
  • 动态规划入门(以爬楼梯为例)
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 实战|智能家居行业移动应用性能分析
  • 走向全栈之MongoDB的使用
  • MiKTeX could not find the script engine ‘perl.exe‘ which is required to execute ‘latexmk‘.
  • gunicorn工作原理
  • Mac 上flink的安装与启动
  • 昨天1024程序员节,我故意写了个死循环~
  • ​低代码平台的核心价值与优势
  • ​总结MySQL 的一些知识点:MySQL 选择数据库​
  • # 安徽锐锋科技IDMS系统简介
  • #if #elif #endif
  • #QT(一种朴素的计算器实现方法)
  • #QT(智能家居界面-界面切换)
  • #常见电池型号介绍 常见电池尺寸是多少【详解】
  • #单片机(TB6600驱动42步进电机)
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • %check_box% in rails :coditions={:has_many , :through}
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (二十五)admin-boot项目之集成消息队列Rabbitmq
  • (一)eclipse Dynamic web project 工程目录以及文件路径问题
  • (原)本想说脏话,奈何已放下
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (转)GCC在C语言中内嵌汇编 asm __volatile__
  • (转)利用PHP的debug_backtrace函数,实现PHP文件权限管理、动态加载 【反射】...