所学模块:
import os
import sys
import getpass
os.system("df -h")
cmd_res = os.system("df -h")
print(cmd_res) 为0,因为结果为0,如果想看结果,请使用如下写法:
cmd_res = os.popen("df -h").read()
os.mkdir("directory")创建目录
print(sys.path)
查看python导入模块的路径
一般/usr/lib/python2.7/site-packages
可以import模块,import模块时,不加后缀py
if else用法
user = jack
passwd = 123456
username = input("username:")
password = input("password:")
if user == username:
print("username is correct.")
if passwd == password:
print("welcome log in.")
else:
print("password is invailid.")
优化:
user = jack
passwd = 123456
username = input("username:")
password = input("password:")
if user == username and passwd == password:
print("welcome login.")
else:
print("username or password is invailid.")
guess age:
age = 22
guess_num = int(input("guess your number"))
if guess_num = age:
print("configratulations,you got it")
elif guess_num > age:
print("thins smaller")
else:
print("think bigger")