python基础语法
2017-12-08 09:46
239 查看
python基础语法小汇总
test.py
# coding utf-8 #1. 打印常量 print("1. 打印常量") print("hello python") #2. 定义变量 print("2. 定义变量") a = 10 b = 20 c=a+b print("c = {0}".format(c)) #3. 条件判断 print("3. 条件判断") score = 65 if score>=80 : print("good") elif score>=60 : print("及格") print ("马马虎虎") elif score>=40 : print("not good") else : print("bad") #4. 循环 print("4. 条件判断") for i in range(0,5): print(i) #5. 定义函数 print("5. 定义函数") def hello(): print("hello wlh") hello() #6.面向对象 print("6. 面向对象 class") class test : def hi() : print("print from test hi()") hello() test.hi() #7.引入python文件 print("7.引入python文件") import other class1 = other.otherclass() class1.display()
other.py
#另一个文件 class otherclass: def display(self): print("open the other file") #otherclass.display()
输出结果:
1. 打印常量
hello python
2. 定义变量
c = 30
3. 条件判断
及格
马马虎虎
4. 条件判断
0
1
2
3
4
5. 定义函数
hello wlh
6. 面向对象 class
print from test hi()
hello wlh
7.引入python文件
open the other file
相关文章推荐
- python的yield语法基础
- python基础语法(二)
- python3 基础语法一
- Python基础语法学习第二篇
- Python 基础语法(二)
- Python学习笔记【基础语法篇(一)】
- python基础语法
- python-第一课-入门语法(1)-基础部分
- Python基础语法——循环(四)
- python语法基础拾遗
- Python3 基础语法
- python语法基础(一)
- Python语法基础(一):变量和数据类型
- Python基础-数据类型和基础语法
- Python学习之路☞1——Python及基础语法
- Python学习笔记:与Java 基础语法对比
- Python学习(二)基础语法
- python 闯关之路一(语法基础)
- python3基础语法
- Python基础语法笔记