Python學習記錄-2016-11-28

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.