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

男女做羞羞的故事网站后台管理系统模板

男女做羞羞的故事网站,后台管理系统模板,注册网站怎么注销,上海网页制作机构目录 一、字符串1.1 在字符串中使用变量 二、列表2.1 遍历列表练习题代码 2.2 列表元素的插入和删除涉及方法练习题代码 2.3 组织列表涉及方法练习题代码 2.4 索引 参考书:Python从入门到实践(第二版) 一、字符串 1.1 在字符串中使用变量 f…

目录

  • 一、字符串
    • 1.1 在字符串中使用变量
  • 二、列表
    • 2.1 遍历列表
      • 练习题
      • 代码
    • 2.2 列表元素的插入和删除
      • 涉及方法
      • 练习题
      • 代码
    • 2.3 组织列表
      • 涉及方法
      • 练习题
      • 代码
    • 2.4 索引

参考书:Python从入门到实践(第二版)

一、字符串

1.1 在字符串中使用变量

f “{ 变量名 }”

f代表format,Python把花括号里的变量名替换为其值来设置字符串的格式。(Python3.6引入)

代码示例:

first_name = input("Your first name is: ")
last_name = input("Your last name is : ")
full_name = f"{first_name} {last_name}"
print(f"My name is {full_name.title()}")

在这里插入图片描述

二、列表

2.1 遍历列表

练习题

将一些朋友的姓名存储在一个列表中,并将其命名为names 。依次访问该列表中的每个元素,从而将每个朋友的姓名打印出来。

代码

names = ['winnie','jack','lili','will','diana']
for name in names:print(f'Hello, my name is {name.title()}')
else:print("The list is overlooped")

代码解释:

  1. 使用for循环遍历列表中的所有信息
  2. 使用format字符串形式输出字符串中的变量
  3. 使用title方法对列表中的字母进行首字母大写

2.2 列表元素的插入和删除

涉及方法

  • append() : 在列表末尾添加元素
  • insert() : 在列表任意位置添加元素
  • remove() :根据具体值删除元素
  • del 语句 :删除整个列别或某一元素
  • pop() :弹出任意元素

练习题

在这里插入图片描述
在这里插入图片描述

代码

#3-4
names = ['diane','kalinda','alicia','will','peter','cary']
for name in names:print(f"Dear {name.title()}, let's have a dinner together this evening.")
num_guests = len(names)
print(f'We have invited {num_guests} guests now',)
print("\n")#3-5
print("Ops! Peter is busy with his campaign so he can't joy the dinner.\n")
names.remove('peter')
names.append('zerk')
for name in names:print(f"Dear {name.title()}, let's have a dinner together this evening.")
num_guests = len(names)
print(f'We have invited {num_guests} guests now',)
print("\n")#3-6
print("We can invite more guests now because I have found a bigger dinner table now.\n")
names.insert(0,'tom')
names.insert(int(len(names)/2),'mary')
names.append('winnie')
for name in names:print(f"Dear {name.title()}, let's have a dinner together this evening.")
num_guests = len(names)
print(f'We have invited {num_guests} guests now',)
print("\n")#3-7
print('Sorry, I can only invite 2 guests to joy the dinner.\n')
while len(names)>2:name = names.pop()print(f"Dear {name.title()}, sorry for the change, we can have dinner the next time!")
for name in names:print(f"Dear {name.title()}, you are still invited to the dinner tonight.")
del names[0]
del names[0]
print(names)

输出如下:
Dear Diane, let’s have a dinner together this evening.
Dear Kalinda, let’s have a dinner together this evening.
Dear Alicia, let’s have a dinner together this evening.
Dear Will, let’s have a dinner together this evening.
Dear Peter, let’s have a dinner together this evening.
Dear Cary, let’s have a dinner together this evening.
We have invited 6 guests now

Ops! Peter is busy with his campaign so he can’t joy the dinner.

Dear Diane, let’s have a dinner together this evening.
Dear Kalinda, let’s have a dinner together this evening.
Dear Alicia, let’s have a dinner together this evening.
Dear Will, let’s have a dinner together this evening.
Dear Cary, let’s have a dinner together this evening.
Dear Zerk, let’s have a dinner together this evening.
We have invited 6 guests now

