Python의 목록 및 튜플 사용법 정의에 대한 자세한 설명
이 글은 주로 파이썬 리스트와 튜플의 정의와 사용법을 소개하고, 파이썬에서 리스트와 튜플의 기능, 차이점, 정의, 사용법을 예제 형식으로 분석해 도움이 필요한 친구들이 참고할 수 있습니다
이 글에서는 예제 Python 목록과 튜플의 정의와 사용을 이해합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다:
#coding=utf8 print ''''' 可以将列表和元组当成普通的“数组”,它能保存任意数量任意类型的Python对象。 列表和元组通过数字索引来访问元素(从0开始)。 列表和元组的区别: ------------------------------------------------------------------------------------ 元组 \ 列表 ------------------------------------------------------------------------------------ 列表元素用中括号[] \ 元组元素用小括号() 元素的个数及元素的值可以改变 \ 元素的个数及元素的值不可改变 ------------------------------------------------------------------------------------ 元组可以看出只读的列表。 列表和元组可以通过使用索引运算符([])和切片运算符([:])可以得到子集 ''' NumberList=[1,2,3,4,5,6,7,8.9,0101,017,0xab] StringList=['hello',"hello world",'''''goddness'''] MixList=[12,13.2,01,'abc','hello'] NumberTouple=(1,2,3,4,5,6,7,8.9,0101,017,0xab) StringTouple=('hello',"hello world",'''''goddness''') MixTouple=(12,13.2,01,'abc','hello') print "output the element of the NumberList by index--------->",NumberList[0],NumberList[1],NumberList[2],NumberList[-1] print "output the element of the StringList by index--------->",StringList[0],StringList[1],StringList[2],StringList[-1] print "output the element of the MixList by index--------->",MixList[0],MixList[1],MixList[2],MixList[-1] print "output the element of the NumberTouple by index--------->",NumberTouple[0],NumberTouple[1],NumberTouple[2],NumberTouple[-1] print "output the element of the StringTouple by index--------->",StringTouple[0],StringTouple[1],StringTouple[2],StringTouple[-1] print "output the element of the MixTouple by index--------->",MixTouple[0],MixTouple[1],MixTouple[2],MixTouple[-1] print "output the element of the NumberList by slice--------->",NumberList[0:2],NumberList[1:3],NumberList[0:],NumberList[:-1] print "output the element of the StringList by slice--------->",StringList[0:1],StringList[2:3],StringList[0:],StringList[:-1] print "output the element of the MixList by slice--------->",MixList[0:],MixList[:1],MixList[0:2],MixList[2:-1] print "output the element of the NumberTouple by slice--------->",NumberTouple[0:2],NumberTouple[1:3],NumberTouple[2:],NumberTouple[:-1] print "output the element of the StringTouple by slice--------->",StringTouple[0:2],StringTouple[1:3],StringTouple[2],StringTouple[-1] print "output the element of the MixTouple by slice--------->",MixTouple[0:],MixTouple[1:3],MixTouple[2],MixTouple[:-1] NumberList[0]=59 #NumberTouple[0]=56 print "Change the value of NumberList[0] to 59------------",NumberList[0] #print "Can not change the value of NumberTouple[0] to 56------------",NumberTouple[0]
실행 결과:
위 내용은 Python의 목록 및 튜플 사용법 정의에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Python의 Pandas 라이브러리를 사용할 때는 구조가 다른 두 데이터 프레임 사이에서 전체 열을 복사하는 방법이 일반적인 문제입니다. 두 개의 dats가 있다고 가정 해

파이썬 프로그래밍에서 Python 매개 변수 주석의 대체 사용법, 매개 변수 주석은 개발자가 기능을 더 잘 이해하고 사용하는 데 도움이되는 매우 유용한 기능입니다 ...

Python 스크립트는 특정 위치에서 Cursor 위치로 출력을 어떻게 제거합니까? Python 스크립트를 작성할 때 이전 출력을 커서 위치로 지우는 것이 일반적입니다 ...

내 코드가 API에 의해 데이터를 반환 할 수없는 이유는 무엇입니까? 프로그래밍에서 우리는 종종 API가 호출 될 때 NULL 값을 반환하는 문제를 겪는 경우가 종종 있습니다.

Uvicorn은 HTTP 요청을 어떻게 지속적으로 듣습니까? Uvicorn은 ASGI를 기반으로 한 가벼운 웹 서버입니다. 핵심 기능 중 하나는 HTTP 요청을 듣고 진행하는 것입니다 ...

파이썬에서 문자열을 통해 객체를 동적으로 생성하고 메소드를 호출하는 방법은 무엇입니까? 특히 구성 또는 실행 해야하는 경우 일반적인 프로그래밍 요구 사항입니다.

Go 또는 Rust를 사용하여 Python 스크립트를 호출하여 실제 병렬 실행을 달성하는 방법은 무엇입니까? 최근에 나는 파이썬을 사용하고 있습니다 ...

Python Binary Library (.WHL) 다운로드 방법은 Windows 시스템에 특정 라이브러리를 설치할 때 많은 Python 개발자가 겪는 어려움을 탐구합니다. 일반적인 해결책 ...
