Python入门(一)

来源:互联网 发布:如何鉴别淘宝代购真假 编辑:程序博客网 时间:2024/05/04 08:03

安装

安装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-8class 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

0 0
原创粉丝点击