python是一个跨平台的脚本语言.需要运行在虚拟机上,有点类似于java.在windows系统下可以去python官网下载msi 安装包进行安装.其他系统类似.
下面是我编写的一个python入门级别的概要脚本:test.py
import time;#导入模块其实就是脚本文件名 print('hello every one.\n') print('\t welcome to use python language.') tup = ('米斯特.唐','male',1990)#这是一个元组 print(tup[0:3]) dict = {}# 这是一个字典 dict['狼王'] = 'Mr Yu' print(dict['狼王']) arr = ['高亮','米斯特.唐','爆炒螺丝','杜','木头棒子'] # 这是一个数组 print(arr) str = 'good afternoon' print('it is ' + str[4:]) now = time.time() print(now) print("program is very insteresting.") def func(name): #定义函数 print('hello',name) pass print('上面的pass仅仅是个占位符,不执行') return; func('高亮') #######下面是面向对象 class Employee: '所有员工的基类' empCount = 0 def __init__(self, name, salary): self.name = name self.salary = salary Employee.empCount += 1 def displayCount(self): print ("Total Employee %d" , Employee.empCount) def displayEmployee(self): print ("Name : ", self.name, ", Salary: ", self.salary) #"创建 Employee 类的第一个对象" emp1 = Employee("Zara", 2000) #"创建 Employee 类的第二个对象" emp2 = Employee("Manni", 5000) emp1.displayEmployee() emp2.displayEmployee() print("Total Employee %d" , Employee.empCount)
命令行:python test.py.下图是运行结果: