1,自己编写的XXX.PY 文件,导入到Python 编译器里面。
①自己编写的脚本导入
import sys
sys.path.append(E:/17、python")
import tieba
2,中文编码
Python的默认中文编码是ASCII格式,要加上编码说明
#coding=utf-8 或者 # -*- coding: UTF-8 -*-
3,不能以数据开头,标识符区分大小写(例如,def 可以识别,但是Def 就不能识别)
4,靠缩进控制代码块语句,同一代码块的语句缩进必须一样。
5,空行是函数和模块之间的区隔
6,同一行中,用分号;区隔多个语句
7,Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程。----简直魔性
8,a,b,c =1,2,"abc"
9,鸡兔同笼程序
def solve(numlegs, numheads): for numchicks in range(0, numheads+1): numpigs = numheads - numchicks tollegs = 4*numpigs + 2*numchicks if tollegs == numlegs: return [numpigs, numchicks] return [None, None] def barnyard(): heads = int(raw_input("Enter number of heads: ")) legs = int(raw_input("Enter number of Legs: ")) pigs, chickens = solve(legs, heads) if pigs is None: print "There is no answer" else: print "Numbers of pigs is ", pigs print "Numbers of chickens is ", chickens barnyard()
①函数,变量定义,应该用小写(Pythoncharm里会标记错误,要求小写)
②逗号前无空格,逗号后有空格。
③raw_input 输入函数
④None 要用is 不能用 = =
递归,自身调用。
********************************************************************
结巴分词
1,安装结巴分词代码
安装错误!是因为path 问题!!!简直糟心
G:\Python27
安装完毕
2,https://github.com/fxsjy/jieba 好好看谢谢。