由于一直在做.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 calendar
cal=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

Python Tool Visual Studio简单使用的更多相关文章

  1. [转]Python in Visual Studio Code

    本文转自:https://code.visualstudio.com/docs/languages/python Working with Python in Visual Studio Code, ...

  2. Visual Studio 简单使用常识操作

    Visual Studio 简单使用个人总结   转载请注明来源:www.cnblogs.com/icmzn(后续会持续更新) 可以查看一下链接,官方关于visual studio 2010 的介绍  ...

  3. Python + Djang+ Visual Studio Code(VSCode)

    使用 Visual Studio Code(VSCode)搭建简单的 Python + Django 开发环境 https://www.cnblogs.com/Dy1an/p/10130518.htm ...

  4. Python 在Visual studio 中做单元测试进行TDD开发

    Unit Tests Steve Dower edited this page on 14 Jul · 3 revisions Pages 38 Home Azure Remote Debugging ...

  5. 在 C 代码中嵌入 Python 语句或使用 Python 模块 (Visual Studio 2013 环境设置)

    1) 新建一个 内嵌 Python 语句的 C 代码, // This is a test for check insert the Python statements or module in C. ...

  6. 【Python】Visual Studio Code 安装&&使用 hello python~~~~

    1.安装Python 官网下载: https://www.python.org/downloads/   选择版本下载 2.下载完毕后,点击安装. 3.看到页面,直接下一步,全部默认选项. 4.安装即 ...

  7. [tool] Visual Studio Code python配置

    语言设置 安装中文插件即可成为中文 选择一个Python解释器 Python是一种解释型语言,为了运行Python代码并获取Python IntelliSense,您必须告诉VS Code使用哪个解释 ...

  8. [Tool] Visual Studio必备插件 + 技能

    总结自己常用的VS插件,其中部分需要注册. 在该链接http://www.cnblogs.com/neverc/p/4591501.html中提供 1.Web Essentials(测试支持2010, ...

  9. python c++ Visual Studio相关 Unable to find vcvarsall.bat问题

    使用Cython编译包的时候报错: Unable to find vcvarsall.bat 说明:https://jingyan.baidu.com/article/adc815138162e8f7 ...

随机推荐

  1. C# ASP.NET Webservice调用外部exe无效的解决方法

    最近用asp.net做webservice,其中有个功能是调用执行外部的exe(类似cmd中执行),但执行Process.Start之后就没有结果,同样代码在winform下正常,折腾两天终于找到解决 ...

  2. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

  3. Codeforces Round #308 (Div. 2) A. Vanya and Table 暴力

    A. Vanya and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  4. Qt Quick实现的涂鸦程序

    之前一直以为 Qt Quick 里 Canvas 才干够自绘.后来发觉不是,原来还有好几种方式都能够画图! 能够使用原始的 OpenGL(Qt Quick 使用 OpenGL 渲染).能够构造QSGN ...

  5. sqlserver 各种判断是否存在(表名、函数、存储过程等)

    库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists'elseprint 'not ex ...

  6. codeblocks中添加-std=c99

    早上用codeblocks编译一个c文件,出现这样一个编译错误: +'for'+loop+initial+declarations+are+only+allowed+in+C99+mode 原来cod ...

  7. Docker大行其道—镜像

    导读 作为Docker三大核心概念之一,Docker镜像(Docker Image)是一个面向Docker引擎的只读模板,包含文件系统.实际上每个Docker镜像包含一个独立的运行环境,如一个镜像包含 ...

  8. ubuntu 11.10 安装apache2 tomcat6

    ubuntu 11.10 安装apache2 tomcat6 导读 Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目 ...

  9. FOR XML PATH 解决联接返回结果集各记录问题

    FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作.那么以一个实例为主 ...

  10. python获取每颗cpu使用率

    以下是关于python来获取服务器每颗CPU使用率的使用脚本. #!/usr/bin/env python # -*- coding: utf-8 -*- import re,time def _re ...