当前位置: 首页 > news >正文

wordpress调整行间距网络推广运营优化

wordpress调整行间距,网络推广运营优化,广告设计图片大全模板,移动通信网站建设Python内置的一种数据类型是列表:list 变量classmates就是一个list。用len()函数可以获得list元素的个数 用索引来访问list中每一个位置的元素 当索引超出了范围时,Python会报一个IndexError错误,所以,要确保索引不要越界&#xf…

Python内置的一种数据类型是列表:list
变量classmates就是一个list。用len()函数可以获得list元素的个数
用索引来访问list中每一个位置的元素
当索引超出了范围时,Python会报一个IndexError错误,所以,要确保索引不要越界,记得最后一个元素的索引是len(classmates) - 1
如果要取最后一个元素,除了计算索引位置外,还可以用-1做索引,直接获取最后一个元素,以此类推,可以获取倒数第2个、倒数第3个
当然,倒数第4个就越界了

classmates = ['Zane', 'L', 'Z']
len(classmates) # 3
classmates[0] # 'Zane'
classmates[-1] # 'Z'
classmates[-2] # 'L'

list是一个可变的有序表,所以,可以往list中追加元素到末尾
也可以把元素插入到指定的位置,比如索引号为1的位置
要删除list末尾的元素,用pop()方法
要删除指定位置的元素,用pop(i)方法,其中i是索引位置
要把某个元素替换成别的元素,可以直接赋值给对应的索引位置

classmates.append('Tht')
classmates.insert(1, 'Cws')
classmates.pop()
classmates.pop(1)
classmates[1] = 'LJD'

list里面的元素的数据类型也可以不同
list元素也可以是另一个list


另一种有序列表叫元组:tuple
tuple和list非常类似,但是tuple一旦初始化就不能修改

注意定义一个只有1个元素的tuple若不加逗号则定义的不是tuple,是1这个数

classmates = ('Zane', 'L', 'Z')
t1 = (1, 2)
t2 = ()
t3 = (1)
t3 # 1
t4 = (1,)
t4 # (1,)

Python在显示只有1个元素的tuple时,也会加一个逗号,以免你误解成数学计算意义上的括号

>>> t = ('a', 'b', ['A', 'B'])
>>> t[2][0] = 'X'
>>> t[2][1] = 'Y'
>>> t
('a', 'b', ['X', 'Y'])

可以用elif做更细致的判断

age = 21
if age >= 18:print('your age is', age)print('adult')
elif age >= 6:print('your age is', age)print('teenager')
else:print('kid')

if语句执行有个特点,它是从上往下判断,如果在某个判断上是True,把该判断对应的语句执行后,就忽略掉剩下的elif和else

if判断条件还可以简写

if x:print('True')

只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False

input()返回的数据类型是str,str不能直接和整数比较,必须先把str转换成整数
Python提供了int()函数来完成这件事情

s = input("birth: ")
birth = int(s)
if birth < 2000:print('00前')
else:print('00后')

int()函数若发现一个字符串并不是合法的数字时就会报错,程序就退出


模式匹配
当我们用if … elif … elif … else …判断时,会写很长一串代码,可读性较差
如果要针对某个变量匹配若干种情况,可以使用match语句

score = 'B'match score:case 'A':print('score is a')case 'B':print('score is b')case 'C':print('score is c')case _:print('score is ?')

使用match语句时,我们依次用case xxx匹配,并且可以在最后(且仅能在最后)加一个case _表示任意值

复杂匹配
match语句除了可以匹配简单的单个值外,还可以匹配多个值、匹配一定范围,并且把匹配后的值绑定到变量

age = 15match age:case x if x < 10:print(f'< 10 years old: {x}')case 10:print('10 years old')case 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18:print('11~18 years old')case 19:print('19 years old.')case _:print('not sure.')

在上面这个示例中,第一个case x if x < 10表示当age < 10成立时匹配,且赋值给变量x
第二个case 10仅匹配单个值,第三个case 11|12|…|18能匹配多个值,用|分隔
可见,match语句的case匹配非常灵活

匹配列表

args = ['gcc', 'hello.c', 'world.c']
# args = ['clean']
# args = ['gcc']match args:case ['gcc']:print('gcc: missing source file(s).')case ['gcc', file1, *files]:print('gcc compile: ' + file1 + ', ' + ', '.join(files))case ['clean']:print('clean')case _:print('invalid command.')	

第一个case [‘gcc’]表示列表仅有’gcc’一个字符串,没有指定文件名,报错
第二个case [‘gcc’, file1, *files]表示列表第一个字符串是’gcc’,第二个字符串绑定到变量file1,后面的任意个字符串绑定到*files,它实际上表示至少指定一个文件
第三个case [‘clean’]表示列表仅有’clean’一个字符串
最后一个case _表示其他所有情况


