博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 打印列表元素_Python程序以不同方式打印列表元素
阅读量:2531 次
发布时间:2019-05-11

本文共 1853 字,大约阅读时间需要 6 分钟。

python 打印列表元素

In this program – we are going to learn how can we print all list elements, print specific elements, print a range of the elements, print list multiple times (using * operator), print multiple lists by concatenating them, etc.

在此程序中,我们将学习如何打印所有列表元素 ,打印特定元素,打印元素范围,多次打印列表(使用*运算符),通过将它们串联来打印多个列表,等等。

Syntax to print list in different ways:

以不同方式打印列表的语法:

print (list)          	# printing complete list    print (list[i])       	# printing ith element of list    print (list[i], list[j])	# printing ith and jth elements    print (list[i:j])     	# printing elements from ith index to jth index    print (list[i:])      	# printing all elements from ith index    print (list * 2)  		# printing list two times    print (list1 + list2) 	# printing concatenated list1 & list2

Python代码打印列表元素 (Python code to print list elements )

Here, we have two lists list1 and list2 with some of the elements (integers and strings), we are printing elements in the different ways.

在这里,我们有两个列表list1和list2 ,其中包含一些元素(整数和字符串),我们以不同的方式打印元素。

# python program to demonstrate example of lists# declaring & initializing two listlist1 = ["Amit", "Abhi", "Radib", 21, 22, 37]list2 = [100, 200, "Hello", "World"]print (list1)          		# printing complete list1print (list1[0])       		# printing 0th (first) element of list1print (list1[0], list1[1])	# printing first & second elementsprint (list1[2:5])     		# printing elements from 2nd to 5th indexprint (list1[1:])      		# printing all elements from 1st indexprint (list2 * 2)  		# printing list2 two timesprint (list1 + list2) 		# printing concatenated list1 & list2

Output

输出量

['Amit', 'Abhi', 'Radib', 21, 22, 37]AmitAmit Abhi['Radib', 21, 22]['Abhi', 'Radib', 21, 22, 37][100, 200, 'Hello', 'World', 100, 200, 'Hello', 'World']['Amit', 'Abhi', 'Radib', 21, 22, 37, 100, 200, 'Hello', 'World']

翻译自:

python 打印列表元素

转载地址:http://yyxzd.baihongyu.com/

你可能感兴趣的文章
mysql中间件研究(tddl atlas cobar sharding-jdbc)
查看>>
Cast-128 加密算法和 MyPassWord 的破解
查看>>
4.28下午 听力611
查看>>
ActiveMQ学习笔记(1)----初识ActiveMQ
查看>>
Java与算法之(2) - 快速排序
查看>>
Windows之IOCP
查看>>
机器学习降维之主成分分析
查看>>
CTP2交易所成交回报
查看>>
WebSocket & websockets
查看>>
《机器学习实战》学习笔记第二章 —— K-近邻算法
查看>>
uni-app 引入本地iconfont的正确姿势以及阿里图标引入
查看>>
DSB
查看>>
Java中的阻塞队列
查看>>
前端软件sublime的一些常用快捷键
查看>>
openssl 升级
查看>>
2017.10.30 天晴 昨天十公里没减肥
查看>>
Git 打标签(分布式版本控制系统)
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>