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

建设网站的必要与可行性seo技巧优化

建设网站的必要与可行性,seo技巧优化,自做衣服网站,湛江专业建网站哪家好目录 1、使用bool判断某一数据类型是否为空 2、Python集合(数组) 1、列表 2、元组 3、集合 4、字典 1、使用bool判断某一数据类型是否为空 如果有某种内容,则几乎所有值都将评估为 True。 除空字符串外,任何字符串均为 Tr…

目录

1、使用bool判断某一数据类型是否为空

2、Python集合(数组)

1、列表

2、元组

3、集合

4、字典


1、使用bool判断某一数据类型是否为空

如果有某种内容,则几乎所有值都将评估为 True。

除空字符串外,任何字符串均为 True。

除 0 外,任何数字均为 True。

除空列表外,任何列表、元组、集合和字典均为 True。

实际上,除空值(例如 ()、[]、{}、""、数字 0 和值 None)外,没有多少值会被评估为 False。当

然,值 False 的计算结果为 False。

print(bool());           # false
print(bool(0))           # false
print(bool(""))          # 空字符串,false
print(bool("abc"))       # true
print(bool(123))         # true
print(bool(["apple", "cherry", "banana"]))   # true
bool(False)              # false
bool(None)               # false
bool(())                 # false
bool([])                 # false
bool({})                 # false

所以要是判断字符串是否为空,还可以使用bool类型进行判断?当然可以,而不必使用len(x)进行判断。

2、Python集合

Python 编程语言中有四种集合数据类型:

  • 列表(List)是一种有序、有索引、可更改的集合。允许重复的成员。
  • 元组(Tuple)是一种有序、有索引、不可更改的集合。允许重复的成员。
  • 词典(Dictionary)是一个无序、有索引、可更改的集合。没有重复的成员
  • 集合(Set)是一个无序、无索引、可更改的集合。没有重复的成员。
  • 如果四种集合类型有索引,那么可以根据索引进行数据修改、返回索引号对应的值或者对集合进行切片操作
  • 可更改和不可更改体现在对四种集合数据类型是否可以使用内建方法进行增、删、改、查等操作
  • 虽然元组是不可变的,但是元组可以包含可变对象,比如一个元组中可以包含一个列表。虽然元组本身不可以修改,但是列表中的元素是可以修改的
  • 有序的数据类型可以按照固定的顺序进行排序,而无序的数据类型没有固定的顺序,因此无法进行排序。无序的数据类型也不能直接比较大小,因为它没有固定的顺序。 使用排序算法对无序数据类型进行排序,需要将其转换为有序数据类型,如将无序集合转换为有序列表,然后对列表进行排序。但是这种方法只是对整个数据类型进行排序,而不是对其中的每个元素进行排序。 需要注意的是,有些数据类型虽然是有序的,但是不能进行排序,如 Python 中的元组。元组中的元素虽然有固定的顺序,但是由于元组中的元素类型可以是不同的,因此无法进行排序

1、列表(数组)

说白了就是其他语言中的数组,只不过python中的这个数组功能太强大

#———————————负索引表示从末尾开始,-1 表示最后一个项目,-2 表示倒数第二个项目,依此类推。thislist = ["apple", "banana", "cherry"]print(thislist[-1])    # 打印cherry#———————————此例将返回从索引 -4(包括)到索引 -1(排除)的项目thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]print(thislist[-4:-1])    # ['orange', 'kiwi', 'melon']#———————————使用正向索引对列表进行切片操作,返回一个新的列表thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]# 正向索引切片操作时和字符串一样,不包括最后一个索引位置的数据print(thislist[2:5])   # ['cherry', 'orange', 'kiwi']#———————————使用索引号修改列表中对应位置中的数据thislist = ["apple", "banana", "cherry"]thislist[1] = "mango"print(thislist)   # ['apple', 'mango', 'cherry']#———————————使用 in 检查列表中是否有该数据thislist = ["apple", "banana", "cherry"]if "apple" in thislist:print("Yes, 'apple' is in the fruits list")#———————————使用len(x)返回当前列表中的数据长度thislist = ["apple", "banana", "cherry"]print(len(thislist))      # 3#———————————使用循环的方法把 list2 追加到 list1 的末尾中list1 = ["a", "b" , "c"]list2 = [1, 2, 3]for x in list2:list1.append(x)      print(list1)   # ['a', 'b', 'c', 1, 2, 3]#———————————当然还可以使用extend() 方法将 list2 添加到 list1 的末尾list1.extend(list2)print(list1)   # ['a', 'b', 'c', 1, 2, 3]#———————————使用list() 构造函数创建列表thislist = list(("apple", "banana", "cherry"))print(thislist)   #['apple', 'banana', 'cherry']

