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