01-python基礎

來源:互聯網
上載者:User

標籤:數實值型別   lob   edit   python   except   style   簡單的   速度   ota   

前幾天, 覺得python簡單的不行, 沒有仔細做筆記, 然後今天翻了下前幾天看的東西, 還是記下來吧

對於python2.7 和 python3 , 建議使用python3 的模式編程, 然後使用python2.7 的包去運行

1, 頭

python檔案的頭一般用來聲明的, 個shell有些類似, 當然對windows無用

#!/usr/bin/env python#encoding=utf-8

2, 保留子

python的保留字有 

>>> import keyword>>> keyword.kwlist[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘nonlocal‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]

3, python通過縮排來控制碼塊, 所以python需要嚴格的縮排, 

  注意editplus遠端連線linux的時候, tab鍵是8個位元組, 會有坑...

4, 注釋: 

# 單行注釋‘‘‘多行注釋, 也可以用來格式化輸出 ‘‘‘

5, 多行輸出

total = item_one +         item_two +         item_three

6, 資料類型

python的資料類型有

數實值型別: int, float, bool, complex(複數)字串類型: String集合類型: list, sets, dictionary, Tuple

 dict使用了一種特殊的hash演算法, 所以不論key有多少, 其查詢速度幾乎不變

7, 匯入其他模組

import sysfrom sys import argvfrom sys import *     # 不建議使用

 

01-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.