Các kiểu dữ liệu được sử dụng để xác định loại dữ liệu mà một vị trí bộ nhớ có thể chứa và các thao tác liên quan để xử lý dữ liệu đó. Dữ liệu mà chúng ta xử lý trong các chương trình của mình có thể thuộc nhiều loại như ký tự, số nguyên, số thực, chuỗi, boolean, v.v. do đó các ngôn ngữ lập trình bao gồm Python cung cấp các cách thức và phương tiện để xử lý tất cả các loại dữ liệu khác nhau này thông qua các loại dữ liệu. Các kiểu dữ liệu xác định khả năng xử lý một loại dữ liệu cụ thể, chẳng hạn như không gian bộ nhớ được phân bổ để chứa một loại dữ liệu nhất định và phạm vi giá trị được hỗ trợ cho một loại dữ liệu nhất định, v.v.
Các kiểu dữ liệu là phân loại hoặc phân loại các mục dữ liệu. Nó đại diện cho loại giá trị cho biết những thao tác nào có thể được thực hiện trên một dữ liệu cụ thể. Vì mọi thứ đều là đối tượng trong lập trình Python, nên kiểu dữ liệu thực chất là các lớp và biến là thể hiện [đối tượng] của các lớp này
Sau đây là kiểu dữ liệu tiêu chuẩn hoặc tích hợp sẵn của Python
Trong Python, kiểu dữ liệu số đại diện cho dữ liệu có giá trị số. Giá trị số có thể là số nguyên, số thực hoặc thậm chí là số phức. Các giá trị này được định nghĩa là lớp
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life3,
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life4 và lớp
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life5 trong Python
- Số nguyên - Giá trị này được biểu thị bằng lớp int. Nó chứa các số nguyên dương hoặc âm [không có phân số hoặc số thập phân]. Trong Python không có giới hạn về thời lượng một giá trị số nguyên có thể
- Float – Giá trị này được đại diện bởi lớp float. Nó là một số thực với biểu diễn dấu phẩy động. Nó được chỉ định bởi một dấu thập phân. Theo tùy chọn, ký tự e hoặc E theo sau là số nguyên dương hoặc âm có thể được thêm vào để chỉ định ký hiệu khoa học
- Số phức – Số phức được biểu diễn bằng lớp phức. Nó được chỉ định là [phần thực] + [phần ảo]j. Ví dụ – 2+3j
Lưu ý – Hàm
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life6 dùng để xác định kiểu của kiểu dữ liệu
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life7
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life8
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s0
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______7_______5
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6_______7_______7_______7_______8
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]0_______7_______1
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______17_______5
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6_______7_______7
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]8
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks0_______7_______1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks3
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______27_______7
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6_______7_______7
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]0
đầu ra
Type of a: Type of b: Type of c:Loại trình tự
Trong Python, chuỗi là tập hợp có thứ tự các kiểu dữ liệu giống hoặc khác nhau. Sequences cho phép lưu trữ nhiều giá trị một cách có tổ chức và hiệu quả. Có một số loại trình tự trong Python –
1] Chuỗi
Trong Python, Chuỗi là mảng byte đại diện cho các ký tự Unicode. Chuỗi là tập hợp của một hoặc nhiều ký tự được đặt trong một trích dẫn đơn, trích dẫn kép hoặc trích dẫn ba. Trong python không có kiểu dữ liệu ký tự, ký tự là một chuỗi có độ dài một. Nó được đại diện bởi lớp
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]1
Tạo chuỗi
Các chuỗi trong Python có thể được tạo bằng cách sử dụng dấu ngoặc đơn hoặc dấu ngoặc kép hoặc thậm chí là dấu ngoặc kép
Python3
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]2
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]3
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]5
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]6
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]7_______7_______1
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______50_______2
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______50_______5
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
First element of tuple 1 Last element of tuple 5 Third last element of tuple 37
First element of tuple 1 Last element of tuple 5 Third last element of tuple 38
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]7_______7_______1
1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______59_______4
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______50_______5
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s7
Traceback [most recent call last]: File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in print[type[true]] NameError: name 'true' is not defined1
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
First element of tuple 1 Last element of tuple 5 Third last element of tuple 37
Traceback [most recent call last]: File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in print[type[true]] NameError: name 'true' is not defined4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]7_______7_______1
Traceback [most recent call last]: File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in print[type[true]] NameError: name 'true' is not defined7
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial blank Set: set[] Set with the use of String: {'F', 'o', 'G', 's', 'r', 'k', 'e'} Set with the use of List: {'Geeks', 'For'} Set with the use of Mixed Values {1, 2, 4, 6, 'Geeks', 'For'}0
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______50_______5
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s7
Traceback [most recent call last]: File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in print[type[true]] NameError: name 'true' is not defined1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial blank Set: set[] Set with the use of String: {'F', 'o', 'G', 's', 'r', 'k', 'e'} Set with the use of List: {'Geeks', 'For'} Set with the use of Mixed Values {1, 2, 4, 6, 'Geeks', 'For'}9
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life00
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]7_______7_______1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life03
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life04____0_______05
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life04____0_______07
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______10
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______50_______5
đầu ra
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life
Truy cập các phần tử của String
Trong Python, có thể truy cập các ký tự riêng lẻ của Chuỗi bằng cách sử dụng phương thức Lập chỉ mục. Lập chỉ mục cho phép các tham chiếu địa chỉ phủ định truy cập các ký tự từ phía sau Chuỗi, e. g. -1 đề cập đến ký tự cuối cùng, -2 đề cập đến ký tự cuối cùng thứ hai, v.v.
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life14
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life15
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]7_______7_______1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life19
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______22
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______50_______5
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life27
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______30
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______0_______33
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life34
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life37
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______40
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______0_______33
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life44
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
đầu ra
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s
Lưu ý – Để biết thêm về chuỗi, hãy tham khảo Chuỗi Python
2] Danh sách
Danh sách cũng giống như mảng, được khai báo bằng các ngôn ngữ khác là tập hợp dữ liệu có thứ tự. Nó rất linh hoạt vì các mục trong danh sách không cần phải cùng loại
Tạo danh sách
Danh sách trong Python có thể được tạo bằng cách đặt chuỗi bên trong dấu ngoặc vuông_______0_______47
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life48
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life49
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life51
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life54
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______57
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life64
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life65
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life69
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life70
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______73
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life80
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life81
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68_______0_______85_______7_______6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life87
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85_______0_______70
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______93
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life34
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s00
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s08
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s09
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s12_______7_______13_______7_______6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s15
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s16
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s18
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s21
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
đầu ra
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]
Truy cập các phần tử của Danh sách
Để truy cập các mục danh sách, hãy tham khảo số chỉ mục. Sử dụng toán tử chỉ mục
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s27 để truy cập một mục trong danh sách. Trong Python, các chỉ mục chuỗi âm biểu thị các vị trí từ cuối mảng. Thay vì phải tính phần bù như trong
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s28, chỉ cần viết
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s29 là đủ. Lập chỉ mục phủ định có nghĩa là bắt đầu từ cuối, -1 đề cập đến mục cuối cùng, -2 đề cập đến mục cuối cùng thứ hai, v.v.
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life48
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s31
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life80
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life81
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68_______0_______85_______7_______6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life87
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85_______0_______70
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s45
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s46
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______7_______49
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life34
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s00
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s64
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s68
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s71
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life44
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s80
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life52
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life44
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s86
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
đầu ra
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks
Lưu ý - Để biết thêm về Danh sách, hãy tham khảo Danh sách Python
3] Bộ ba
Cũng giống như danh sách, bộ dữ liệu cũng là một tập hợp các đối tượng Python có thứ tự. Sự khác biệt duy nhất giữa bộ dữ liệu và danh sách là bộ dữ liệu là bất biến. e. bộ dữ liệu không thể được sửa đổi sau khi nó được tạo. Nó được đại diện bởi lớp
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s88
Tạo Tuple
Trong Python, các bộ dữ liệu được tạo bằng cách đặt một chuỗi các giá trị được phân tách bằng 'dấu phẩy' có hoặc không sử dụng dấu ngoặc đơn để nhóm chuỗi dữ liệu. Các bộ dữ liệu có thể chứa bất kỳ số lượng phần tử nào và của bất kỳ kiểu dữ liệu nào [như chuỗi, số nguyên, danh sách, v.v. ]
Ghi chú. Các bộ dữ liệu cũng có thể được tạo bằng một phần tử duy nhất, nhưng hơi phức tạp một chút. Có một phần tử trong ngoặc là không đủ, phải có dấu 'dấu phẩy' ở cuối để biến nó thành một bộ
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life48
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s90
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s92
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s93______7_______1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s95
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______7_______98
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]01
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]03
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]04
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s93_______7_______1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13_______7_______6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s15
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]14
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______17_______01
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]19
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]20
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]21
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life68
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45_______7_______6
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]28
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]32
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life70
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]36
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s88
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]41
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]43
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]44
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s93_______7_______1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s88
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]53
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______17_______01
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]58
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]59
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s93_______7_______1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4_______0_______34_______7_______6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s86
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]71
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]74
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]76
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]78
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]80
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]83
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______17_______86
đầu ra
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]
Lưu ý - Việc tạo bộ dữ liệu Python mà không sử dụng dấu ngoặc đơn được gọi là Đóng gói bộ dữ liệu
Truy cập các phần tử của Tuple
Để truy cập các mục Tuple, hãy tham khảo số chỉ mục. Sử dụng toán tử chỉ mục
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s27 để truy cập một mục trong bộ dữ liệu. Chỉ số phải là một số nguyên. Các bộ dữ liệu lồng nhau được truy cập bằng cách sử dụng chỉ mục lồng nhau
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life7
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]89
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]91
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s88
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]94
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s86
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]28
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s2
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks04
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks06
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______27_______09
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks10
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______12
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life34
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks04
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks16
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks17
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks20
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks10
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______12
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life44
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks04
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______27_______30
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks10
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______12
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life44
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s86
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks04
đầu ra
First element of tuple 1 Last element of tuple 5 Third last element of tuple 3
Lưu ý - Để biết thêm về các bộ dữ liệu, hãy tham khảo Python Tuples
BooleanLoại dữ liệu có một trong hai giá trị tích hợp sẵn,
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks37or
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks38. Các đối tượng Boolean bằng True là đúng [đúng] và những đối tượng bằng Sai là sai [sai]. Nhưng các đối tượng không phải Boolean cũng có thể được đánh giá trong ngữ cảnh Boolean và được xác định là đúng hay sai. Nó được ký hiệu là lớp
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks39
Lưu ý - Đúng và Sai với chữ 'T' và 'F' viết hoa là các phép toán hợp lệ nếu không python sẽ báo lỗi
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life7
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks41
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______7_______7
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4_______27_______37
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks48
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______7_______7
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4_______27_______38
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks48
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s7
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks59
đầu ra
Traceback [most recent call last]: File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in print[type[true]] NameError: name 'true' is not definedBộ
Trong Python, Set là một tập hợp kiểu dữ liệu không có thứ tự, có thể lặp lại, có thể thay đổi và không có phần tử trùng lặp. Thứ tự các phần tử trong một tập hợp không xác định mặc dù nó có thể bao gồm nhiều phần tử khác nhau
Tạo bộ
Có thể tạo các bộ bằng cách sử dụng hàm
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks60 tích hợp với một đối tượng có thể lặp lại hoặc một chuỗi bằng cách đặt chuỗi bên trong dấu ngoặc nhọn, được phân tách bằng 'dấu phẩy'. Loại phần tử trong một tập hợp không nhất thiết phải giống nhau, các giá trị loại dữ liệu hỗn hợp khác nhau cũng có thể được chuyển đến tập hợp
Python3
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life48
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks62
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks64
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks67
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s95
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______27_______71
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______74
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks76
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life65
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks67
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s4
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life19
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______27_______86
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______74
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks91
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks92
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks67
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]94
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life87
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______37_______05
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______74
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life9
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks76
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]11
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]12
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks67
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]94
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks2
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]28
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s15
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]32_______7_______6_______7_______13_______0_______35
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______37_______33
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______74
đầu ra
Initial blank Set: set[] Set with the use of String: {'F', 'o', 'G', 's', 'r', 'k', 'e'} Set with the use of List: {'Geeks', 'For'} Set with the use of Mixed Values {1, 2, 4, 6, 'Geeks', 'For'}
Truy cập các phần tử của Sets
Không thể truy cập các mục của tập hợp bằng cách tham chiếu đến một chỉ mục, vì các tập hợp không có thứ tự nên các mục không có chỉ mục. Nhưng bạn có thể lặp qua các mục của tập hợp bằng cách sử dụng vòng lặp for hoặc hỏi xem giá trị đã chỉ định có tồn tại trong một tập hợp hay không bằng cách sử dụng từ khóa
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]37
Python3
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]38
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]39
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]41
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks65
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Accessing element from the list Geeks Geeks Accessing element using negative indexing Geeks Geeks67
Initial blank List: [] List with the use of String: ['GeeksForGeeks'] List containing multiple values: Geeks Geeks Multi-Dimensional List: [['Geeks', 'For'], ['Geeks']]94
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life87
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life85
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life35
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______37_______54
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______27_______74
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]59
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]60
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______37_______63
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]65
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]66
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]37
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]68
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]69_______7_______3
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]71
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]73
First element of tuple 1 Last element of tuple 5 Third last element of tuple 33
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]4
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]76
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]77
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s3_______7_______4_______0_______85
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]37
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]82
đầu ra
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life0
Lưu ý - Để biết thêm về các bộ, hãy tham khảo Bộ Python
Từ điểnTừ điển trong Python là một tập hợp các giá trị dữ liệu không có thứ tự, được sử dụng để lưu trữ các giá trị dữ liệu như bản đồ, không giống như các Loại dữ liệu khác chỉ chứa một giá trị dưới dạng một phần tử, Từ điển chứa các cặp
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]83. Khóa-giá trị được cung cấp trong từ điển để tối ưu hóa hơn. Mỗi cặp khóa-giá trị trong Từ điển được phân tách bằng dấu hai chấm
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]84, trong khi mỗi khóa được phân tách bằng 'dấu phẩy'
Tạo từ điển
Trong Python, Từ điển có thể được tạo bằng cách đặt một chuỗi các phần tử trong dấu ngoặc nhọn
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]85, được phân tách bằng 'dấu phẩy'. Các giá trị trong từ điển có thể thuộc bất kỳ kiểu dữ liệu nào và có thể được sao chép, trong khi các khóa không thể lặp lại và phải không thay đổi. Từ điển cũng có thể được tạo bằng chức năng tích hợp
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]86. Một từ điển trống có thể được tạo bằng cách chỉ cần đặt nó vào dấu ngoặc nhọn{}
Lưu ý – Các khóa từ điển có phân biệt chữ hoa chữ thường, cùng tên nhưng khác chữ hoa chữ thường sẽ được xử lý khác biệt
Python3
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]87
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]88
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s1
First element of tuple 1 Last element of tuple 5 Third last element of tuple 304
String with the use of Single Quotes: Welcome to the Geeks World String with the use of Double Quotes: I'm a Geek String with the use of Triple Quotes: I'm a Geek and I live in a world of "Geeks" Creating a multiline String: Geeks For Life45
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]84
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
15
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]84
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s15
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s6
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s86
Initial empty Tuple: [] Tuple with the use of String: ['Geeks', 'For'] Tuple using List: [1, 2, 4, 5, 6] Tuple with the use of function: ['G', 'e', 'e', 'k', 's'] Tuple with nested tuples: [[0, 1, 2, 3], ['python', 'geek']]84
Initial String: GeeksForGeeks First character of String is: G Last character of String is: s13
First element of tuple 1 Last element of tuple 5 Third last element of tuple 316