1、mac中安装python
使用homebrew安装
安装brew install pyenv
查看当前的shell
echo $SHELL
/bin/zsh/
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
vscode插件
python
live server
code format
pretti
jupyter
jupyter notebook 启动在vscode上
python 语法
print (a,b,spl)
type(18) 类型
.18 = 0.18
18. = 18.0
boolean
True
False
python不需要声明类型
keywords
变量规则
x +=3
a= b =c =2
a=2;
b=2;
c=2;
a,b,c=1,2,3
流程 语句
if
if else
for x in range(m,n): range 左开右闭
x =1
while x<10:
print(x)
x+=1
break;
continue;
字符串文字
单双号 混用
print(''test1'')
if "测试" in strl: 用in判断在不在串中
print ("test123")
str[0,2]
str[3:]
str[:3]
字符串截取
f‘xxx{name}xxx ’ 填充字符串
file = open ('article.txt','r',encoding= "utf-8");
content = file.read()
//w写入
file2 = open('test1.txt','w',encoding='utf-8')
content = '123312213321';
file2.write(content)
file2.close()
with open ('article.txt','r',encoding= "utf-8") as file :
print (file.readline())
file.close()
列表和元组
a = 0;
cla = ['12',12,False,a]
cla[-1] 最后一个
len(cla)
cla.append('')追加
cla.pop() 删最后一个
cla.insert(1,'ttw')
cla.pop(1)删索引位的值
Tuple 元组
不能修改其中内容
Tuple
cla = ('1',3)
cla1 = (1)只有一个值
元组中的列表可以修改
cla[3][0] ='123231'
d = {p1:"p1,p2:"p2"}
d['p1']
d.pop('key值')
d.get(‘key值’)
d['p1'] = 66
set1 = set([1,2,3])
set1.add(值)
set1.remove(索引)
a.replace(s,r)替换
函数
def sumFn(a,b):
if(a<100):
pass
else:
a = a-100
return a+b
def testFace():
return 2,2332,2112
反回的元组不可修改
模块
tkinter ui
requests 爬虫
python -m venv envirment01