D10 基本数据类型(各种职业的技能分析) 主要为 int 和 str
在python中具有魔法的 职业 类型
召唤每种职业 在pychar 中 打出该职业的名称 按住Ctrl 光标在该职业名称上 点击就能看该职业的技能
1 数字 int
a = "123" (这个a只是字符串)
b = int(a) int 是把字符串变成数字类型
b = b + 1000 这样b就能算了
2 字符串 str
- text = "alex"
- v1 = text.capitalize()
- print (v1)
可以把首字母变成大写
- text = "Alex"
- v1 = text.casefold()
- print (v1)
- text = "Alex"
- v1 = text.lower()
- print (v1)
这个可以把首字母变成小写 第一个比较牛逼 很多未知的对应关系也能变小写
老子写不下去啦 啊啊啊啊 复制粘贴
.center
# 设置宽度,并将内容居中
# 20 代指总长度
# * 空白未知填充,一个字符,可有可无
# v = test.center(20,"中")
# print(v)
count
#去字符串中寻找,寻找子序列的出现次数
# test = "aLexalexr"
# v = test.count('ex')
# print(v)
# 5,6 是从代码的5 到6 这里面的代码找
# test = "aLexalexr"
# v = test.count('ex',5,6)
# print(v)
# 欠
# encode
# decode
# 以什么什么结尾
# 以什么什么开始
# test = "alex"
# v = test.endswith('ex')
# v = test.startswith('ex')
# print(v)
# 欠
# test = "12345678\t9"
# v = test.expandtabs(6)
# print(v,len(v))
# 从开始往后找,找到第一个之后,获取其未知
# > 或 >=
# test = "alexalex"
# 未找到 -1
# v = test.find('ex')
# print(v)
# index找不到,报错 忽略
# test = "alexalex"
# v = test.index('8')
# print(v)
format
# 格式化,将一个字符串中的占位符替换为指定的值
# test = 'i am {name}, age {a}'
# print(test)
# v = test.format(name='alex',a=19)
# print(v)
# test = 'i am {0}, age {1}'
# print(test)
# v = test.format('alex',19)
# print(v)
# 格式化,传入的值 {"name": 'alex', "a": 19}
# test = 'i am {name}, age {a}'
# v1 = test.format(name='df',a=10)
# v2 = test.format_map({"name": 'alex', "a": 19})
# 字符串中是否只包含 字母和数字
# test = "123"
# v = test.isalnum()
# print(v)
- # 12 是否是字母,汉子
- # test = "as2df"
- # v = test.isalpha()
- # print(v)
- # 13 当前输入是否是数字
- # test = "二" # 1,②
- # v1 = test.isdecimal()
- # v2 = test.isdigit()
- # v3 = test.isnumeric()
- # print(v1,v2,v3)
- # 14 是否存在不可显示的字符
- # \t 制表符
- # \n 换行
- # test = "oiuas\tdfkj"
- # v = test.isprintable()
- # print(v)
- # 15 判断是否全部是空格
- # test = ""
- # v = test.isspace()
- # print(v)
- # 16 判断是否是标题
- # test = "Return True if all cased characters in S are uppercase and there is"
- # v1 = test.istitle()
- # print(v1)
- # v2 = test.title()
- # print(v2)
- # v3 = v2.istitle()
- # print(v3)
- # 17 ***** 将字符串中的每一个元素按照指定分隔符进行拼接
- # test = "你是风儿我是沙"
- # print(test)
- # # t = ' '
- # v = "_".join(test)
- # print(v)
- # 18 判断是否全部是大小写 和 转换为大小写
- # test = "Alex"
- # v1 = test.islower()
- # v2 = test.lower()
- # print(v1, v2)
- # v1 = test.isupper()
- # v2 = test.upper()
- # print(v1,v2)
- # 19
- # 移除指定字符串
- # 有限最多匹配
- # test = "xa"
- # # v = test.lstrip('xa')
- # v = test.rstrip('9lexxexa')
- # # v = test.strip('xa')
- # print(v)
- # test.lstrip()
- # test.rstrip()
- # test.strip()
- # 去除左右空白
- # v = test.lstrip()
- # v = test.rstrip()
- # v = test.strip()
- # print(v)
- # print(test)
- # 去除\t \n
- # v = test.lstrip()
- # v = test.rstrip()
- # v = test.strip()
- # print(v)
- # 20 对应关系替换
- # test = "aeiou"
- # test1 = "12345"
- # v = "asidufkasd;fiuadkf;adfkjalsdjf"
- # m = str.maketrans("aeiou", "12345")
- # new_v = v.translate(m)
- # print(new_v)
- # 21 分割为三部分
- # test = "testasdsddfg"
- # v = test.partition('s')
- # print(v)
- # v = test.rpartition('s')
- # print(v)
- # 22 分割为指定个数
- # v = test.split('s',2)
- # print(v)
- # test.rsplit()
- # 23 分割,只能根据,true,false:是否保留换行
- # test = "asdfadfasdf\nasdfasdf\nadfasdf"
- # v = test.splitlines(False)
- # print(v)
- # 24 以xxx开头,以xx结尾
- # test = "backend 1.1.1.1"
- # v = test.startswith('a')
- # print(v)
- # test.endswith('a)
- # 25 大小写转换
- # test = "aLex"
- # v = test.swapcase()
- # print(v)
- # 26 字母,数字,下划线 : 标识符 def class
- # a = "def"
- # v = a.isidentifier()
- # print(v)
- # 27 将指定字符串替换为指定字符串
- # test = "alexalexalex"
- # v = test.replace("ex",'bbb')
- # print(v)
- # v = test.replace("ex",'bbb',2)
- # print(v)
- text = "abcd\tjjjjjj"
- print(text)
- #在上面的代码中 \t 是空一个大行
- text = "abcd\njjjjjj"
- print(text)
- #在上面的代码中 \n 是换行
上面的基本 魔法之要知道
join
- text = "alexer"
- v = "_".join(text)
- print(v)
把_ 插入text 中
upper
lower
strip
split
- test = "ljslhsjjjkh"
- v = test.split('s')
- print(v)
['lj', 'lh', 'jjjkh'] 除去 s 后 进行分割
find
replase
- text = "alexalexlalexalex"
- v = text.replace("le","",2)
- print(v)
a76xa76xlalexalex replase是替换字符串的字符串 字符串要记得打双引号 第一个是旧的 第二个是新的 第三个 是替换几个
下面的灰魔法
1 查找出字符串中的某一个字符
- text = "alex"
- v = text[3]
- print(v)
会打出 x
2 切片 给 字符串进行切片
- text = "alex"
- v = text[0:3]
- print(v)
第一个字母位置是0 第四个字母的位置是3 [0:3] 是大于等于0 到小于等于三
- text = "alex"
- v = text[0:-1]
- print(v)
也可以用这个表示 倒数第一位不取
3 len 是看该字符串有多少位
- text = "alexer"
- v = len(text)
- print(v)
会发现有6位
4 range 用来创造连续的数字
- v = range(0,100)
- for item in v :
- print(item)
会输出 从 0 到 99
也可以通过设置步长来创造等距的数字
- v = range(0,100,5)
- for item in v :
- print(item)
会输出 0 5 10 15 ...... 95
3 列表 list
4 元祖 tuple
5 字典 dict
6 布尔值 bool
- # a = "123a"
- # print(type(a),a)
- #
- # b = int(a)
- # print(type(b),b)
通过这个代码 就是 type 可以查看 此时的 变量是什么职业
D10 基本数据类型(各种职业的技能分析) 主要为 int 和 str的更多相关文章
- day3------基本数据类型int, bool, str,list,tuple,dict
基本数据类型(int, bool, str,list,tuple,dict) 一.python基本数据类型 1. int 整数. 主要用来进行数学运算 2. str 字符串, 可以保存少量数据并进 ...
- 基本数据类型int,bool,str
.基本数据类型(int,bool,str) 基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list 列表.用来存放大 ...
- Python基础学习Day3 数据类型的转换、int、str、bool、字符串的常用方法、for循环
一.数据类型的转换 常用的是:int 转str.str转int.int转bool 时 非零即为 True . # 数据类型之间转换 ***** # int <--> str str(i ...
- python基础与数据类型(int, float, str, list)
目录 python多版本共存 在cmd窗口进入不同版本的python环境 在pycharm中切换不同的版本 python语法之注释 python变量与常量 变量 变量的本质 变量的命名规范 常量 py ...
- .NET技能分析
知乎话题:如何面试.NET/ASP.NET工程师? No.1初级:1.对 C#(推荐) 或 VB 语言直至与 .NET 4 (目前为止)相匹配的版本,绝大多数特性熟悉并使用过2.通晓 HTTP 协议的 ...
- python-基本数据类型(int,bool,str)
一.python基本数据类型 1. int ==> 整数. 主要⽤用来进⾏行行数学运算 2. str ==> 字符串串, 可以保存少量量数据并进⾏行行相应的操作 3. bool==> ...
- 第十三节,基本数据类型,数字int字符串str
基本数据类型 数字 int 字符串 str 布尔值 bool 列表 list 元组 tuple 字典 dict 数据类型关系图 查看一个对象的类 如:如查看对象变量a是什么类 用到函 ...
- 基本数据类型,数字int字符串str
基本数据类型 数字 int 字符串 str 布尔值 bool 列表 list 字典 dict 元组 tuple(待续...) 整数 int - 创建 a = 123 a = int(123) - 转换 ...
- python中的基本数据类型(int,bool,str)及字符串操作
一. 基本数据类型概况 1. int 整数,主要用来进行数学运算 2. str 字符串,可以保存少量数据并进行相应的操作 3. bool 布尔值,判断真假,True,False 4. list ...
随机推荐
- POJ 3254:Corn Fields
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9295 Accepted: 4940 Descr ...
- POJ 1458:Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41957 Accepted: 16 ...
- 一百一十三、SAP的SCAT录屏操作,类似按键精灵可用于批量修改数据
一.输入事务代码SCAT,输入Z开头的程序名,点击左上角的新建图标 二.输入标题和模块名 三.保存为本地对象 四.包属性修改为CATT,然后保存 五.可以看到我们新建的一条内容,点击小铅笔修改 六.点 ...
- 087-把PHP数组中的元素按随机顺序重新排列shuffle
<?php $arr=array(3,23,'A','f','123','hello'); //定义一个数组 echo '排序之前的数组信息:<br>'; print_r($arr) ...
- Idea 打印GC
设置 Run ⇒ Edit Configurations ⇒ VM options 添加 -XX:+PrintGCDetails 运行程序后会在末尾打印GC信息 2019-11-02 13:07:47 ...
- 第二篇MTV模型、基本命令、简单配置
MTV模型.基本命令.简单配置 阅读目录(Content) MTV模型 基本命令 简单配置 MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Tem ...
- UVA - 1614 Hell on the Markets(奇怪的股市)(贪心)
题意:输入一个长度为n(n<=100000)的序列a,满足1<=ai<=i,要求确定每个数的正负号,使得所有数的总和为0. 分析: 1.若总和为0,则未加符号之前,所有数之和必为偶数 ...
- PHP的操作符与控制结构
一.操作符 操作符是用来对数组和变量进行某种操作运算的符号. 算术操作符 操作符 名称 示例 + 加 $a+$b - 减 $a-$b * 乘 $a*$b / 除 $a/$b % 取余 $a%$b 复 ...
- node.js爱心邮件
一.用的软件是VsCode:下载地址:https://code.visualstudio.com/ 二.用的是node.js完成:下载地址:http://nodejs.cn/download/ 无脑下 ...
- Monthly Expense(最大值最小化问题)
POJ-3273 ...