python基础知识(一)运算符-字符串详解

python基础知识
python

    

一:python简单介绍web

a.python基础算法

-基础练习编程

-基础数据类型设计模式

-函数api

-面向duix网络

b.网络编程ide

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-100内的因此偶数
    count=1
    while count<=100:
        if(count%2!=0):
            pass
        else :
            print(count)
        count = count+1
二、求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)#替换前两个
相关文章
相关标签/搜索