【命名规范】

模块名:小写字母,单词之间用_分割;例如:ad_stats.py

包名:和模块名一样

类名:单词首字母大写;例如:ConfigUtil

全局变量名:大写字母,单词之间用_分割;例如:NUMBER,COLOR_WRITE

普通变量:小写字母,单词之间用_分割;例如:this_is_a_var

类实例变量:以_开头,其他和普通变量一样;例如:_price,_instance_var

私有实例变量:以__开头(2个下划线),其他和普通变量一样;例如:__private_var

专有变量:__开头,__结尾,一般为python的自有变量,不要以这种方式命名;例如:__doc__,__class__

函数名:和普通变量一样;例如:count_number(),get_name()

私有函数(外部访问会报错):以__开头(2个下划线),其他和普通函数一样;例如:__get_name()

【类1:类】

#!/usr/bin/python
# -*- coding:UTF-8 -*- class Dog():
#construct
#类变量可以不用显式定义在类的头部 但是最好不要这样做
#类变量不显式区分public 和 private, 隐式规则:变量前缀是__,则表示该变量是private变量,否则为public
def __init__(self, name, age):
self.name = name
self.age = age def sit(self):
print(self.name.title() + " is now sitting") def roll_over(self):
print(self.name.title() + " rolled over") dog = Dog("dabai", 10)
dog.sit()
dog.roll_over();
print dog.name

【类2:继承】

#!/usr/bin/python
# -*- coding:UTF-8 -*- class Animal():
def __init__(self, animal_type, name):
self.animal_type = animal_type;
self.name = name; class Dog(Animal):
def __init__(self, name, age):
self.name = name
#python2的语法
#python3的语法: super().__init__(param1, param2, ...)
Animal.__init__(self, "reptiles", name)
self.age = age
self.animal_type = "reptiles" def sit(self):
print(self.name.title() + " is now sitting") def roll_over(self):
print(self.name.title() + " rolled over") dog = Dog("dabai", 10)
dog.sit()
dog.roll_over();
print dog.name
print dog.animal_type

【字典】

#!/usr/bin/python

#unordered dict
a = {'a':'a', 'b':'b', 'c': 'c'}
for val in a:
print val #ordered dict
from collections import OrderedDict
a = OrderedDict()
a['a'] = 'a'
a['b'] = 'b'
a['c'] = 'c'
a['test'] = 'test'
for key, val in a.items():
print key, val

默认的字典是无序的,需要定义有序字典可参考OrderedDict

【unittest】

参考链接:https://docs.python.org/3/library/unittest.html

【python】初识python的更多相关文章

  1. Python——初识Python

    本篇主要内容: • Python的特点 • Python的种类 • Python的编码 • Python的安装环境推荐 • Python的基础用法:输入输出,算术运算符,逻辑运算符,基本程序结构语法 ...

  2. Python导出Excel为Lua/Json/Xml实例教程(一):初识Python

    Python导出Excel为Lua/Json/Xml实例教程(一):初识Python 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出 ...

  3. Python开发【第一篇】:初识Python

    初识python 一.python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解 ...

  4. Python开发【第二篇】:初识Python

    Python开发[第二篇]:初识Python   Python简介 Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏 ...

  5. 初识python面向对象

    一.初识python面向对象: class Person: #使用class关键字定义一个类 age=0 #类变量(静态变量) def eat(self,food): #定义一个方法 self.age ...

  6. Python初识与简介【开篇】

    目录 1.扯淡 2.Python历史 3.Python简介 4.Python应用 5.为什么是python而不是其他语言? 6.Python的种类 7.Python的特点 8.Python设计哲学 9 ...

  7. 篇2 安卓app自动化测试-初识python调用appium

    篇2              安卓app自动化测试-初识python调用appium --lamecho辣么丑 1.1概要 大家好!我是lamecho(辣么丑),上一篇也是<安卓app自动化测 ...

  8. 2017-06-22初识python

    初识python #!/usr/bin/env python (python解释器的文件路径)# -*- coding:utf-8 -*- (使用的编码内型)# python 2.7 <需要加第 ...

  9. python学习笔记:1.初识python

    4.26 今日内容大纲 1.初识计算机.CPU 内存 硬盘 2.python初识 3.python发展史以及影响 4.python的分类 5.python的种类 6.变量 7.常量 8.注释 9.基础 ...

  10. python基础篇_001_初识Python

    一.Python环境 windows环境安装Python步骤 .下载安装包:https://www.python.org/downloads/windows/  .安装:默认安装路径:C:\pytho ...

随机推荐

  1. 10款流行的Markdown编辑器,总有一款适合你

    摘要:作为一个开源人,如果你不会使用Markdown语法,那你就OUT了!Markdown 是 2004 年由 John Gruberis 设计和开发的纯文本格式的语法,非常的简单实用. 作为一个开源 ...

  2. APP-8.1-百度语音应用

    1.百度语音登录地址 http://yuyin.baidu.com/ 2.控制台创建应用 3.生成签名 3.1Postman软件应用 APP-8.2-Postman应用 3.2Postman执行 UR ...

  3. ubuntu 安装oracle客户端

    from: http://webikon.com/cases/installing-oracle-sql-plus-client-on-ubuntu Installing Oracle SQL*Plu ...

  4. The Roadmap of my web learning.

  5. 拓展Scene视图——场景编辑Vector2/3

    Test.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class ...

  6. Unity 平台依赖编译

    位置:unity文档-Manual-Scripting-Platform dependent compilation Property: Function: UNITY_EDITOR #define ...

  7. 多线程 死锁 wait(int i) notifyAll()

    public class ThreadDemo5 { public static void main(String[] args){ Pool pool = new Pool(); Productor ...

  8. Jumpserver 文档

    http://docs.jumpserver.org/zh/docs/admin_guide.html

  9. 什么是JIT,写的很好

    什么是JIT 一些其他解释的网站:http://www.sohu.com/a/169704040_464084 1.动态编译(dynamic compilation)指的是“在运行时进行编译”:与之相 ...

  10. 3G开发遇到的问题

    1.使用线程时,编译时要加上gcc xxx.c -o xxx -lpthread 2.分离字符串"abc,de,fgh" printf("%s",strtok ...