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

政府网站建设联系电话品牌营销策划公司

政府网站建设联系电话,品牌营销策划公司,腾讯云做淘客网站,dreamweaver做网站教学数据容器-----元组 定义格式,特点,相关操作 元组一旦定义,就无法修改 元组内只有一个数据,后面必须加逗号 """ #元组 (1,"hello",True) #定义元组 t1 (1,"hello") t2 () t3 tuple() prin…

数据容器-----元组

定义格式,特点,相关操作

元组一旦定义,就无法修改

元组内只有一个数据,后面必须加逗号

"""
#元组
(1,"hello",True)
#定义元组
t1 = (1,"hello")
t2 = ()
t3 = tuple()
print(f"t1的类型是{type(t1)}")
#单个元素后面需要加逗号
t4 = ("hello",)
print(f"t4的类型是{type(t4)}")
#元素的嵌套
t5 = ((1,2,3),(4,5,6))
print(f"t5的类型是{type(t5),},内容是{t5}")
#下标索引去取内容
element = t5[1][1]
print(element)
#index查找方法
t6 = ("heima","heima","hij","sda")
index = t6.index("hij")
print(f"在元组t6中查找hij,的下标是:{index}")
#元组的操作:count统计方法
num = t6.count("heima")
print(f"在元组t6中,heima的数量是{num}")t8 = ("hins","heima","heima","hij","sda")
num1 = len(t8)
print(f"t8元组中,元素的个数为{num1}")
#while循环
#for 循环遍历
t1 = (1,2,3,4,5,6)
for element in t1:print(f"t1中的元素分别为{element}")t1 = (1,2,3,4,5,6)
index = 0
while index<len(t1):print(f"t1中的元素分别为{t1[index]}")index += 1#元组不支持修改元素
t1 = (1,2,3)
t1[0]=4
print(t1)
"""
#元组内的列表内容可以修改
t2 = (1,2,3,[4,5,6,7])
t2[3][0]=8
print(t2)

t1 = ("周杰伦",11,["football","music"])
index = t1.index("周杰伦")
print(f"周杰伦年龄所在的下标位置是{index}")
name = t1[0]
print(f"该学生的姓名为{name}")
t1[2][0]=()
print(t1)
t1[2][0]="coding"
print(t1)

2.掌握字符串的常见操作

#字符串的替换
#得到的是一个新字符串而并非将原有字符串修改
my_str = "itheima and itcast"
my_str2 = my_str.replace("and","beautiful")
print(my_str2)
print(my_str)

"""
#元组
(1,"hello",True)
#定义元组
t1 = (1,"hello")
t2 = ()
t3 = tuple()
print(f"t1的类型是{type(t1)}")
#单个元素后面需要加逗号
t4 = ("hello",)
print(f"t4的类型是{type(t4)}")
#元素的嵌套
t5 = ((1,2,3),(4,5,6))
print(f"t5的类型是{type(t5),},内容是{t5}")
#下标索引去取内容
element = t5[1][1]
print(element)
#index查找方法
t6 = ("heima","heima","hij","sda")
index = t6.index("hij")
print(f"在元组t6中查找hij,的下标是:{index}")
#元组的操作:count统计方法
num = t6.count("heima")
print(f"在元组t6中,heima的数量是{num}")t8 = ("hins","heima","heima","hij","sda")
num1 = len(t8)
print(f"t8元组中,元素的个数为{num1}")
#while循环
#for 循环遍历
t1 = (1,2,3,4,5,6)
for element in t1:print(f"t1中的元素分别为{element}")t1 = (1,2,3,4,5,6)
index = 0
while index<len(t1):print(f"t1中的元素分别为{t1[index]}")index += 1#元组不支持修改元素
t1 = (1,2,3)
t1[0]=4
print(t1)#元组内的列表内容可以修改
t2 = (1,2,3,[4,5,6,7])
t2[3][0]=8
print(t2)#练习
t1 = ("周杰伦",11,["football","music"])
index = t1.index("周杰伦")
print(f"周杰伦年龄所在的下标位置是{index}")
name = t1[0]
print(f"该学生的姓名为{name}")
t1[2][0]=()
print(t1)
t1[2][0]="coding"
print(t1)my_str = "itheima and itcast"
value = my_str[0]
print(value)
value2 = my_str[-1]
print(value2)
#字符串不支持修改
my_str[0]="1"
print(my_str)#字符串的index方法
my_str = "itheima and itcast"
value = my_str.index("and")
print(f"在字符串中查找and,其起始下标是{value}")#字符串的替换
#得到的是一个新字符串而并非将原有字符串修改
my_str = "itheima and itcast"
my_str2 = my_str.replace("and","beautiful")
print(my_str2)
print(my_str)#字符串的切分
my_str = "itheima and itcast"
mystr2 = my_str.split()
print(my_str)
print(mystr2,f"类型是{type(mystr2)}")#字符串的归整操作(去前后空格)
#不传入参数,去除收尾空格
my_str = "  itheima and itcast  "
newstr = my_str.strip()
print(my_str)
print(newstr)#去除收尾指定元素
my_str = "2314itheima and itcast231"
newstr = my_str.strip("2314")
print(newstr)
#统计元素出现次数
count = my_str.count("i")
print(count)#统计长度
my_str = "2314itheima and itcast231"
length = len(my_str)
print(length)#字符串的遍历
#while
mystr = "lili is a good boy"
index = 0
while index <len(mystr):print(f"该字符串的元素为{mystr[index]}")index += 1#for循环
mystr = "lili is a good boy"
for element in mystr:print(f"该字符串的元素为{element}")
"""

mystr = "itheima itcast boxuegu"
count = mystr.count("it")
print(f"字符串中it一共有{count}个")
newstr = mystr.replace(" ","|")
print(newstr)
new2 = newstr.split("|")
print(new2)
http://www.15wanjia.com/news/1155.html

相关文章:

  • 网站改域名如何做百度优化18款禁用网站app直播
  • 绵阳建设网站优化师是干嘛的
  • 哈尔滨做网站哪里好广州网站优化运营
  • 网站做端口是什么问题中国网络优化公司排名
  • 府网站建设运维情况自查报告网页优化seo公司
  • 中国十大外贸上市公司排名百度seo是什么
  • 深圳微信网站建设公司哪家好seo技术培训宁波
  • ftp上传网站后怎么弄网络服务器图片
  • wordpress企业主题教程徐州seo推广优化
  • wp网站如何做多级联动筛选框网站推广主要是做什么
  • 东台网站开发搜索大全引擎
  • 什么网站可以注册微信支付方式网站设计制作
  • 网站导航这么做重庆百度总代理
  • 网站定制开发流程和功能seo研究中心vip课程
  • 网站备案免费的吗厦门百度推广开户
  • 移动网站建站企业网站seo排名
  • 潍坊网站建设联系方式百度快照优化
  • 做淘宝客网站会犯法吗西安百度seo推广电话
  • 网站建设与管理做什么哪个推广网站好
  • 19网站建设百度人工客服电话是多少
  • 设计师可以做兼职的网站营销策划培训
  • 浙江省一建建设集团网站首页百度搜索榜单
  • 做外贸网站如果是东西杂会不会不好推广小程序推广引流
  • 带你做网站毕设重庆seo推广
  • 怎样用文档做网站首页网站关键词优化软件
  • 湖南网站建设小公司排名seo公司多少钱
  • 武汉优化推广公司长沙靠谱seo优化价格
  • 把自己做的网站开放到外网百度下载官方下载安装
  • 如何建设网站挣钱微信推广平台
  • 做淘客网站怎么寰宇seo