1.开发工具

  python开发IDE: pycharm、eclipse

  # 专业版

  # 不要汉化

2.运算符

  结果是值

    算数运算

      a = 10 * 10

    赋值运算

      a = a + 1 a+=1

  结果是布尔值

    比较运算

      a = 1 > 5

    逻辑运算

      a = 1>6 or 1==1

    成员运算

      a = "蚊" in "郑建文"

3.基本数据类型

  a.数字  int ,所有的功能,都放在int里

    a1: int(object)   将字符串转换为数字

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#int
a = ""
print(type(a), a) b = int(a)
print(type(b), b) num = ""
v = int(num, base=16)
print(v)

    a2:bit_lenght(self)  当前数字的二进制,至少用n位表示

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#int
age = 5
r = age.bit_length()
print(r)

  b.字符串 str

    b1   capitalize()  首字母大写

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 首字母大写 capitalize()
test = "aLex"
v = test.capitalize()
print(v)

    b2   casefold() 所有变小写 包括特殊字符   lower() 所有英文字母变小写

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 所有变小写 casefold() lower()
test = "ShiQIanYu"
v1 = test.casefold()
print(v1)
v2 = test.lower()
print(v2)

    b3  center(width, fillchar=None)  width 代表总长度   fillchar 空白未知填充,一个字符,可有可无   两边填充

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = 'sqy'
v = test.center(20,"*")
print(v)

      b31  ljust(width, fillchar=None)   width 代表总长度   fillchar 空白未知填充,一个字符,可有可无  右边填充

        

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "alex"
v = test.ljust(20,"*")
print(v)

      b32  rjust(width, fillchar=None)   width 代表总长度   fillchar 空白未知填充,一个字符,可有可无  左边填充

        

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "alex"
v = test.rjust(20,"*")
print(v)

      b33  zfill(width) idth 代表总长度 默认左边填充0

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "alex"
v = test.zfill(20)
print(v)

      

        

    b4  count(sub, start=None, end=None)  去字符串中寻找,寻找子序列的出现次数     左闭右开

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "aLexalexr"
v = test.count('ex')
print(v) test = "aLexalexr"
v = test.count('ex',6,8)
print(v)

    b5  以什么什么结尾 endswith(suffix, start=None, end=None)

       以什么什么开始startswith(suffix, start=None, end=None)

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 以什么什么结尾
# 以什么什么开始
test = "alex"
v = test.endswith('ex')
print(v)
v = test.startswith('alex')
print(v)

    b6  find(sub, start=None, end=None)   从开始往后找,找到第一个之后,获取其位置  找不到返回-1

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 从开始往后找,找到第一个之后,获取其未知
# > 或 >=
test = "alexalex"
# 未找到 -1
v = test.find('ex')
print(v)

    b7   index(sub, start=None, end=None)  找不到,报错   忽略

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "alexalex"
v = test.index('')
print(v)

    b8  format(*args, **kwargs) 格式化,将一个字符串中的占位符替换为指定的值

      

 # -*- coding:utf8 -*-
