python基礎文法

來源:互聯網
上載者:User

標籤:strong   輸出   item   字母   通過   keyword   with   module   python   

標識符
  • 第一個字元必須是字母或底線‘_‘。
  • 其他的部分可以是字母、數字和底線。
  • 標識符對大小寫敏感。
內建關鍵字

不能把它們用作任何標識符名稱。Python 的標準庫提供了一個 keyword 模組,可以輸出目前的版本的所有關鍵字:

import keyword

keyword.kwlist

多行語句

Python 通常是一行寫完一條語句,但如果語句很長,我們可以使用反斜線(\)來實現多行語句,例如:

total = item_one +         item_two

  • 自然字串, 通過在字串前加r或R。 如 r"this is a line with \n" 則\n會顯示,並不是換行。

 

print 預設輸出是換行的,如果要實現不換行需要在變數末尾加上 end="":
print( x, end=" " )

import 與 from...import

在 python 用 import 或者 from...import 來匯入相應的模組。

將整個模組(somemodule)匯入,格式為: import 模組

從某個模組中匯入某個函數,格式為: from 模組 import 函數

從某個模組中匯入多個函數,格式為: from 模組 import 函數1, 函數2, 函數3

將某個模組中的全部函數匯入,格式為: from 模組 import *

 

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.