Đào tạo cho khuôn viên trường đại học
Javatpoint cung cấp đào tạo trường đại học về Core Java, Advance Java, .NET, Android, Hadoop, PHP, Web Technology và Python. Vui lòng gửi thư yêu cầu của bạn tại [Email & NBSP; được bảo vệ] Thời lượng: 1 tuần đến 2 tuần
Duration: 1 week to 2 week
Các loại 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 hoạt động có thể được thực hiện trên một dữ liệu cụ thể. Vì mọi thứ là một đối tượng trong lập trình Python, các loại dữ liệu thực sự là các lớp và biến là ví dụ [đối tượng] của các lớp này.
num = 24
Kiểu dữ liệu javatpoint là gì?24 [an integer] is assigned to the num variable. So the data type of num is of the
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
4 class.Các loại dữ liệu chỉ định các kích thước và giá trị khác nhau có thể được lưu trữ trong biến. Có hai loại loại dữ liệu trong Java: Các loại dữ liệu nguyên thủy: Các loại dữ liệu nguyên thủy bao gồm boolean, char, byte, ngắn, int, long, float và gấp đôi.
Số Python. Các loại dữ liệu số lưu trữ giá trị số. .... | Chuỗi Python. Các chuỗi trong Python được xác định là một tập hợp các ký tự tiếp giáp được thể hiện trong các dấu ngoặc kép. .... | Danh sách Python. Danh sách là loại linh hoạt nhất trong số các loại dữ liệu hỗn hợp của Python. .... |
Python Tuples. .... | Từ điển Python .. | Trong lập trình máy tính, các loại dữ liệu chỉ định loại dữ liệu có thể được lưu trữ bên trong một biến. Ví dụ, |
Ở đây, 24 [một số nguyên] được gán cho biến số. Vì vậy, loại dữ liệu của num là của lớp 4. | Kiểu dữ liệu Python | Loại dữ liệu |
Các lớp học | Sự mô tả | Số |
int, float, phức tạp | bool | giữ 5 hoặc 6 |
Bộ | Đặt, Frozeenset | Giữ bộ sưu tập các mặt hàng độc đáo |
Vì mọi thứ là một đối tượng trong lập trình Python, các loại dữ liệu thực sự là các lớp và biến là các trường hợp [đối tượng] của các lớp này.
Kiểu dữ liệu số Python
Trong Python, kiểu dữ liệu số được sử dụng để giữ các giá trị số.
Số nguyên, số điểm nổi và số phức tạp thuộc loại số Python. Chúng được định nghĩa là các lớp
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
4, num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
8 và num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
9 trong Python.
4 - Giữ số nguyên có chữ ký có độ dài không giới hạn.num1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
8 - giữ các điểm thập phân nổi và nó chính xác lên đến 15 chữ số thập phân.15 decimal places.num1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
9 - giữ các số phức.num1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
Chúng ta có thể sử dụng hàm
5 is of type 2.0 is of type [1+2j] is of type3 để biết biến A hoặc giá trị nào thuộc về.
Hãy xem một ví dụ,
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
Đầu ra
5 is of type 2.0 is of type [1+2j] is of type
Trong ví dụ trên, chúng tôi đã tạo ba biến có tên NUM1, NUM2 và NUM3 với các giá trị 5, 5.0 và
5 is of type 2.0 is of type [1+2j] is of type4 tương ứng.5, 5.0, and
5 is of type 2.0 is of type [1+2j] is of type4 respectively.
Chúng tôi cũng đã sử dụng hàm
5 is of type 2.0 is of type [1+2j] is of type3 để biết loại A nào đó thuộc về.
Since,
- 5 là một giá trị số nguyên,
5 is of type 2.0 is of type [1+2j] is of type
3 trả về
4 là lớp của num1 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
5 is of type 2.0 is of type [1+2j] is of type
8 is an integer value,5 is of type 2.0 is of type [1+2j] is of type
3 returns
4 as the class of num1 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
5 is of type 2.0 is of type [1+2j] is of type
8 - 2.0 là một giá trị nổi,
5 is of type 2.0 is of type [1+2j] is of type
3 trả về
8 là lớp của num2 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
1 is a floating value,languages = ["Swift", "Java", "Python"]
5 is of type 2.0 is of type [1+2j] is of type
3 returns
8 as the class of num2 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
1languages = ["Swift", "Java", "Python"]
2 là một số phức,languages = ["Swift", "Java", "Python"]
5 is of type 2.0 is of type [1+2j] is of type
3 trả về
9 là lớp của num3 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
5languages = ["Swift", "Java", "Python"]
Kiểu dữ liệu danh sách Python
Danh sách là một bộ sưu tập được đặt hàng gồm các loại vật phẩm tương tự hoặc khác nhau được phân tách bằng dấu phẩy và được đặt trong ngoặc
languages = ["Swift", "Java", "Python"]
6. Ví dụ,languages = ["Swift", "Java", "Python"]
Ở đây, chúng tôi đã tạo một danh sách các ngôn ngữ có tên với 3 giá trị chuỗi bên trong nó.3 string values inside it.
Các mục trong danh sách truy cập
Để truy cập các mục từ danh sách, chúng tôi sử dụng số chỉ mục [0, 1, 2 ...]. Ví dụ,[0, 1, 2 ...]. For example,
languages = ["Swift", "Java", "Python"]
# access element at index 0
print[languages[0]] # Swift
# access element at index 2
print[languages[2]] # Python
Trong ví dụ trên, chúng tôi đã sử dụng các giá trị chỉ mục để truy cập các mục từ danh sách ngôn ngữ.
7 - Truy cập mục đầu tiên từ các ngôn ngữ, tức làlanguages = ["Swift", "Java", "Python"]
8languages = ["Swift", "Java", "Python"]
9 - Truy cập mục thứ ba từ các ngôn ngữ, tức làlanguages = ["Swift", "Java", "Python"]
0languages = ["Swift", "Java", "Python"] # access element at index 0 print[languages[0]] # Swift # access element at index 2 print[languages[2]] # Python
Để tìm hiểu thêm về danh sách, hãy truy cập danh sách Python.
Kiểu dữ liệu Python Tuple
Tuple là một chuỗi được đặt hàng của các mục giống như một danh sách. Sự khác biệt duy nhất là bộ dữ liệu là bất biến. Tuples một lần được tạo không thể được sửa đổi.
Trong Python, chúng tôi sử dụng dấu ngoặc đơn
languages = ["Swift", "Java", "Python"]
# access element at index 0
print[languages[0]] # Swift
# access element at index 2
print[languages[2]] # Python
1 để lưu trữ các mục của một tuple. Ví dụ,product = ['Xbox', 499.99]
Ở đây, sản phẩm là một tuple với giá trị chuỗi
languages = ["Swift", "Java", "Python"]
# access element at index 0
print[languages[0]] # Swift
# access element at index 2
print[languages[2]] # Python
2 và giá trị số nguyên 499,99.499.99.Truy cập các mục Tuple
Tương tự như danh sách, chúng tôi sử dụng số chỉ mục để truy cập các mục Tuple trong Python. Ví dụ,
# create a tuple
product = ['Microsoft', 'Xbox', 499.99]
# access element at index 0
print[product[0]] # Microsoft
# access element at index 1
print[product[1]] # Xbox
Để tìm hiểu thêm về các bộ dữ liệu, hãy truy cập Python Tuples.
Kiểu dữ liệu chuỗi Python
Chuỗi là một chuỗi các ký tự được biểu thị bằng trích dẫn đơn hoặc đôi. Ví dụ,
name = 'Python'
print[name]
message = 'Python for beginners'
print[message]
Đầu ra
Python Python for beginners
Trong ví dụ trên, chúng tôi đã tạo ba biến có tên NUM1, NUM2 và NUM3 với các giá trị 5, 5.0 và
5 is of type 2.0 is of type [1+2j] is of type4 tương ứng.
Chúng tôi cũng đã sử dụng hàm
5 is of type 2.0 is of type [1+2j] is of type3 để biết loại A nào đó thuộc về.
5 là một giá trị số nguyên, 5 is of type
2.0 is of type
[1+2j] is of type
3 trả về num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
4 là lớp của num1 i.e 5 is of type
2.0 is of type
[1+2j] is of type
8
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
2.0 là một giá trị nổi,
5 is of type 2.0 is of type [1+2j] is of type3 trả về
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
8 là lớp của num2 i.e languages = ["Swift", "Java", "Python"]
1# create a set named student_id
student_id = {112, 114, 116, 118, 115}
# display student_id elements
print[student_id]
# display type of student_id
print[type[student_id]]
Đầu ra
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
0Trong ví dụ trên, chúng tôi đã tạo ba biến có tên NUM1, NUM2 và NUM3 với các giá trị 5, 5.0 và
5 is of type 2.0 is of type [1+2j] is of type4 tương ứng.5 integer values.
Chúng tôi cũng đã sử dụng hàm
5 is of type 2.0 is of type [1+2j] is of type3 để biết loại A nào đó thuộc về.
5 là một giá trị số nguyên,
5 is of type 2.0 is of type [1+2j] is of type3 trả về
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
4 là lớp của num1 i.e 5 is of type 2.0 is of type [1+2j] is of type8
2.0 là một giá trị nổi, 5 is of type
2.0 is of type
[1+2j] is of type
3 trả về num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
8 là lớp của num2 i.e languages = ["Swift", "Java", "Python"]
1
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
languages = ["Swift", "Java", "Python"]
languages = ["Swift", "Java", "Python"]
2 là một số phức, 5 is of type 2.0 is of type [1+2j] is of type3 trả về
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
9 là lớp của num3 i.e languages = ["Swift", "Java", "Python"]
5Kiểu dữ liệu danh sách Python
Hãy xem một ví dụ,
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
1Đầu ra
Trong ví dụ trên, chúng tôi đã tạo ba biến có tên NUM1, NUM2 và NUM3 với các giá trị 5, 5.0 và5 is of type 2.0 is of type [1+2j] is of type4 tương ứng.
Chúng tôi cũng đã sử dụng hàm
5 is of type 2.0 is of type [1+2j] is of type3 để biết loại A nào đó thuộc về.
- 5 là một giá trị số nguyên,
5 is of type 2.0 is of type [1+2j] is of type
3 trả về
4 là lớp của num1 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
5 is of type 2.0 is of type [1+2j] is of type
8 are
7,languages = ["Swift", "Java", "Python"] # access element at index 0 print[languages[0]] # Swift # access element at index 2 print[languages[2]] # Python
8,languages = ["Swift", "Java", "Python"] # access element at index 0 print[languages[0]] # Swift # access element at index 2 print[languages[2]] # Python
9languages = ["Swift", "Java", "Python"] # access element at index 0 print[languages[0]] # Swift # access element at index 2 print[languages[2]] # Python
- 2.0 là một giá trị nổi,
5 is of type 2.0 is of type [1+2j] is of type
3 trả về
8 là lớp của num2 i.enum1 = 5 print[num1, 'is of type', type[num1]] num2 = 2.0 print[num2, 'is of type', type[num2]] num3 = 1+2j print[num3, 'is a complex number?', isinstance[1+2j,complex]]
1 arelanguages = ["Swift", "Java", "Python"]
0,product = ['Xbox', 499.99]
1,product = ['Xbox', 499.99]
2product = ['Xbox', 499.99]
languages = ["Swift", "Java", "Python"]
2 là một số phức, 5 is of type 2.0 is of type [1+2j] is of type3 trả về
num1 = 5
print[num1, 'is of type', type[num1]]
num2 = 2.0
print[num2, 'is of type', type[num2]]
num3 = 1+2j
print[num3, 'is a complex number?', isinstance[1+2j,complex]]
9 là lớp của num3 i.e languages = ["Swift", "Java", "Python"]
5Kiểu dữ liệu danh sách Python
Danh sách là một bộ sưu tập được đặt hàng gồm các loại vật phẩm tương tự hoặc khác nhau được phân tách bằng dấu phẩy và được đặt trong ngoặc
languages = ["Swift", "Java", "Python"]
6. Ví dụ,Ở đây, chúng tôi đã tạo một danh sách các ngôn ngữ có tên với 3 giá trị chuỗi bên trong nó.Các mục trong danh sách truy cập
Để truy cập các mục từ danh sách, chúng tôi sử dụng số chỉ mục [0, 1, 2 ...]. Ví dụ,
Trong ví dụ trên, chúng tôi đã sử dụng các giá trị chỉ mục để truy cập các mục từ danh sách ngôn ngữ.
languages = ["Swift", "Java", "Python"]
7 - Truy cập mục đầu tiên từ các ngôn ngữ, tức là languages = ["Swift", "Java", "Python"]
8