Python语言编程基础ppt

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

转换
fruits = ["apple","orange","pear","banana"] m = [fruit +'s' for fruit in fruits if len(fruit)!=6 ] print m
数将 将连
单词
['apples', 'pears']



tuple=('z','z','y') tuple=('Z',)+tuple[1:] print tuple
张振宇 {1: 'zhangzhenyu', 2: 'xuegui', 3: 'dengmengyang'} {1: 'zhangzhenyu', 2: 'xuegui'} {1: 'zhangzhenyu', 2: 'zhaochao'} 2 {}


class student: name="unknow" sex="男" age="secret" school='none' def printname(self): print self.name def printall(self): print self.name print self.sex print self.age print self.school def setname(self,name): self.name=name
内资 权
16 27

string1 = “Red” string2 = “Hat” print string1+string2 print = 3*”Love”
RedHat LoveLoveLove



须数



string1 = “Red”
string2 = “Hat” print string1+string2#连接 print = 3*”Love”#复制3个
TypeError: 'str' object does not support item assignment
Python


级数 结
import string print string.find("www.baidu.com","com") print string.find("I love python","o",5) print string.find("I love python","o",1) print string.find("I love python","c",1,3) print string.lowercase print string.uppercase print string.digits

[1, 2, 3, 4, 5, 6] [1, 2, 3, 1, 2, 3, 1, 2, 3] ['zzy']
os=["Linux","Unix","Mac","Windows"] print 'Windows' in os for m in os:
print m
数 测试 数
True Linux Unix Mac Windows
线
写别
则为
时 须赋
NameError : name ’abc’ is not defined
12345 pi = 3.1415926 3+5

认为

该语
报错
print 3*4 print = 3**4 print 5/2 print 5.0/2
12 81 2 2.5



print (1+3)*2 print = 3*3**2
2.5*5.9=14.75 2.5/5.9=0.423728813559


m = 10 def multiply(p1):
m=20 print p1,"*",m,"=",p1*m def devide(p2): global m print p2,"/",m,"=",p2/m v1=2 v2=10 multiply(v1) devide(v2)
语编 础

编语



解释器
释语 执
编译
标码
编译 语 执

执行
区别
•Βιβλιοθήκη Baidu
码 缩进
缩进

内录

•数

关键

•语




• •释
数• • •组






赋 编语
x = 10 print x x = “China” print x
10 China






print type ('Hello') print type(18) x = "China" print type(x) print type(3.0)
<type ‘str’> <type ‘int’> <type ‘str’> <type ‘float’>

数 链 数组
关键

Name =‘PYTHON’ name = ‘python’ print name, Name
线
关键
写别
python PYTHON


nessage =“How are you” n = 18 pi = 3.1415926 print abc
0*0=0 0*1=0 0*2=0 0*3=0 0*4=0 0*5=0 0*6=0 0*7=0 0*8=0 0*9=0 1*0=0 1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9 2*0=0 2*1=2 2*2=4 2*3=6 2*4=8
级数 结
name="zhangzhenyu is a handsome boy" travel(name)
z
a
h
a
h
n
a
g
n
z
d
h
s
e
o
n
m
y
e
u
b
i
o
s
Y
级数 结
love ="python" love[0]="P"
love ="python" newlove="P"+love[1:] print newlove
x=1 y=2 x,y=x+y,x*y print x,y def swap(x,y):
return y,x a=1 b=2 a,b= swap(a,b) print a,b
('Z', 'z', 'y') 32 21
访问数 数

dict1 = {'001':'张振宇','002':'薛规'} print dict1['001']
name[0]= z name[4]= g lettle= a name[a+b]= n 14
计数
级数 结

def travel(string): index=0 while index<len(string): letter=string[index] print letter index = index+1
1 5

from math import * print sin(pi/2) print fabs(-5)
1 5

def minus(): x=0 y=0 while(x<=9): while(y<=9): print x,"*",y,"=",x*y y=y+1 x=x+1 y=0
minus()

name="zhangzhenyu" print "name[0]=",name[0] print "name[4]=",name[4] letter = name[2] print "lettle=",letter a=1 b=2 print "name[a+b]=",name[a+b] address="www.stu.edu.cn" print len(address)

10 11 3 -1 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
a = [1,2,3] b = [4,5,6] c = a+b d = ['zzy', 'is', 'a', 'boy'] print c print a*3 print d[0:1]
RedHat LoveLoveLove




def multiply(p1,p2)

print p1,”*”,p2,”=”,p1*p2

def devide(p3,p4)
print p3,”/”,p4,”=”,p3/p4
v1=2.5
v2=5.9
multiply(v1,v2)
devide(v1,v2)
2 * 20 = 40 10 / 10 = 1


def ex(x): if (x>10):

return 1
else:
return 0
print ex(20)
print ex(5)
1 0

内 数调
import math print math.sin(math.pi/2) print math.fabs(-5)
dict1 = {1:"zhangzhenyu",2:"xuegui",3:"dengmengyang"} print dict1 del dict1[3] print dict1 dict1[2]="zhaochao" print dict1 print len(dict1) dict1.clear() print dict1
z=student() z.printname() z.printall() z.setname("zhangzhenyu") z.printname()
unknow unknow 男
secret none zhangzhenyu


虚现 术


产计
【1】虚拟现实技术及其应用 安维华 清华大学出版社
相关文档
最新文档