Chinaunix首页 | 论坛 | 博客
  • 博客访问: 295622
  • 博文数量: 240
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-04 18:14
文章分类

全部博文(240)

文章存档

2017年(8)

2014年(4)

2013年(15)

2012年(4)

2011年(14)

2010年(55)

2009年(140)

我的朋友

分类: Python/Ruby

2010-07-28 16:09:53

Hello.py
 

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
    print "hello world"


 

Compile.py

import py_compile
py_compile.compile('hello.py')


import compiler
compiler.compileFile('hello.py')

 


rule_naming.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 变量、模块名的命名规则
# Filename: ruleModule.py

_rule = "rule information"

#面向对象中的命名规则
class Student: # 类名大写
    __name = "" # 私有实例变量前必须有两个下划线
    def __init__(self, name):
        self.__name = name # self相当于Java中的this
    def getName(self): # 方法名首字母小写,其后每个单词的首字母大写
        return self.__name

if __name__ == "__main__":
    student = Student("borphi") # 对象名小写
    print student.getName()


>>> borphi

 

 

variable.py

i = 1
print id(i)
i = 2
print id(i)


 

local_global_variable.py

# 局部变量
local = 1

# 全局变量
global _x; _x = 3


 

number.py

# 整型
i = 1; print type(i)

# 长整型
l = 9999999990; print type(l)

# 浮点型
f = 1.2; print type(f)

# 布尔型
b = True; print type(b)

# 复数类型
c = 7 + 8j; print type(c)


 

 

阅读(1143) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~