一.数字型
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. Springboot关于脚本脚本启动的项目:

    #!/bin/bash if [ -f ~/.bash_profile ];then  . ~/.bash_profilefi JAVA_HOME=/usr/local/usr_software/jd ...

  2. 如何在微信小程序定义全局变量、全局函数、如何实现 函数复用 模块化开发等问题详解

    1.如何定义全局数据 在app.js的App({})中定义的数据或函数都是全局的,在页面中可以通过var app = getApp();  app.function/key的方式调用,不过我们没有必要 ...

  3. Node.js(day6)

    初始化准备工作 初始化目录 nmp init -y 安装基本的第三方插件 express npm install express --save art-template npm install art ...

  4. [Swift]LeetCode1024. 视频拼接 | Video Stitching

    You are given a series of video clips from a sporting event that lasted T seconds.  These video clip ...

  5. 机器学习入门17 - 嵌套 (Embedding)

    原文链接:https://developers.google.com/machine-learning/crash-course/embeddings/ 嵌套是一种相对低维的空间,可以将高维矢量映射到 ...

  6. Jedis与Luttuce区别

    如果你在网上搜索Redis 的Java客户端,你会发现,大多数文献介绍的都是 Jedis. 不可否认,Jedis是一个优秀的基于Java语言的Redis客户端. 但是,其不足也很明显:Jedis在实现 ...

  7. ThinkPHP 数据库操作(四) : 聚合查询、时间查询、高级查询

    聚合查询 在应用中我们经常会用到一些统计数据,例如当前所有(或者满足某些条件)的用户数.所有用户的最大积分.用户的平均成绩等等,ThinkPHP为这些统计操作提供了一系列的内置方法,包括: 用法示例: ...

  8. MySQL系列--2.常用的命令

    1 .创建数据库 #语法: CREATE DATABASE dbName; #创建数据库rms create database rms; 2.切换数据库 #选择数据库 USE dbName; #选择数 ...

  9. Jvm垃圾回收器(算法篇)

    在<Jvm垃圾回收器(基础篇)>中我们主要学习了判断对象是否存活还是死亡?两种基础的垃圾回收算法:引用计数法.可达性分析算法.以及Java引用的4种分类:强引用.软引用.弱引用.虚引用.和 ...

  10. leetcode — validate-binary-search-tree

    import apple.laf.JRSUIUtils; /** * Source : https://oj.leetcode.com/problems/validate-binary-search- ...