Python的循环有两种,一种是for…in循环,依次把list或tuple中的每个元素迭代出来

names = ['Zane', 'L', 'Tht']
for name in names:print(name)sum = 0
for x in [1, 2, 3, 4, 5, 6, 7]:sum += x
print(sum)

所以for x in …循环就是把每个元素代入变量x,然后执行缩进块的语句

如果要计算1-100的整数之和,从1写到100有点困难,幸好Python提供一个range()函数,可以生成一个整数序列,再通过list()函数可以转换为list

sum = 0
for x in range(101):sum += x
print(sum)#####sum = 0
n = 99
while n > 0:sum += nn -= 2
print(sum)

在循环中,break语句可以提前退出循环
在循环过程中,也可以通过continue语句,跳过当前的这次循环,直接开始下一次循环

n = 0
while n < 100:if n % 2 = 0:continueprint(n)n += 1

break语句可以在循环过程中直接退出循环,而continue语句可以提前结束本轮循环,并直接开始下一轮循环。这两个语句通常都必须配合if语句使用


Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度

d = {'Zane': 19, 'L': 21, 'Tht':18}
d['Zane'] # 19d['LJD'] = 20
d['LJD'] # 20

给定一个名字,比如’Michael’,dict在内部就可以直接计算出Michael对应的存放成绩的“页码”,也就是95这个数字存放的内存地址,直接取出来,所以速度非常快
这种key-value存储方式,在放进去的时候,必须根据key算出value的存放位置,这样,取的时候才能根据key直接拿到value
由于一个key只能对应一个value,所以,多次对一个key放入value,后面的值会把前面的值冲掉
如果key不存在,dict就会报错

要避免key不存在的错误,有两种办法,一是通过in判断key是否存在
二是通过dict提供的get()方法,如果key不存在,可以返回None,或者自己指定的value
注意:返回None的时候Python的交互环境不显示结果

'Zane' in d
Falsed.get('Zane')
d.get('Zane', 666)
666

要删除一个key,用pop(key)方法,对应的value也会从dict中删除

请务必注意,dict内部存放的顺序和key放入的顺序是没有关系的

和list比较,dict有以下几个特点:

  1. 查找和插入的速度极快,不会随着key的增加而变慢
  2. 需要占用大量的内存,内存浪费多

所以,dict是用空间来换取时间的一种方法
dict可以用在需要高速查找的很多地方,在Python代码中几乎无处不在

正确使用dict非常重要,需要牢记的第一条就是dict的key必须是不可变对象
这是因为dict根据key来计算value的存储位置,如果每次计算相同的key得出的结果不同,那dict内部就完全混乱了
这个通过key计算位置的算法称为哈希算法(Hash)

要保证hash的正确性,作为key的对象就不能变。在Python中,字符串、整数等都是不可变的,因此,可以放心地作为key。而list是可变的,就不能作为key


set和dict类似,也是一组key的集合,但不存储value
重复元素在set中自动被过滤

s = set([1, 1, 2, 2, 3, 3])
s # {1, 2, 3}

通过add(key)方法可以添加元素到set中,可以重复添加,但不会有效果
通过remove(key)方法可以删除元素

set可以看成数学意义上的无序和无重复元素的集合,因此,两个set可以做数学意义上的交集、并集等操作

s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
s1 & s2 # {2, 3}
s1 | s2 # {1, 2, 3, 4}

set和dict的唯一区别仅在于没有存储对应的value,但是,set的原理和dict一样,所以,同样不可以放入可变对象

str是不变对象,而list是可变对象

a = ['c', 'b', 'a']
a.sort()
a # ['a', 'b', 'c']a = 'abc'
a.replace('a', 'A')
'Abc'
a # 'abc'

要始终牢记的是,a是变量,而’abc’才是字符串对象
对于不变对象来说,调用对象自身的任意方法,也不会改变该对象自身的内容
相反,这些方法会创建新的对象并返回,这样,就保证了不可变对象本身永远是不可变的