#str
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)

    b9  format_map(mapping)  格式化,传入的值 {"name": 'alex', "a": 19}  字典的形式

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 格式化,传入的值 {"name": 'alex', "a": 19}
test = 'i am {name}, age {a}'
v1 = test.format(name='df',a=10)
print(v1)
v2 = test.format_map({"name": 'alex', "a": 19})
print(v2)

    b10  isalnum()  字符串中是否只包含 字母和数字  汉字

    

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
# 字符串中是否只包含 字母和数字 汉字
test = "as123对的?"
v = test.isalnum()
print(v)

       b10a  isalpha()  是否是字母,汉字

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "as对的df"
v = test.isalpha()
print(v)

      b10b  isdecimal()<isdigit()<isnumeric()  当前输入是否是数字  判断的数字种类依次为

        

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "②" # 1,② ,二
v1 = test.isdecimal()
v2 = test.isdigit()
v3 = test.isnumeric()
print(v1,v2,v3)

    

    b11  expandtabs(width)   断句   找到制表符/t  制表符两边的内容间隔的距离为width

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "username\temail\tpassword\nlaiying\tying@q.com\t123\nlaiying\tying@q.com\t123\nlaiying\tying@q.com\t123"
v = test.expandtabs(20)
print(v)

   b12  isprintable()  是否存在不可显示的字符  \t 制表符  \n换行符

    

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = "oiuas\tdfkj"
v = test.isprintable()
print(v)

    b13  isspace()  判断是否全部是空格

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
#str
test = ""
v = test.isspace()
print(v)

    b14  istitle()  判断是否是标题   title() 转换为标题

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
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)

    b15  join(iterable)  字符串中的每一个元素按照指定分隔符进行拼接

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "你是风儿我是沙"
print(test)
# t = ' '
v = "_".join(test)
print(v)

    b16  islower()  isupper()  判断是否全部是小大写  lower()  upper()  转换为小大写

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "Alex"
v1 = test.islower()
v2 = test.lower()
print(v1, v2) v1 = test.isupper()
v2 = test.upper()
print(v1,v2)

    b17  strip(str)  去除两边str  lstrip(str)  去除左边str  rstrip(str)  去除右边str

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
# 移除指定字符串
# 有限最多匹配
test = " \nxa "
#v = test.lstrip('xa')
#v = test.rstrip('9lexxexa')
#v = test.strip('xa')
#print(v) #test.lstrip()
#test.rstrip()
#test.strip()
#print(test)
# 去除左右空白
# 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)

    b18   maketrans(src,dest)   src源内容  dest 目标内容  对应关系替换

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "aeiou"
test1 = "" v = "asidufkasd;fiuadkf;adfkjalsdjf"
m = str.maketrans("aeiou", "")
new_v = v.translate(m)
print(new_v)

    b19  分割为三部分 分割内容包含str  partition(str) 从左边开始分割   rpartition(str)  从右边开始分割   分割为指定个数不包含str  split(str,num) str 分割内容  num 分割    splitlines(boo)  只能根据,true,false:是否保留换行

        

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "testasdsddfg"
# v = test.partition('s')
# print(v)
# v = test.rpartition('s')
# print(v) v = test.split('s',1)
print(v)
test.rsplit() test = "asdfadfasdf\nasdfasdf\nadfasdf"
v = test.splitlines(True)
print(v)

    

      

     b20  swapcase()  大小写转换  小写转大写

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "aLex"
v = test.swapcase()
print(v)

    b21  字母,数字,下划线 : 标识符 def  class

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
a = "d2哈好的f"
v = a.isidentifier()
print(v)

    b22  将指定字符串替换为指定字符串 replace(self, old, new, count=None)

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "alexalexalex"
v = test.replace("ex",'bbb')
print(v)
v = test.replace("ex",'bbb',3)
print(v)

    b23  ###################### 7个基本魔法 ######################

      # join       # '_'.join("asdfasdf")  # split  # find  # strip  # upper  # lower  # replace

    b24  ###################### 4个灰魔法 ######################

      B241  一、for循环

        

 #!/usr/bin/env python
# -*- coding:utf8 -*-
# test = "郑建文妹子有种冲我来"
# for 变量名 in 字符串:
# 变量名
# break
# continue # index = 0
# while index < len(test):
# v = test[index]
# print(v)
#
# index += 1
# print('=======') # for zjw in test:
# print(zjw) test = "郑建文妹子有种冲我来"
# for item in test:
# print(item)
# break for item in test:
continue
print(item)

    B242  索引,下标,获取字符串中的某一个字符

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "妹子有种冲我来"
v = test[3]
print(v)

    B243  三、切片

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "妹子有种冲我来"
v = test[0:1] # 0=< <1
print(v)

    B244  四、获取长度

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
test = "妹子有种冲我来"
# Python3: len获取当前字符串中由几个字符组成
v = len(test)
print(v)

      # 注意:  # len("asdf")  # for循环  # 索引  # 切片

    B245  五、获取连续或不连续的数字

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
# Python2中直接创建在内容中
# python3中只有for循环时,才一个一个创建
r1 = range(10)
r2 = range(1,10)
r3 = range(1,10,2)
# 帮助创建连续的数字,通过设置步长来指定不连续
v = range(0, 100, 5) for item in r3:
print(item)

    b25      ###################### 1个深灰魔法 ######################

       # 字符串一旦创建,不可修改  # 一旦修改或者拼接,都会造成重新生成字符串

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
name = "shiqianyu"
age = ""
info = name + age
print(info)

    b26  练习题  根据用户输入的值,输出每一个字符以及当前字符所在的索引位置 #####

      

 #!/usr/bin/env python
# -*- coding:utf8 -*-
# 根据用户输入的值,输出每一个字符以及当前字符所在的索引位置
usr = input("请输入值:\n")
index = 0
while index < len(usr):
print(index,usr[index])
index += 1

 

 #!/usr/bin/env python
# -*- coding:utf8 -*-
# 根据用户输入的值,输出每一个字符以及当前字符所在的索引位置
# test = input(">>>:\n")
# print(test) # test = qwe test[0] test[1]
# l = len(test) # l = 3
# print(l)
#
# r = range(0,l) # 0,3
# for item in r:
# print(item, test[item]) # 0 q,1 w,2 e test = input(">>>\n")
for item in range(0, len(test)):
print(item, test[item])

    

# 制作表格
# 循环提示用户输入:用户名、密码、邮箱 (要求用户输入的长度不超过 20 个字符,如果超过则只有前 20 个字符有效)
# 如果用户输入 q 或 Q 表示不再继续输入,将用户输入的内容以表格形式大隐

 

 s = ""
