python基本概念_python基础整理----基本概念和知识

整理一下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]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值