Python-基本语法
2016-04-02 12:30
507 查看
# coding=utf-8
print “Hello Python”
b=23
c=a+b
print c
if score>=90:
print “优秀”
elif score>=60:
print “及格”
else:
print “不及格”
print (“Item {0} {1}”.format(i,”Fishyer”))
print (“我在说话”)
def max(a,b):
if a>b:
return a
else:
return b
say()
print (max(12,23))
def init(self,name):
self.name=name;
def say(self,content):
print(“{0}说:{1}”.format(self.name,content))
class Student(Person):
def init(self,name,grade):
Person.init(self,name)
self.grade=grade
def say(self,content):
Person.say(self,content)
def study(self,course):
print (“{2}年纪的{0}在学习{1}”.format(self.name,course,self.grade))
laoWang=Person(“老王”)
laoWang.say(“我是逗比”)
xiaoMing=Student(“小明”,1)
xiaoMing.say(“我去找小红了”)
xiaoMing.study(“语文课”)
b=lib.Book(“数学之美”)
print (“我借了一本书:{0}”.format(b.getName()))
from lib import Book
b=Book(“五子棋先手必胜法”)
print (“我买了一本书:{0}”.format(b.getName()))
print “Hello Python”
1-变量
a=12b=23
c=a+b
print c
2-判断语句
score=67if score>=90:
print “优秀”
elif score>=60:
print “及格”
else:
print “不及格”
3-循环语句
for i in range(0,10,2):print (“Item {0} {1}”.format(i,”Fishyer”))
4-函数
def say():print (“我在说话”)
def max(a,b):
if a>b:
return a
else:
return b
say()
print (max(12,23))
5-面向对象
class Person:def init(self,name):
self.name=name;
def say(self,content):
print(“{0}说:{1}”.format(self.name,content))
class Student(Person):
def init(self,name,grade):
Person.init(self,name)
self.grade=grade
def say(self,content):
Person.say(self,content)
def study(self,course):
print (“{2}年纪的{0}在学习{1}”.format(self.name,course,self.grade))
laoWang=Person(“老王”)
laoWang.say(“我是逗比”)
xiaoMing=Student(“小明”,1)
xiaoMing.say(“我去找小红了”)
xiaoMing.study(“语文课”)
6-引用外部文件
import libb=lib.Book(“数学之美”)
print (“我借了一本书:{0}”.format(b.getName()))
from lib import Book
b=Book(“五子棋先手必胜法”)
print (“我买了一本书:{0}”.format(b.getName()))
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法