首页 > 编程语言 > 详细

Python-小练习-初学

时间:2021-04-10 22:40:42      阅读:22      评论:0      收藏:0      [点我收藏+]

‘‘‘
练习:
1、使用循环输出list中的每个元素的索引和元素
2、输出list中除第一个元素以外的其他元素
‘‘‘

-------------------------------------------------------------------------------------------------------------------

# 10循环.py
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = ‘小袋袋‘

 

i = 0
index = 0
nums = [11, 4, 3, 23, 64, 2, 236, 8]
while i < len(nums):
  print(‘[‘ + str(index) + ‘]‘ + str(nums[index]), end = ‘\n‘)
  index += 1
  i += 1
print()

index = 1
while index < (len(nums) - 1):
  print(nums[index], end =‘,‘)
  index += 1
print(nums[index])
print()

 

------------------------------------------------------------------------------------------------------------------------

【运行结果:】

[0]11
[1]4
[2]3
[3]23
[4]64
[5]2
[6]236
[7]8

4,3,23,64,2,236,8

[Finished in 0.1s]

 

Python-小练习-初学

原文:https://www.cnblogs.com/daiyiqin/p/14641567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!