一.数字型
1.整型 int
======================================基本使用======================================
1、用途 用来记录年龄/等级/年等整数相关 2、定义方式
age=18 # age=int(18) 3、常用操作+内置的方法
数学运算符&比较运算
======================================该类型总结====================================
存一个值 无序 不可变(1、可变:值变,id不变。可变==不可hash 2、不可变:值变,id就变。不可变==可hash) 2.浮点型 float
======================================基本使用======================================
1、用途 用来记录升高/体重/薪资等小数相关的数字 2、定义方式
salary=3.1 # salary=float(3.1) 3、常用操作+内置的方法
数学运算符&比较运算
======================================该类型总结====================================
存一个值 无序 不可变(1、可变:值变,id不变。可变==不可hash 2、不可变:值变,id就变。不可变==可hash) 二.字符串类型
======================================基本使用======================================
1、用途 用来记录姓名/性别/爱好等具有描述性质 2、定义方式
name='deng' hobbies='sleep' #name=str('deng') 3、常用操作+内置的方法
优先掌握的操作:
1、按索引取值(正向取+反向取) :只能取
msg='hello world'
res=msg[2]
res1=msg[0]
print(res)
print(res1) msg[0]='A' 2、切片(顾头不顾尾,步长)
msg='hello world'
res=msg[0:4:1] # 0 代表起始位置 4 代表终止位置,顾头不顾尾 1 代表步长
res=msg[0:6:2] # 此时步长为2
print(res) info='egon 18'
print(info[0:4]) 了解
msg='hello world'
print(msg[-1:-12:-1]) #-1 -2 -3 -4
print(msg[-1::-1]) #-1 -2 -3 -4
print(msg[::-1]) #-1 -2 -3 -4 3、长度len
print(len('hello 我是Enosh Deng')) 4、成员运算in和not in
msg='hello 我是Enosh Deng'
print('Enosh Deng' in msg)
print('no' in msg)
print('大家好' not in msg) 5、移除空白strip
name='*******wang******'
print(name.strip('*')) msg=' 你好 '
res=msg.strip()
print(res) msg='+-*&^%egon-=)^(#'
print(msg.strip('-+*&^%(#=')) name_inp=input('please input your name:').strip()
pwd_inp=input('please input your password:').strip()
if name_inp == 'egon' and pwd_inp == '123':
print('登陆成功')
else:
print('user or password error!!') 6、切分split
msg='deng:18:male'
res=msg.split(':')
print(res) bo_wen_508='deng|wang|cui|feng|cui'
res=bo_wen_508.split('|')
print(res) msg='deng:18:male'
print(msg.split(':',1))
print(msg.rsplit(':',1)) 7、循环
msg='hello world'
for item in msg:
print(item) 3.2需要掌握的操作 ****
1、strip,lstrip,rstrip
name='****deng****'
print(name.strip('*'))
print(name.rstrip('*'))
print(name.lstrip('*')) 2、lower,upper # lower 把字符串里的所有大写字母转换成小写, upper 把字符串里的所有字母转换成大写
name='Enosh Deng'
print(name.lower())
print(name.upper()) 3、startswith,endswith # startswith 是以什么为开头,判断真假! endswith 是以什么结尾,判断真假
msg='wang is dsb'
print(msg.startswith('wang'))
print(msg.endswith('sb')) 4、format的三种玩法
msg='my name is %s my age is %s' %('deng',18)
print(msg) msg='my name is {name} my age is {age}'.format(age=18,name='deng')
print(msg) 了解
msg='my name is {} my age is {}'.format('egon',18)
print(msg) 5、split,rsplit
info='egon:18:male'
print(info.split(':',1))
print(info.rsplit(':',1)) 6、join
7、replace 替换
msg='wang is dsb wang'
res=msg.replace('wang','cui',2)
print(res) 8、isdigit:当字符串是由纯数字组成时返回True
print('123123'.isdigit()) age_of_db=18
inp_age=input('>>: ').strip()
if inp_age.isdigit():
inp_age=int(inp_age)
print(inp_age == age_of_db)
else:
print('年龄必须是数字') 3.3 了解的操作
1、find,rfind,index,rindex,count
find: 查找子字符串在大字符串中的起始位置
msg='kevin is kevin xxxx sb'
print(msg.find('kevin'))
print(msg.index('kevin'))
print(msg.find('asdf'))
print(msg.index('asdf')) print(msg.rfind('kevin')) count:统计子字符串在大字符串中出现的次数
print('alex kevin alex kevin kevin'.count('kevin')) 2、center,ljust,rjust,zfill
username=input('>>>: ').strip()
print(username.center(50,'*')) print('egon'.ljust(50,'#'))
print('egon'.rjust(50,'#')) print('egon'.rjust(50,'0'))
print('egon'.zfill(50)) 3、captalize,swapcase,title
print('abdef adsfasdf'.capitalize())
print('AbC'.swapcase())
print('my name is egon'.title()) 4、is数字系列
print('123213'.isdigit())
print('Ⅳ'.isnumeric())
print('贰'.isnumeric())
5、is其他
name='My Nmae'
print(name.isalnum()) #字符串由字母或数字组成
print(name.isalpha()) #字符串只由字母组成 print(name.isidentifier())
print(name.islower())
print(name.isupper())
print(name.isspace())
print(name.istitle()) ======================================该类型总结====================================
存一个值 有序 不可变(1、可变:值变,id不变。可变==不可hash 2、不可变:值变,id就变。不可变==可hash)
x='a'
print(id(x))
x+='b'
# print(x)
print(id(x))

