您的位置:首页 > 编程语言 > Python开发

Python入门(一)

2016-01-17 16:52 447 查看

安装

安装python

环境变量设置为 C:\Python34 即可(或27)

在cmd中输入 python 测试是否配置正确环境变量

lxml(flask等)

easy_install lxml (不推荐)

pip install lxml

手动安装 下载lxml库( http://www.lfd.uci.edu/~gohlke/pythonlibs/ )— 后缀名改为zip,解压— 将lxml文件夹放入C:\Python27\Lib中— 在.py 中import lxml 看报不报错

Python入门(一)

Python语言基本语法

判断

s = 90
if s >= 80:         # 判断
print("很好")
else:
print("vjls")
# elif


循环

for i in range(0, 10):      # 循环
print("Item {0} {1}".format(i, "hello"))    # 字符拼接


定义函数

def sayhello():         # 定义函数
print("hello")
sayhello()


类及继承

class Hello:
def __init__(self, name):
self._name = name
def sayhello(self):
print("hello {0}".format(self._name))
h = Hello("dr")
h.sayhello()


# coding=utf-8
class Fa:
def __init__(self, name):
self._name = name
def sayhello(self):
print("hello {0}".format(self._name))
class Son(Fa):      # 在括号里写父类
def __init__(self, name):
Fa.__init__(self, name)

def sayhi(self):
print("hi {0}".format(self._name))
h = Fa("dr")
h.sayhello()
h1 = Son("wang")
h1.sayhi()


引入 Python文件

import mylib        # 引入文件
h = mylib.Hello()


from mylib import Hello     # 引入文件的一部分
h = Hello()


Python语言Web开发框架web2py

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: