整理一下python的基本概念和知识, 主要用python3为语法标准.

python介绍

一种面向对象的解释性计算机设计语言,具有丰富和强大的库。

  • python定位:“优雅”、“明确”、“简单”
  • 多种应用场景:可以写工具,后台服务,移动端等等。

运行环境搭建

下载对应版本的Python安装,官网地址如下

https://www.python.org/

运行get-pip.py安装pip (Py3自带pip)

https://bootstrap.pypa.io/get-pip.py

添加python目录及Scripts子目录添加至环境变量中

安装虚拟环境

  • 安装virtualenv
pip install virtualenv
  • 配置正确的话,会进入python解释器界面
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

编辑器选择

Sublime Text,Wing IDE,pycharm

基本语法和概念

变量

>>> x=3
>>> x*2
6
>>> x*999
2997

  

整数、浮点数

x=567(整数)
y=5.67(浮点数)
x/y(默认返回浮点数)
x//y(默认返回整数)

  

函数

def checkIsHasCapitalLetter(filename):
if filename.islower() == True:
return True
else:
common.outError(filename + "文件名存在大写.................")
return Fasle

  

缩进,流程控制语句for,if,while等都靠缩进识别,还有函数也是

for i in range(0, 5):
print(i)

模块

>>>import common(允许使用命名空间访问common里的东西)
>>>common.count()
>>>from common import count(添加到当前命名空间)
>>>count()

  

执行python程序

python.exe test.py

常用数据结构

  • 列表(list)
  • 字典(dict)
  • 集合(set)
  • 元组(tuple)

常用数据类型

  • 整数
  • 浮点数
  • 布尔值
  • 字符串

字符串基础

字符串是不可以改变的,和java一样,如若赋值,其实是新建了一个字符串

字符串定义,可以是单引号,也可以是双引号,字符拼接用+号

>>> "hello world"
'hello world'
>>> 'hello world'
'hello world'
>>> "hello" + "world"
'helloworld'
>>> "don't let go"
"don't let go"
>>> 'don\'t let go'(转义单引号)
"don't let go"
>>> "don\'t let go"
"don't let go"
>>> r"don\'t let go"(前面带"r"不转义)
"don\\'t let go"

  

字符串查找

>>> "nothing to see here".find("see")
11
>>> "nothing to see here".find("ok")
-1

  

字符串格式化

>>> filename = "notepad"
>>> "get file: %s ok"%filename
'get file: notepad ok'

UNICODE,python3字符串是以Unicode编码的
1.将其他字符串格式转为unicode:

ret=str.decode("gb2312")
ret=str.decode("ascii")
ret=str.decode("utf-8")

2.将unicode字符转为其他字符串格式:

ret=str.encode(“gb2312”)
ret=str.encode("ascii")
ret=str.encode("utf-8")

正则表达式

http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

 

扩展

字符串内建函数,len(), split(), upper(), strip()
多行字符串
字符串下标[0],[-2]

  

最新文章

  1. 数据库设计中的Soft Delete模式
  2. JS原生第六篇 (帅哥)
  3. NULL指针、零指针、野指针
  4. ndk学习8: 编译动态库
  5. Hark的数据结构与算法练习之臭皮匠排序
  6. 内核Makefile编写
  7. JS正则表达式基础
  8. 数据库操作(ADO)
  9. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
  10. memcpy内存拷贝及优化策略图解
  11. cocos2d-x Lua与OC互相调用
  12. redis事务、管道及消息通知探究
  13. UITextField 之 失去焦点 收起键盘
  14. Linux(2)文件和权限
  15. memcache+tp3.2实现消息队列
  16. Linux命令 df du
  17. C语言--pow()函数实现
  18. Linux下mysql出错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  19. JDBC的MySQL配置properties文件
  20. Ubuntu sudo apt-get update提示 Failed to fetch,解决办法

热门文章

  1. Docker MariaDB 10.3 Galera Cluster 集群同步复制 多主 Docker Haproxy 负载均衡
  2. C语言老司机学Python (六)- 多线程
  3. shell 脚本——判断条件
  4. qwe框架- CNN 实现
  5. Trump就职演说
  6. ffmpeg在am335x上的移植
  7. freemarker中的split字符串分割
  8. Jquery常用操作:checkbox、select取值,radio、checkbox、select选中及其相关
  9. freemarker写select组件(四)
  10. 应对不同格式 轻松转换PDF、WORD、PPT、TXT常用文件