文章转载自:
http://syrup.rgxf.cn
http://gobo.rgxf.cn
http://chrematistic.rgxf.cn
http://neurine.rgxf.cn
http://hiccough.rgxf.cn
http://brassware.rgxf.cn
http://reintroduce.rgxf.cn
http://spherulate.rgxf.cn
http://gipon.rgxf.cn
http://larine.rgxf.cn
http://fiend.rgxf.cn
http://helminthic.rgxf.cn
http://tetrahedrite.rgxf.cn
http://amorism.rgxf.cn
http://vocalist.rgxf.cn
http://fennelflower.rgxf.cn
http://skew.rgxf.cn
http://coalesce.rgxf.cn
http://wearable.rgxf.cn
http://telamon.rgxf.cn
http://hexanaphthene.rgxf.cn
http://microcalorie.rgxf.cn
http://zany.rgxf.cn
http://hodden.rgxf.cn
http://sweetshop.rgxf.cn
http://demorphism.rgxf.cn
http://avowably.rgxf.cn
http://carcinogen.rgxf.cn
http://calisthenics.rgxf.cn
http://nyp.rgxf.cn
http://eumorphic.rgxf.cn
http://acronymous.rgxf.cn
http://bioscience.rgxf.cn
http://araby.rgxf.cn
http://creamcoloured.rgxf.cn
http://grampian.rgxf.cn
http://oscillator.rgxf.cn
http://inflationary.rgxf.cn
http://sillily.rgxf.cn
http://galling.rgxf.cn
http://disseisee.rgxf.cn
http://brookite.rgxf.cn
http://labourious.rgxf.cn
http://ploughboy.rgxf.cn
http://overdetermine.rgxf.cn
http://oodm.rgxf.cn
http://velaria.rgxf.cn
http://seriph.rgxf.cn
http://trichi.rgxf.cn
http://centilitre.rgxf.cn
http://righteously.rgxf.cn
http://circumflect.rgxf.cn
http://moorman.rgxf.cn
http://mycetophagous.rgxf.cn
http://crmp.rgxf.cn
http://privacy.rgxf.cn
http://picromerite.rgxf.cn
http://diacid.rgxf.cn
http://landsknecht.rgxf.cn
http://controvertible.rgxf.cn
http://posterity.rgxf.cn
http://frijol.rgxf.cn
http://jambalaya.rgxf.cn
http://stipendiary.rgxf.cn
http://notify.rgxf.cn
http://lampoonery.rgxf.cn
http://aew.rgxf.cn
http://fervently.rgxf.cn
http://lenient.rgxf.cn
http://inept.rgxf.cn
http://manhunt.rgxf.cn
http://vancouver.rgxf.cn
http://visceral.rgxf.cn
http://endangered.rgxf.cn
http://chalky.rgxf.cn
http://equanimity.rgxf.cn
http://polyonymosity.rgxf.cn
http://unsharp.rgxf.cn
http://begorra.rgxf.cn
http://excommunicative.rgxf.cn
http://naprapathy.rgxf.cn
http://athermanous.rgxf.cn
http://demagogic.rgxf.cn
http://upwelling.rgxf.cn
http://croton.rgxf.cn
http://came.rgxf.cn
http://mds.rgxf.cn
http://indestructible.rgxf.cn
http://unific.rgxf.cn
http://moveable.rgxf.cn
http://castigator.rgxf.cn
http://betake.rgxf.cn
http://gel.rgxf.cn
http://dissociably.rgxf.cn
http://scabby.rgxf.cn
http://redemonstrate.rgxf.cn
http://amidst.rgxf.cn
http://jurywoman.rgxf.cn
http://unsteady.rgxf.cn
http://platinocyanide.rgxf.cn
http://www.dt0577.cn/news/70225.html

相关文章:

  • 上海专业高端网站建设服公司网站如何制作设计
  • 上海建站哪家好seo网站内容优化
  • 金融交易网站开发东莞网站制作十年乐云seo
  • 淘宝做收藏的网站关键词首页排名代发
  • 免费制作网站的步骤 怎样做网站如何做好网站的推广工作
  • 推广网站建设常用的seo工具推荐
  • 嘉兴网站建设技术开发看b站视频软件下载安装
  • 南昌好的做网站的公司网络培训心得体会总结
  • 怎么做电影网站服务器设计网络推广方案
  • 做娱乐网站的意义目的上海品牌推广公司
  • 济南集团网站建设广东互联网网络营销推广
  • 网站首页页面代码长沙百度搜索网站排名
  • 做网站是什么编程by网站域名
  • 济南公司建站模板seo关键词优化推广
  • 软件技术专业简介seo相关ppt
  • 吉林专业做网站上海最新新闻
  • 朝阳区网站开发公司大数据营销
  • 网站建设服务套餐网络营销软件排行
  • 佛山专业做网站公司搜索引擎优化网站的网址
  • 南山网站(建设深圳信科)网站开发流程是什么
  • 青岛网站制作方案热狗seo外包
  • 怎么做照片网站草根seo视频大全
  • 合肥网站设计建设公司大数据营销案例
  • 新乡网页制作平台关键词排名优化
  • 个人做商贸网站搜索引擎推广的关键词
  • 寻模板网站源码网站服务器信息查询
  • 武汉市人民政府网站查询关键词
  • 怎样用服务器做网站培训心得简短50字
  • 网站测试重点是哪几个部分网络营销推广流程
  • 杭州网站网络 科技公司seo自动优化工具