Python第二天

Python用处:

运维,测试

Python全栈(前端、后端)

Java+Python  人工智能 爬虫工程师

数据分析  算法工程师 cv nlp rs 系统 

大数据 Hadoop spark

...

 elif switch score = 5 if score >=90 and score <=100:

print('你的考试等级为A')

 elif score >=80 and score <90:

print('你的考试等级为B')

 elif score >=70 and score <80:

print ('你的考试等级为C')

elif score >=60 and score <70:

 print('你的等级考试为D')

elif score <60: print('你的等级考试为E')

Python 中的循环 #先介绍for循环

格式: for 临时变量 in 可替代对象:

            循环体

...

name = 'neusoft' for x in name:

print(x) if x=='s':

print ('哈哈')

循环次数哪里去了?

range(起始位置,终止位置,步长)可以写循环次数 #起始位置省略默认为0,步长省略为1

范围是左闭右开

...

给道歉一百次 for i in range (1,101,2):

print ('对不起,这是',i,'次道歉')

...

这个X是什么?

x是临时变量,不用提前声明,python自动创建

常用数据类型

数字、列表、字符串、字典、元组、集合

 生成一个[0,1,2.....20]的列表

可以使用循环来创建

创建一个空列表 list1=[]

使用循环不停的append

...

for i in range(21):

list1.append(i) print(list1) for hero in herolist:

print (hero) #len()

可以检测对象的元素个数

for i in range(4):

for i in (len(herolist))

print(herolist[i]) if herolist[i]=='技术':

print('恭喜你选中了') else: print('没有隐藏')

...

Python制作进度条

安装tqdm库

...

pip install 库的名称

 terminal---pip---pip install tqdm

导入 tqdm from tqdm import tqdm import time mylist = [] for i in range (1):

mylist.append(i)

遍历mylist for x in tqdm (mylist):

time.sleep(0.1)

...

字符串

表示''""

...

要注意的是 name = 'k"o"be' print(name)

访问 print(name[2])

 修改 name="x" print(name) name="kobe" print(name)

常用操作 price="$9.9"

 字符串的替换 price=price.replace("$","")

print (price)

 价格涨十倍 new_price=float(price)*10 print(new_price)

...

strip 去空格操作  写一个价值一亿的AI代码

...

while Ture:

 seg=input ('')

seg .replace('吗')

print(seg) #strip 去空格操作

 name=' neuedu '

print(len(name))

name=name.strip()

name=name.strip()

print(len(name))

join 将列表变成字符串 li=['1','2','3'] disk_path =['1233','qq','w','q']

path='\\'.join(disk_path) print(path)

...

元组 tuple() list() int()str()

创建 元组和列表很相似,只不过不能修改 a=(1,'1',['']) print(a) print(type(a))

#访问 print(a[1]) #a[2]=6 #元组的用处

1.写保护(安全),Python内置函数返回的类型都是元素

2.相对列表来讲,元组更节省空间,效率更高 掌握

1.拥有一个元素的元组 b=(100,) print(type(b)) #我们经常使用的组合方式: list2=[('a',22),('b',3),('c',5)]

字典 创建字典

info={'name':'qq','age':18,'gender':'female'} print(type(info))

访问字典 通过建访问值 print(info['name'])

 访问不存在的建  print(info['add']) print(info.get('addr','抚顺市'))

当不存在这个建的时候可以返回默认设置的值,有这个建就正常返回

修改 info ['age']=3 print (info)

 增加 当字典中不存在这个建 ,我们就会添加 info['addr']='鞍山市' print(info)

 删除 del info['age'] print(info)

循环 ######sqlalcheny str

遍历 for k,v in info.items(): print (k,v)

获取所有键 print(list(info.keys()))

获取所有的值 print(list(info.values()))

你可能感兴趣的:(Python第二天)