We can invite more guests now because I have found a bigger dinner table now.

Dear Tom, let’s have a dinner together this evening.
Dear Diane, let’s have a dinner together this evening.
Dear Kalinda, let’s have a dinner together this evening.
Dear Mary, let’s have a dinner together this evening.
Dear Alicia, let’s have a dinner together this evening.
Dear Will, let’s have a dinner together this evening.
Dear Cary, let’s have a dinner together this evening.
Dear Zerk, let’s have a dinner together this evening.
Dear Winnie, let’s have a dinner together this evening.
We have invited 9 guests now

Sorry, I can only invite 2 guests to joy the dinner.

Dear Winnie, sorry for the change, we can have dinner the next time!
Dear Zerk, sorry for the change, we can have dinner the next time!
Dear Cary, sorry for the change, we can have dinner the next time!
Dear Will, sorry for the change, we can have dinner the next time!
Dear Alicia, sorry for the change, we can have dinner the next time!
Dear Mary, sorry for the change, we can have dinner the next time!
Dear Kalinda, sorry for the change, we can have dinner the next time!
Dear Tom, you are still invited to the dinner tonight.
Dear Diane, you are still invited to the dinner tonight.

2.3 组织列表

涉及方法

  • sort():对列表排序
  • sorted():对列表暂时排序,不改变原有顺序
  • reverse():翻转列表

练习题

在这里插入图片描述
在这里插入图片描述

代码

#3-8
travel = ['italy','france','america','spain','denmark']
print("original:",travel)
print("sorted:",sorted(travel))
print("after sorted:",travel)
travel.reverse()
print("reverse:",travel)
travel.reverse()
print("reverse again:",travel)
travel.sort()
print("sort:",travel)
travel.sort(reverse=True)
print("sort reverse=True:",travel)#3-9
names = ['diane','kalinda','alicia','will','peter','cary']
print("The number of guests are %d." %len(names))

在这里插入图片描述
在这里插入图片描述

2.4 索引

在这里插入图片描述
列表从前往后的下标从0开始,从后往前的下标从-1开始

http://www.yayakq.cn/news/205770/

相关文章:

  • 布吉网站建设艺术作品欣赏网站
  • 说说网站是怎样建设和推广的wordpress主题如何导入演示
  • 网站开发工程师 下载多语言网站怎么实现的
  • 网站标题关键字cc域名注册
  • 现在网站还用asp做西安做小程序的公司
  • 做资料分享网站有哪些工信部官网
  • 西安制作公司网站的公司安徽网站建设制作
  • 如何把做的网站变成链接武进做网站的公司
  • 环江住房和城乡建设部网站5星做号宿水软件的网站
  • 成都网站建设制作公司妙趣网 通辽网站建设
  • 网站评论 设计深圳网站订制开发
  • 广西建设厅关公网站小厂建网站
  • 旅游网站开发文档WordPress明月浩空
  • 南京微信网站开发软件开发工具的主要的分类方法
  • 网站开发分工手机域名解析错误
  • 海沧区建设局网站网站弹窗是怎么做的
  • 学习php网站开发怎么样seo外链工具软件
  • php 开启gzip加速网站做app网站的公司
  • 语种网站建设网站怎样制作 优帮云
  • 湛江模板建站服务商深圳高端设计公司
  • 全国企业信息公示系统查询通辽网站seo
  • 苏州 网站 建设 公司wordpress检测登录ip
  • 网站开发的最后5个阶段网店运营推广初级实训系统答案
  • 旅游网站wordpresswordpress引用视频
  • 北京网站制作设计宁河网站建设
  • 更改wordpress程序站点网址郑州做公司网站的
  • wordpress网站怎么打开17网站一起做网店增城
  • 企业网站推广的方法有( )跑腿网站建设
  • 什么样的水平可以做网站网站服务器备案
  • 怎么上传软件到网站正规建筑工程网站