os.popen()方法的使用
os.popen()方法用于从一个命令打开一个管道。
语法:os.popen(command[, mode[, bufsize]]) 其中 command是使用的命令 mode--模式权限可以是‘r’或‘w’,默认为r。
示例:
#!/usr/bin/python import os a = 'mkdir newdir' b = os.popen(a, 'r') print(b)
os.mkdir("num_dir") 创建目录
isdigit()的使用
Python中的isdigit()函数是检测输入字符串是否只由数字组成。如果是则返回Ture否则返回False
enumerate()的使用
多用于在for循环中得到计数,利用它可以同时获得索引和值。
>>> lst = [1,2,3,4,5,6] >>> for index,value in enumerate(lst): print ('%s,%s' % (index,value)) 0,1 1,2 2,3 3,4 4,5 5,6
Python字符串加颜色区别:
print("