Python Tool Visual Studio simple to use

Source: Internet
Author: User

Because it's been done. NET development, has been using the IDE is the VS series, so want to use vs can also develop Python, just Microsoft provides a plug-in PTVs (Python Tool Visual Studio) specifically for Python development, but unfortunately not available in Chinese version, Only English version of, for the English is very bad for me is a test ah!!!!!!!!!!!

Sort and sorted

Accidentally using the PTVs plugin to sort the list, I found that with Python's own scmd command sort or sorted sort is OK, but in the plugin, sort is not

It seems that you must use sorted to use it, this is really not good.

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

Use of formatted dates

Use the Strftime method of the time module to format the date

Import Time#formatted as 2016-03-20 11:45:39 in the form ofPrintTime.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())#formatted as Sat 28 22:24:24 2016 FormPrintTime.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ())#convert a format string to a timestampA ="Sat Mar 22:24:24"PrintTime.mktime (Time.strptime (A,"%a%b%d%h:%m:%s%Y"))

Get calendar

Import calendarcal=calendar.month (2016,7)print(CAL)

Some operations on IO

Read file

>>>f=open ("g:\\python\\txt1.txt","R" )>>>f.read () read content >>>f.close ()

Write file contents

>>>f=open ("g:\\python\\txt1.txt","w") >>>f.write ("Python"# Write content >>>f.close ()

Custom function of the wording, which is more attention to the colon: the wording, there is the use of space, or it is easy to error

 >>>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 ... >>> is python

How anonymous functions are written

The keyword lambda represents an anonymous function, preceded by a colon, that x represents a function parameter.

The anonymous function has a restriction that there can be only one expression, without writing return , and the return value is the result of that expression.

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

Python Tool Visual Studio simple to use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.