Python Tool Visual Studio, pythonstudio

Source: Internet
Author: User

Python Tool Visual Studio, pythonstudio

Because I have been doing this. NET development, the IDE has always been used in the VS series, so if you want to use VS, you can also develop Python, just as Microsoft provides a plug-in PTVS (Python Tool Visual Studio) for Python development, however, it is a pity that the Chinese version is not provided, and only the English version is provided. It is a test for me who have poor English !!!!!!!!!!!

Sort and Sorted

When the PTVS plug-in is used to Sort the list, it is found that the SCMD command Sort or Sorted in Python can be used to Sort the list, but Sort cannot be used in the plug-in.

It seems that you must use Sorted.

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

Format date usage

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

Import time # format to print time in the format of 11:45:39. strftime ("% Y-% m-% d % H: % M: % S", time. localtime () # format as Sat Mar 28 22:24:24 2016 format print time. strftime ("% a % B % d % H: % M: % S % Y", time. localtime () # convert the format string to the Timestamp a = "Sat Mar 28 22:24:24 2016" print time. mktime (time. strptime (a, "% a % B % d % H: % M: % S % Y "))

Get calendar

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

IO operations

Read files

>>> F = open ("G: \ Python \ txt1.txt", "r") >>> f. read () read content >>>> f. close ()

Write File Content

>>> F = open ("G: \ Python \ txt1.txt", "w") >>> f. write ("Python") # write content >>> f. close ()

For the writing of user-defined functions, pay attention to the writing of colons, and use of spaces. Otherwise, it is easy to report errors.

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

Writing anonymous Functions

KeywordslambdaIndicates an anonymous function.xFunction parameters.

An anonymous function has a limit that only one expression is allowed.returnThe return value is the result of this expression.

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

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.