Python基礎:基礎

來源:互聯網
上載者:User

標籤:匯入   編碼   檔案尾碼名   尾碼   nbsp   不能   code   報錯   結果   

1.第一句python

print(‘hello world‘)

-python調用的檔案尾碼名可以是任意

-匯入模組時,如果不是.py檔案,會報錯

-建議始終將檔案名稱尾碼寫為.py

2.兩種執行方式

1)python 解譯器  py檔案路徑

2)輸入Python 進入解譯器    即時輸入並擷取到執行結果(互動式頁面)

3.解譯器路徑

#!/usr/bin/env python

4.編碼

# -*- coding:utf8 -*-  

eg :在Linux環境中,

檔案名稱:

  ./2.py

檔案內部:

#!/usr/bin/env python
# -*- coding:utf8 -*- %在Python3中此句不需要
print (‘hello world‘)

 5.執行一個操作

  提示使用者輸入使用者名稱和密碼,如果使用者名稱和密碼都為root,則登入成功

#n為變數,變數只能由字母、數字、底線組成,不能以數字開頭,也不能以Python的關鍵字命名,也不能以Python的內建函數或類命名#Python中用“““   ”””注釋一段程式n1 = input(‘請輸入使用者名稱: ‘)n2 = input(‘請輸入密碼: ‘)if n1 == ‘root‘ and n2 == ‘root‘:    print(‘登入成功‘)else:    print(‘登入失敗‘)“““print(n1)print(n2)”””

 

Python基礎:基礎

聯繫我們

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