Python学习记录-2016-11-28
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习记录-2016-11-28相关的知识,希望对你有一定的参考价值。
所学模块:
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")
以上是关于Python学习记录-2016-11-28的主要内容,如果未能解决你的问题,请参考以下文章