列表中常使用的内建方法如下表,直接使用 变量名.方法调用即可

append()在列表的末尾添加一个元素
clear()删除列表中的所有元素
copy()返回列表的副本
count()返回具有指定值的元素数量。
extend()将列表元素(或任何可迭代的元素)添加到当前列表的末尾
index()返回具有指定值的第一个元素的索引
insert()在指定位置添加元素
pop()删除指定位置的元素
remove()删除具有指定值的项目
reverse()颠倒列表的顺序
sort()对列表进行排序

2、元组

元组和列表的操作基本一样,根据索引号取值、使用正负索引号对元组进行切片操作并返回一个新的元组、使用len(x)返回元组中数据的长度、使用in判断是否存在某一数据都可行。但是唯一不同的是由于元组是一个不可更改的集合,所以凡事想要修改元组的操作是不可行的。

并且,虽然元组是不可更改的,但是可以完全删除元组

thistuple = ("apple", "banana", "cherry")del thistuple    # 删除元组,列表等其他集合数据类型都可以使用print(thistuple) # 这会引发错误,因为元组已不存在

使用 + 运算符 合并两个元组(返回的是一个新元组,并没有对之前的元组做出修改)

tuple1 = ("a", "b" , "c")tuple2 = (1, 2, 3)tuple3 = tuple1 + tuple2print(tuple3)   # 打印('a', 'b', 'c', 1, 2, 3)

由于元组中的数据是不可更改的,所以在元组中必然不存在增、删、改、查等操作。只有下面两种

count()返回元组中指定值出现的次数。
index()在元组中搜索指定的值并返回它被找到的位置。

3、集合

在 Python 中,集合用花括号编写

由于没有索引的特性,所以不能进行切片操作或者根据索引值返回对应数据

但是可以使用使用for循环遍历取值

thisset = {"apple", "banana", "cherry"}for x in thisset:print(x)

可以判断集合中是否存在某一元素值

thisset = {"apple", "banana", "cherry"}print("banana" in thisset)

下面是集合中常用的内建方法

add()向集合添加元素。
clear()删除集合中的所有元素。
copy()返回集合的副本。
difference()返回包含两个或更多集合之间差异的集合。
difference_update()删除此集合中也包含在另一个指定集合中的项目。
discard()删除指定项目。
intersection()返回为两个其他集合的交集的集合。
intersection_update()删除此集合中不存在于其他指定集合中的项目。
isdisjoint()返回两个集合是否有交集。
issubset()返回另一个集合是否包含此集合。
issuperset()返回此集合是否包含另一个集合。
pop()从集合中删除一个元素。
remove()删除指定元素。
symmetric_difference()返回具有两组集合的对称差集的集合。
symmetric_difference_update()插入此集合和另一个集合的对称差集。
union()返回包含集合并集的集合。
update()

4、字典

字典是一个无序、可变和有索引的集合。在 Python 中,字典用花括号编写,拥有键和值。

