码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习记录-2016-11-28

时间:2016-11-29 11:52:58      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:password   welcome   correct   python   import   

所学模块:

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

标签:password   welcome   correct   python   import   

原文地址:http://12306114.blog.51cto.com/12296114/1877517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!