一、模块初始
import sys
print(sys.path)#打印python的环境
print(sys.argv)#打印相对路径
print(sys.argv【2】)#打印对应的变量
import os
cmd = os.system("dir")
print(cmd)
os.mkdir(‘new_dir‘)
#第三方库
在同一目录下或在lib/site-package下可直接import,其他情况下需写路径
import
数据运算:
3/2 ==1
5%2 ==1返回余数
!=
<>
8bit =byte
1024byte=1kbyte
1024kbyte=1mbyte
1024mb=1gb
2014gb=1T
& | ^(异或运算) ~(反转) >>右移 <<左移
str和二进制的转换
列表的操作
names = [‘zhangyang‘,‘guyun‘,‘xiangpeng‘,‘xuliangchen‘] print(names)print(names[0],names[2])print(names[0:2])#切片,顾头不顾尾print(names[0:])print(names[-1])print(names[-3:]) names.append("leihaidong")names.insert(1,‘chenronghua‘)names.insert(3,‘xinzhiyun‘)names[2]=‘xiedi‘#names.pop(2)names.remove(‘chenronghua‘)del names[1]names.pop()#删除最后一个 print(names.index(‘xiedi‘)) print(names[names.index(‘xiedi‘)]) print(names.count(‘xiedi‘))names.clear()names.reverse()#反转names.sort()#排序 names1=[1,2,3,4]names.extend(names1) names2 = names.copy()#浅copynames[1]= ‘sd‘print(names,names2)#names变了,names2不变 #但是names还有一层的话,都变 import copynames3 = copy.copy(names)names3 = copy.deepcopy(names) for i in range(1,10,2): print(i)
时间: 2024-10-18 04:05:27