python基础知识(一)运算符-字符串详解
2018-09-19 22:17
861 查看
python基础知识
一:python简单介绍
a.python基础
-基础练习
-基础数据类型
-函数
-面向duix
b.网络编程
c.web编程
d.设计模式与算法
介绍:Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。
学习python课程,从基础知识到web项目开发以及爬虫系统项目代码开发实践课程记录。
二:本次python开发版本3.0+ ,python安装不进行演示,使用开发工具pycharm
三:执行python
变量:
字母
数字
下划线
不能使用数字开头,不能使用python关键字
字符串:
+ - * / % **
in not in 判断字符是否包含在其中
逻辑运算 : not and or
数据类型:
str:
一:python简单介绍
a.python基础
-基础练习
-基础数据类型
-函数
-面向duix
b.网络编程
c.web编程
d.设计模式与算法
介绍:Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。
学习python课程,从基础知识到web项目开发以及爬虫系统项目代码开发实践课程记录。
二:本次python开发版本3.0+ ,python安装不进行演示,使用开发工具pycharm
三:执行python
变量:
n1 = input("输入变量名") print(n1)#变量构成:
字母
数字
下划线
不能使用数字开头,不能使用python关键字
字符串:
name = "hello"运算符:
+ - * / % **
in not in 判断字符是否包含在其中
n1=9 n2=2 n3=n1+n2 n3=n1-n2 n3=n1*n2 n3=n1/n2 n3=n1%n2 n3=n1**n2循环:
死循环: while 1==1: print("ok") 循环遍历0到9 count=0 while count<10: print(ok) count += 1 1、输出1-100内的所以偶数 count=1 while count<=100: if(count%2!=0): pass else : print(count) count = count+1 2、求1-2+3-4+5...99的所有数的和 count=1 sum1=0 sum2=0 while count<100: if(count%2!=0): sum1=count+sum1 else : sum2=count+sum2 count = count+1 print(sum1-sum2)判断:
name = xixihaha if "xi" not in name: print("ok") else : print("error")布尔值: 真True 假 False
逻辑运算 : not and or
数据类型:
str:
test="alex" test.capitalize() 首字母大写,其他小写 test.casefold() 全部小写(牛) test.lower() 全部小写 test.upper() 全部大写 test.swapcase() 大小写转换 test.islower() 是否全是小写 test.isupper() 是否全是大写 test.center(20,"*")设置宽度,并将内容居中,20代指总长度,* 空白位置填充(一个字符) test.count("a") 计算字符中出现个数从0开始 test.count("a",5,7) 从第5位开始,到第7位结束 test.endswith("a") 以什么结尾,返回bool值 test.startswith('x')以什么开始,返回bool值 test.find("ex") 从开始到最后,找到第一个后获取其位置,未找到返回-1 test.find("ex",3,7) 从第3位开始,到底7位结束 格式化,将一个字符串的占位符替换为指定的值 test='i am {name},age {age}' test.format(name='alex',age='20') 格式化,将一个字符串的占位符替换为指定的值 test='i am {0},age {1}' test.format('alex',10) 格式化,传入的值{"name":"xie","age":23} test='i am {name},age {age}' test.format('alex',10) test.format_map({"name":"xie","age":23}) 识别\t ,\n 等标签 test="1234567\t89" test.expandtabs(2)空白位置数 join插入,将字符串的每一个元素安装指定分隔进行拼接 test="我就是我不一样的烟火" t='' t.join(test) #等同于 "".join(test) t='_s' test.join(t) 分隔 test="testegesjuisfsgwsfhwrweydasgstee" test.partition("s")#只能把字符串分隔为三份 test.rpartition() test="testegesjuisfsgwsfhwrweydasgstee" test.split("s")#全部找到进行分隔,无法保留分隔符“s” test.split("s",1) test.rsplit() test="alex" #索引,下标,获取字符串中的某一个字符 test[2] test[0:2]# 0<= val <2 test[0:-1] #切片 字符串一旦创建,不可以修改 一旦修改或者拼接,都会造成重新生成字符串 #替换 test="alexalexalex" test.replace("ex","bbb")#全部替换 test.replace("ex","bbb",1)#替换第一个 test.replace("ex","bbb",2)#替换前两个
相关文章推荐
- Python基础知识(七)--字符串详解
- 首学python基础知识(三)字符串与元祖
- python基础知识——字符串
- Python 基础知识之字符串处理
- 菜鸟的Python之路--基础知识(字符串的基本操作)
- 【C#基础知识】之常量、变量、枚举、字符串、转义符、运算符及表达式、try...catch等简单介绍
- python基础知识-元组和字符串
- python基础知识2(语法结构及字符串)
- Python学习第三章《字符串》(成为高手前必须知道的一些基础知识)
- Python 专题三 字符串的基础知识
- [Python学习] 专题三.字符串的基础知识
- python 基础知识(字符串 序列)(1)
- Python---基础知识、数值类型、字符串
- Python基础:Python数据类型详解之字典与字符串
- python基础知识-字符串的通用操作 分类: python 2012-11-29 19:57 252人阅读 评论(0) 收藏
- python 基础知识(字符串 序列)(1)
- Python 第一章 基础知识(9) 字符串
- Python中关于字符串对象的一些基础知识
- python基础知识-字符串的通用操作
- python 基础知识(字符串 序列)(2)