python学习1.0

# !/usr/bin/env python
# _*_ coding=utf8 _ * _

# 布尔值 True False
# 算数运算 + - * / // % == **
# 赋值运算 += -= *= /= %= .....
# 比较运算 > < >= <=
# 成员运算 in not in
# 逻辑运算 and or 没有优先级,建议使用(),如果没有,运算从前往后走 逻辑判断

#基本数据类型 :数字 字符串 布尔值 (列表 元祖 字典)
#不同的数据类型有各自的特殊运算命令
# 数字 int 字符串 str 列表 list 元祖 tupie 字典 dict 布尔 bool

# int(str,base=int) 将字符串转换成数字,base可以规定进制类型
# .bit_length() 当前数字的二进制,至少用n位表示


# .capitalize() 首字母大写(覆盖)
# .casefold() 所有字母变小写(casefold可以把很多未知变小写)
# .lower() .upper() .title() 所有字母变小写或大写或标题支持is判断操作(覆盖)**************************************************************
# .swapcase() 大小写转换(互补)


# .count(str,int,int) 查找字符串某段区间内字符个数
# .find(str,int,int) .index 从前往后找,找到第一个,获取其位置(如果找不到find显示-1,index报错)***************************************


# .endswith(str) .startswith 以什么字符开头和结尾,判断真值
# .isalnum() 判断字符串是否只包含字母或数字
# .isalpha() 判断是否只包含字母或汉字
# .isspace() 判断是否全部是空格
# .isdecimal() .isdigit(支持特殊序号) .isnumeric(支持中文) 判断是否只包含数字
# .isidentifier() 判断字母,数字,下划线:标识符
# .isprintable() 是否存在不可显示字符 \n \t


# .center(int,none or str) .ljust .rjust 设置字符串宽度,并将内容填充在中间或左右,默认空格补位
# .strip(str) 去除左右空白,\t,\n,或指定字符,(按元素级去除从两边判断直到遇到没有相同元素时停止)********************************

# .join() 将字符串中的每个元素按指定分割符隔离*************************************
# .partition("o") .rpartition 分割一次,包含分割元素
# .split("o",3) .rsplit 分割n次,不包含分割元素***************************************
# .splitlines(True or False) #根据\n分割,可以显示是否保留换行符
# expandtabs(int) 断句,搭配\t,\n使用,(做表格)*******************
# .format() .format_map 占位符(格式化)**************
# .replace("old","new",7) 替换**************
###a = 'd3f43f34f43342'
###b = str.maketrans("12345","abcde") 元素级一一对应替换
###c= a.translate(b)
# a[0] 索引
#a[2:9] 切片
# len() 统计字符串字符数“\”表示转意时,不占字符位
# for b in a: 迭代
# range(0,100,5) 列表*********************************
# .encode() 编码
# .decode() 解码

猜你喜欢

转载自www.cnblogs.com/brzp97/p/9785758.html
今日推荐