133/Python

/15. 集合和字典/02. 集合的用法.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 定义一个类,定义它的属性和方法
class Student(object):
def __init__(self, name, score):
self.name = name
self.score = score

def print_score(self):
print("%s: %s" % (self.name, self.score))

# 创建一个类的实例
bart = Student('Bart Simpson', 59)
lisa = Student('Lisa Simpson', 87)

bart.print_score()
lisa.print_score()

# Python中类的实例属性和类属性
class Student(object):
name = 'Student'
def __init__(self, name, score):
self.name = name
self.score = score

bart = Student('Bart Simpson', 59)
lisa = Student('Lisa Simpson', 87)

print(bart.name)
print(bart.score)
print(lisa.name)
print(lisa.score)
print(Student.name)

/16. 生成器和迭代器/05. 生成器.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 定义一个类,定义它的属性和方法
class Student(object):
def __init__(self, name):
self.name = name

def print_score(self):
print("%s: %s" % (self.name, self.score))

# 创建一个类的实例
bart = Student('Bart Simpson')
bart.print_score()
bart.score = 100
bart.print_score()

# Python中类的实例属性和类属性
class Student(object):
def __init__(self):
self.name = 'Student'
def print_score(self):
print("%s: %s" % (self.name, self.score))

bart = Student()
bart.print_score()
bart.score = 100
bart.print_score()

/13. 函数/02. 函数的使用.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 函数的使用

def printMax(a, b):
if a > b:
print(a, '最大')
elif a == b:
print(a, '等于', b)
else:
print(b, '最大')

printMax(3, 4)

x = 5
y = 5
printMax(x, y)

def printMax(a, b):
if a > b:
print(a, '最大')
elif a == b:
print(a, '等于', b)
else:
print(b, '最大')

printMax(3, 4)

x = 5
y = 5
printMax(x, y)

# 函数的使用
def printMax(a, b):
if a > b:
print(a, '最大')
elif a == b:
print(a, '等于', b)
else:
print(b, '最大')

printMax('hello', 'world')

# 函数的使用
def printMax(a, b):
if a > b:
print(a, '最大')
elif a == b:
print(a, '等于', b)
else:
print(b, '最大')

printMax('hello', 'world')

/15. 集合和字典/03. 字典的用法.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 字典的使用
d = {'Name': 'Runoob', 'Age': 20, 'Score': 98}
print(d['Name'])

d = {'Name': 'Runoob', 'Age': 20, 'Score': 98}
print(d['Name'])

d = {'Name': 'Runoob', 'Age': 20, 'Score': 98}
print(d['Name'])
print(d['Age'])
print(d['Score'])

d = {'Name': 'Runoob', 'Age': 20, 'Score': 98}
print(d['Name'])
print(d['Age'])
print(d['Score'])

d = {'Name': 'Runoob', 'Age': 20, 'Score': 98}
print(d['Name'])
print(d['Age'])
print(d['Score'])

/11. 文件处理/03. 写入.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 写入
f = open('test.txt', 'w')
f.write('Hello, world!\n')
f.write('Hello, Python!\n')
f.close()

/15. 集合和字典/01. 集合的定义.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 定义一个类,定义它的属性和方法
class Student(object):
def __init__(self, name, score):
self.name = name
self.score = score

def print_score(self):
print("%s: %s" % (self.name, self.score))

# 创建一个类的实例
bart = Student('Bart Simpson', 59)
lisa = Student('Lisa Simpson', 87)

bart.print_score()
lisa.print_score()

# Python中类的实例属性和类属性
class Student(object):
def __init__(self):
self.name = 'Student'

bart = Student()
print(bart.name)

/14. 文件操作/01. 文件的读写.py
#!/usr/bin/python
# -*- coding: utf-8