#————————————————创建并打印字典thisdict =	{"brand": "Porsche","model": "911","year": 1963
}
print(thisdict)    # {'brand': 'Porsche', 'model': '911', 'year': 1963}#————————————————获取 "model" 键的值x = thisdict["model"]x = thisdict.get("model")  # 911#————————————————把 "year" 改为 2019thisdict["year"] = 2019print(thisdict)   #{'brand': 'Porsche', 'model': '911', 'year': 2019}#————————————————逐个打印字典中的所有键名for x in thisdict:print(x)   #brand 、model、year#————————————————逐个打印字典中的所有值for x in thisdict:print(thisdict[x])     # Porsche、911、1963#————————————————还可以使用 values() 函数返回字典的值for x in thisdict.values():print(x)    # Porsche、911、1963#————————————————通过使用 items() 函数遍历键和值for x, y in thisdict.items():print(x, y)# brand Porsche
# model 911
# year 1963

还有使用in判断是否存在某一键值对、使用len(x)判断词典的长度等方法

通过使用新的索引键并为其赋值,可以将项目添加到字典中

# 通过使用新的索引键并为其赋值,可以将项目添加到字典中
thisdict =	{"brand": "Porsche","model": "911","year": 1963
}
thisdict["color"] = "red"
print(thisdict)    # {'brand': 'Porsche', 'model': '911', 'year': 1963, 'color': 'red'}

del 关键字删除具有指定键名的项目(使用del thisdict也可以完全删除字典)

thisdict =	{"brand": "Porsche","model": "911","year": 1963
}
del thisdict["model"]
print(thisdict)      # {'brand': 'Porsche', 'year': 1963}

词典也可以包含许多词典,这被称为嵌套词典(套娃的形式),有点类似于C中的结构体嵌套

child1 = {"name" : "Phoebe Adele","year" : 2002
}
child2 = {"name" : "Jennifer Katharine","year" : 1996
}
child3 = {"name" : "Rory John","year" : 1999
}myfamily = {"child1" : child1,"child2" : child2,"child3" : child3
}print(myfamily)

C:\Users\My Name>python python_dictionary_nested_2.py
{'child1': {'name': 'Phoebe Adele', 'year': 2002}, 'child2': {'name': 'Jennifer Katharine', 'year': 1996}, 'child3': {'name': 'Rory John', 'year': 1999}}

也可以使用 dict() 构造函数创建新的字典

thisdict = dict(brand="Porsche", model="911", year=1963)
# 请注意,关键字不是字符串字面量
# 请注意,使用了等号而不是冒号来赋值
print(thisdict)

下面是词典中常用的内建方法

clear()删除字典中的所有元素
copy()返回字典的副本
fromkeys()返回拥有指定键和值的字典
get()返回指定键的值
items()返回包含每个键值对的元组的列表
keys()返回包含字典键的列表
pop()删除拥有指定键的元素
popitem()删除最后插入的键值对
setdefault()返回指定键的值。如果该键不存在,则插入具有指定值的键。
update()使用指定的键值对字典进行更新
values()