基本数据类型 int float str的更多相关文章

  1. python基础与数据类型(int, float, str, list)

    目录 python多版本共存 在cmd窗口进入不同版本的python环境 在pycharm中切换不同的版本 python语法之注释 python变量与常量 变量 变量的本质 变量的命名规范 常量 py ...

  2. 基本数据类型int,bool,str

    .基本数据类型(int,bool,str) 基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list 列表.用来存放大 ...

  3. day3------基本数据类型int, bool, str,list,tuple,dict

    基本数据类型(int, bool, str,list,tuple,dict) 一.python基本数据类型 1. int  整数. 主要用来进行数学运算 2. str  字符串, 可以保存少量数据并进 ...

  4. while和for循环的补充与数据类型的内置方法(int, float, str)

    目录 while与for循环的补充 while + else 死循环 while的嵌套 for补充 range函数 break与continue与else for循环的嵌套 数据类型的内置方法 int ...

  5. 基本数据对象(int,float,str)

    一.整型(int) # int对象初始化 x = 2 y = int(3) n = int("A3",12) # 运算符(+.-.*././/.%.**) ''' 相关的函数 '' ...

  6. python中的基本数据类型(int,bool,str)及字符串操作

    一. 基本数据类型概况 1.  int 整数,主要用来进行数学运算 2.  str 字符串,可以保存少量数据并进行相应的操作 3.  bool 布尔值,判断真假,True,False 4.  list ...

  7. 第三天-基本数据类型 int bool str

    # python基础数据类型 # 1. int 整数 # 2.str 字符串.不会用字符串保存大量的数据 # 3.bool 布尔值. True, False # 4.list 列表(重点) 存放大量的 ...

  8. python基本数据类型,int,bool,str

    一丶python基本数据类型 1.int 整数,主要用来进行数学运算. 2.str 字符串,可以保存少量数据并进行相应的操作 3.bool 判断真假.True.False 4.list 存储大量数据, ...

  9. go package 学习笔记 —— strconv(string与其他基本数据类型(int, float, bool)的转换)

    strconv实现了go中基本数据类型与string之间的转换. How to use in go go doc:https://godoc.org/strconv import "strc ...

随机推荐

  1. Android简单计时器

    本文利用ContextMenu(上下文菜单),Chronometer实现简单计数器. Main.xml: <?xml version="1.0" encoding=" ...

  2. ABP入门系列(17)——使用ABP集成的邮件系统发送邮件

    ABP中对邮件的封装主要集成在Abp.Net.Mail和Abp.Net.Mail.Smtp命名空间下,相应源码在此. #一.Abp集成的邮件模块是如何实现的 分析可以看出主要由以下几个核心类组成: E ...

  3. 老桂.net core系列课程

    为了支持"首届dnc开源峰会"(dncNew.com)顺利举办,本人<.net core系列课程>进行一波优惠,每个课程优惠在立即购买上方,领取现金券即可.课程地址为腾 ...

  4. Python 爬虫入门(二)——爬取妹子图

    Python 爬虫入门 听说你写代码没动力?本文就给你动力,爬取妹子图.如果这也没动力那就没救了. GitHub 地址: https://github.com/injetlee/Python/blob ...

  5. Android OpenSL ES 开发:Android OpenSL 录制 PCM 音频数据

    一.实现说明 OpenSL ES的录音要比播放简单一些,在创建好引擎后,再创建好录音接口基本就可以录音了.在这里我们做的是流式录音,所以需要用至少2个buffer来缓存录制好的PCM数据,这里我们可以 ...

  6. Centos7 Nginx开机启动

    1.简易安装nginx: ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf ...

  7. #Java学习之路——基础阶段(第六篇)

    我的学习阶段是跟着CZBK黑马的双源课程,学习目标以及博客是为了审查自己的学习情况,毕竟看一遍,敲一遍,和自己归纳总结一遍有着很大的区别,在此期间我会参杂Java疯狂讲义(第四版)里面的内容. 前言: ...

  8. [Swift]LeetCode38. 报数 | Count and Say

    The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...

  9. 浅谈React

    浅谈react react是什么?其官网给出了明确定义:A JavaScript library for building user interfaces,一个用于构建用户界面的JavaScript库 ...

  10. 用Flutter开发的跨平台项目,完美运行在Android和IOS上,Material简洁风格,包括启动页、引导页、注册、登录、首页、体系、公众号、导航、项目,还有漂亮的妹子图库,运行极度流畅,结构清晰,代码规范,值得拥有

    Flutter学习资源汇总持续更新中...... Flutter官方网站 Flutter中文网 wendux的Flutter实战 Flutter官方exampleflutter_gallery 阿里巴 ...