i = 1
while i<3:
name = input("请输入用户名:\t\n")
pwd = input("请输入密码:\t\n")
email = input("请输入邮箱:\t\n") template = "{0}\t{1}\t{2}\n"
v = template.format(name,pwd,email) s = s + v
i += 1
print(s.expandtabs(20))

 

      

  c  列表 list

  d 元组 tuple

  e 字典 dict

  f 布尔值 bool

  

      

      

day10-11-python基础之字符串的更多相关文章

  1. Python基础数据类型-字符串(string)

    Python基础数据类型-字符串(string) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客使用的是Python3.6版本,以及以后分享的每一篇都是Python3.x版 ...

  2. Python基础(二) —— 字符串、列表、字典等常用操作

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 二.三元运算 result = 值1 if 条件 else 值2 如果条件为真:result = 值1如果条件为 ...

  3. python基础、字符串和if条件语句,while循环,跳出循环、结束循环

    一:Python基础 1.文件后缀名: .py 2.Python2中读中文要在文件头写: -*-coding:utf8-*- 3.input用法      n为变量,代指某一变化的值 n = inpu ...

  4. python基础之字符串基本功能

    终于还是踏上了Python的不归路,不知道能不能走的完. 先总结一下今天学习的字符串的各个功能吧:只写了部分用的比较多的. 1.capitalize: 字符串首字母大写 >>> na ...

  5. Python基础__字符串拼接、格式化输出与复制

    上一节介绍了序列的一些基本操作类型,这一节针对字符串的拼接.格式化输出以及复制的等做做详细介绍.一. 字符串的拼接 a = 'I', b = 'love', c = 'Python'. 我们的目的是: ...

  6. python基础类型—字符串

    字符串str 用引号引起开的就是字符串(单引号,双引号,多引号) 1.字符串的索引与切片. 索引即下标,就是字符串组成的元素从第一个开始,初始索引为0以此类推. a = 'ABCDEFGHIJK' p ...

  7. Python基础二字符串和变量

    了解一下Python中的字符串和变量,和Java,c还是有点区别的,别的不多说,上今天学习的代码 Python中没有自增自减这一项,在转义字符那一块,\n,\r\n都是表示回车,但是对于不同的操作系统 ...

  8. Python基础之字符串和编码

    字符串和编码 字符串也是一种数据类型,但是字符串比较特殊的是还有个编码问题. 因为计算机自能处理数字,如果徐娅处理文本,就必须先把文本转换为数字才能处理,最早的计算机子设计时候采用8个比特(bit)作 ...

  9. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  10. Python开发【第一篇】Python基础之字符串格式化

    字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-310 ...

随机推荐

  1. [LeetCode] Domino and Tromino Tiling 多米诺和三格骨牌

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  2. JS-函数的构造函数Function

    ##  在js中使用Function可以实例化函数对象,也就是说在js中函数和普通对象一样. 函数在Js中是比较特殊的,拥有很多功能. 1,函数是对象,就可以使用对象的动态特性. 2,函数是对象,就有 ...

  3. JS-原型的某些概念

    prototype:构造函数拥有一个对象,称为构造函数的原型属性,可以通过 构造函数prototype进行访问. __proto__: 构造函数所创造出的实例对象,可通过该属性访问原型对象. cons ...

  4. 记录C#中的扩展方法

    C#中的扩展方法. 系统自带的类型,我们无法去修改: 修改源代码需要较大的精力,而且可能会带来错误: 我们只是需要一个或者较少的几个方法,修改源代码费时费力: 被扩展的类是sealed的,不能被继承: ...

  5. ListView添加图片文字项

    1)listview 控件 结合 imagelist 控件 实现类似效果. 2)添加 imagelist 控件 images 属性,点击后面的... 添加相应图片. 3)点listview,查看其属性 ...

  6. 第八周 ip通信基础回顾

    安装完华三模拟器,拖多台设备到工作区,全部启动及配置,建立好拓扑图,之后启动命令行终端. 配置登录用户,口令的指令有: <H3C>                       //用户直行 ...

  7. springboot新增swagger2配置

    转自http://www.cnblogs.com/jtlgb/p/8532433.html SpringBoot整合Swagger2 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人 ...

  8. Opencv-Python No module named 'cv2.cv2'

    关于 No module named 'cv2.cv2'等其他一些问题,一般都是版本不兼容的问题,重装即可. pip uninstall opencv-python 然后 pip install op ...

  9. UML与软件建模:第一次作业(UML用例图绘制)

    uml第一次作业: 用例图是什么? 用例图我感觉就是把网站中各个用户的动作分解一下,再用rational rose软件把图画出来. 画例图主要分为三个步骤:a 确定系统角色  b 确定用例  c 对用 ...

  10. cacheline基本理论

    一.cacheline 1.cache:解决cpu频率与内存访问之间速度差距越来越大的问题 2.cacheline:cpu cache的最小单位,主流为64B 3.指导:访问数组数据在同一个cache ...