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
Keywordslambda
Indicates an anonymous function.x
Function parameters.
An anonymous function has a limit that only one expression is allowed.return
The return value is the result of this expression.
>>>f=lambda x:x+x>>>f(5)10