python全棧開發—Week1

來源:互聯網
上載者:User

標籤:記憶體   var   中文   input   位元組   開發   and   選擇   think   

      第一周主要介紹了python的發展史,以及當前的一些應用情況。

變數

  python的編寫過程中會用到許多資料,那為了方便操作,需要把這些資料分別用一個簡單的名字代表,方便在接下來的程式中引用,變數就是代表某個資料(值)的名稱。     

       1、變數名可以包括字母、數字、底線,但是數字不能做為開頭

  2、系統關鍵字不能做變數名使用

  

  var = ‘hello world!‘
  print(var)

 

  執行後

  hello world!

 

字元編碼

  字元編碼從ASCII,到GB2312、GBK、GBK18030,到現在的萬國碼Unicode,因為Unicode的英文佔用記憶體太大,所以其中的UTF-8最佳化後,一個中文字元佔3個位元組,一個英文字元佔1個位元組。

 

if else

  

 1 _username = ‘doulen‘ 2 _password = ‘home1234‘    #聲明使用者名稱和密碼的變數 3  4 username = input(‘username:‘) 5 password = input(‘password:‘)     6  7 if username == _username and password == _password: 8     print(‘welcome {name}, login...‘ .format(name=username))     #只要輸入的使用者名稱密碼和預先存的一致 那就輸出這段話 9 else:10     print(‘username or password is wrong‘)       #否則 輸出這段話

 

 

while迴圈

 1 true_age = 24 2 count = 0 3 while count < 3: 4     g_age = int(input(‘age:‘)) 5     chances = 2-count 6  7     if g_age == true_age: 8         print(‘you got it!‘) 9         break10     elif g_age > true_age:11         print(‘oops! think smaller, you have %s chances left‘ %(chances))12     else:13         print(‘oops! think bigger, you have %s chances left‘ %(chances))14     count +=115 else:16     print(‘you have guessed too many times‘)

  讓使用者自行選擇繼續還是終止

 1 true_age = 24 2 count = 0 3 while count < 3: 4     g_age = int(input(‘age:‘)) 5     chances = 2-count 6  7     if g_age == true_age: 8         print(‘you got it!‘) 9         break10     elif g_age > true_age:11         print(‘oops! think smaller, you have %s chances left‘ %(chances))12     else:13         print(‘oops! think bigger, you have %s chances left‘ %(chances))14     count +=115     if count == 3:16         countine_comfirm = input(‘do you want countine?y/n:‘)17         if countine_comfirm != ‘n‘:18             count = 0

 

python全棧開發—Week1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.