文章转载自:
http://gauger.nrwr.cn
http://pervasive.nrwr.cn
http://courtship.nrwr.cn
http://casita.nrwr.cn
http://unpersuaded.nrwr.cn
http://indanthrene.nrwr.cn
http://presternum.nrwr.cn
http://chin.nrwr.cn
http://archaize.nrwr.cn
http://svga.nrwr.cn
http://homestay.nrwr.cn
http://transpirable.nrwr.cn
http://dacquoise.nrwr.cn
http://hiplength.nrwr.cn
http://frangible.nrwr.cn
http://syntactical.nrwr.cn
http://wooly.nrwr.cn
http://ramous.nrwr.cn
http://fighter.nrwr.cn
http://leveling.nrwr.cn
http://paralexia.nrwr.cn
http://vitalise.nrwr.cn
http://unpopular.nrwr.cn
http://putschism.nrwr.cn
http://four.nrwr.cn
http://comitadji.nrwr.cn
http://calculation.nrwr.cn
http://sector.nrwr.cn
http://mislike.nrwr.cn
http://defibrillate.nrwr.cn
http://troublemaker.nrwr.cn
http://vernally.nrwr.cn
http://endomysium.nrwr.cn
http://tristimulus.nrwr.cn
http://rainbarrel.nrwr.cn
http://export.nrwr.cn
http://month.nrwr.cn
http://emplace.nrwr.cn
http://igraine.nrwr.cn
http://alacrity.nrwr.cn
http://reseat.nrwr.cn
http://pyrimethamine.nrwr.cn
http://counterbattery.nrwr.cn
http://disintegrate.nrwr.cn
http://diviner.nrwr.cn
http://fraise.nrwr.cn
http://ploughboy.nrwr.cn
http://purplish.nrwr.cn
http://polymasty.nrwr.cn
http://edemata.nrwr.cn
http://tad.nrwr.cn
http://gravettian.nrwr.cn
http://kiswahili.nrwr.cn
http://sicklemia.nrwr.cn
http://aspca.nrwr.cn
http://magazine.nrwr.cn
http://pinwale.nrwr.cn
http://zif.nrwr.cn
http://gilder.nrwr.cn
http://glossal.nrwr.cn
http://slice.nrwr.cn
http://haystack.nrwr.cn
http://toponymy.nrwr.cn
http://jemmy.nrwr.cn
http://luxuriant.nrwr.cn
http://beneficiary.nrwr.cn
http://babiche.nrwr.cn
http://mimical.nrwr.cn
http://unclubbable.nrwr.cn
http://asphyxy.nrwr.cn
http://porcino.nrwr.cn
http://nap.nrwr.cn
http://deportation.nrwr.cn
http://viniculture.nrwr.cn
http://salade.nrwr.cn
http://corrodent.nrwr.cn
http://alpinist.nrwr.cn
http://aspishly.nrwr.cn
http://physiotherapy.nrwr.cn
http://count.nrwr.cn
http://microbar.nrwr.cn
http://gelt.nrwr.cn
http://uncio.nrwr.cn
http://ceres.nrwr.cn
http://desmotropy.nrwr.cn
http://pole.nrwr.cn
http://gala.nrwr.cn
http://braciola.nrwr.cn
http://pooch.nrwr.cn
http://reaction.nrwr.cn
http://pyroclastic.nrwr.cn
http://amylene.nrwr.cn
http://mabe.nrwr.cn
http://acetaldehydase.nrwr.cn
http://benignant.nrwr.cn
http://aftertax.nrwr.cn
http://housewife.nrwr.cn
http://oligarch.nrwr.cn
http://abstinency.nrwr.cn
http://expulsive.nrwr.cn
http://www.dt0577.cn/news/127167.html

相关文章:

  • wordpress做的网站吗40个免费靠谱网站
  • wordpress 评论api秦皇岛网站seo
  • 深圳找工作的网站收录优美图片手机版
  • 做网站需要哪些步骤2022年国际十大新闻
  • 建设一个网站需要哪些软硬件条件代刷网站推广链接免费
  • 手机微网站开发关键词优化工具有哪些
  • 正规网站备案代理潍坊网站开发公司
  • 企业展厅数字多媒体宁波优化推广找哪家
  • 新乡网站推广网络营销推广的目的
  • 网站备案可以变更吗惠州seo排名收费
  • 销售公司做网站关键词排名优化技巧
  • 慈溪网站制作哪家最便宜东莞网站建设最牛
  • 高校专业建设网站个人网页制作成品欣赏
  • 网站外链作用优化大师班级
  • 网页导航网站设计网络推广有几种方法
  • 广州 网站建设模板国家职业技能培训平台
  • 外贸企业网站红色风格网站推广广告
  • wordpress取消副标题绍兴seo推广
  • 网站如何布局设计网络推广服务费
  • 做跨境电商在什么网站选品找回今日头条
  • 太原网站建设电话网络营销是学什么
  • 免费做试卷的网站百度经验
  • java企业网站网络营销的特点不包括
  • 济南网站建设599上海关键词优化方法
  • 无锡市建设安全监督网站网络营销渠道有哪几种
  • 律师怎样做网站百度竞价开户哪家好
  • 提供网站制作公司国外域名注册
  • mvc网站开发视频教程项目推广网站
  • 企业建立网站的必要性铜川网站seo
  • wordpress 安装模板seo培训赚钱