Python Tool Visual Studio簡單使用,pythonstudio

來源:互聯網
上載者:User

Python Tool Visual Studio簡單使用,pythonstudio

由於一直在做.NET的開發,一直用的IDE是VS系列的,所以想用VS也能開發Python,剛好微軟提供一個外掛程式PTVS(Python Tool Visual Studio)專門應用於Python開發的,但是很可惜沒有提供中文版本的,只有英文版本的,對於英語很差的我來說是一種考驗呀!!!!!!!!!!!

Sort與Sorted

無意中用PTVS外掛程式做列表的排序的時候發現,用Python自己帶的SCMD命令Sort或者Sorted排序都行,但是在外掛程式中Sort就不行

貌似必須使用Sorted使用才行,這真是百思不得。

s=[1,2,3,4,15,1,1]print(sorted(s))

格式化日期的使用

使用 time 模組的 strftime 方法來格式化日期

import time# 格式化成2016-03-20 11:45:39形式print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 格式化成Sat Mar 28 22:24:24 2016形式print time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())   # 將格式字串轉換為時間戳記a = "Sat Mar 28 22:24:24 2016"print time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y"))

擷取日曆

import calendarcal=calendar.month(2016,7)print(cal)

對IO的一些操作

讀取檔案

>>>f=open("G:\\Python\\txt1.txt","r")>>>f.read()讀出內容>>>f.close()

寫入檔案內容

>>>f=open("G:\\Python\\txt1.txt","w")>>>f.write("Python") #寫入內容>>>f.close()

自訂函數的寫法,這裡面多注意冒號:的寫法,還有就是空格的使用,不然很容易報錯的

>>>def my_function(x):...            if x>=0:...                   return x...            else:...                  return -x...>>> my_function(5)5
>>>def my_print():...        print("i am is python")...        return...>>> my_print()i am is python

匿名函數的寫法

關鍵字lambda表示匿名函數,冒號前面的x表示函數參數。

匿名函數有個限制,就是只能有一個運算式,不用寫return,傳回值就是該運算式的結果。

>>>f=lambda x:x+x>>>f(5)10

聯繫我們

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