Hướng dẫn is there a binary datatype in python? - có một kiểu dữ liệu nhị phân trong python không?

Một kiểu dữ liệu xác định loại của một biến. Vì mọi thứ là một đối tượng trong Python, các loại dữ liệu thực sự là các lớp; và các biến là các trường hợp của các lớp.data types are actually classes; and the variables are instances of the classes.

Trong bất kỳ ngôn ngữ lập trình nào, các hoạt động khác nhau có thể được thực hiện trên các loại dữ liệu khác nhau, một số loại phổ biến với các kiểu dữ liệu khác trong khi một số có thể rất cụ thể với kiểu dữ liệu cụ thể đó.

1. Các loại dữ liệu tích hợp trong Python

Python có các loại dữ liệu sau được tích hợp theo mặc định.

LoạiKiểu dữ liệu / tên lớp
Text/String ________số 8
Số int,
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
0,
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
1
Danh sách
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2,
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
3,
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
4
Bản đồ
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
5
Bộ
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
6,
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
7
Boolean
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
8
Nhị phân
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
9,
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
0,
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
1

2. Các loại dữ liệu chi tiết

2.1. str

Chuỗi có thể được định nghĩa là chuỗi các ký tự được đặt trong các trích dẫn đơn, gấp đôi hoặc ba. Các trích dẫn ba (có thể được sử dụng để viết các chuỗi nhiều dòng.

x = 'A'
y = "B"
z = """
	C
	"""

print(x)	# prints A
print(y)	# prints B
print(z)	# prints C

print(x + y)	# prints AB	- concatenation

print(x*2)		# prints AA - repeatition operator

name = str('john')	# Constructor

sumOfItems = str(100)	# type conversion from int to string

2.2. int, float, phức tạp

Đây là những loại số. Chúng được tạo khi một số được gán cho một biến.

  • int giữ số nguyên có chữ ký có độ dài không giới hạn.
  • x = 2					# int
    x = int(2)				# int	
    
    x = 2.5					# float
    x = float(2.5)			# float	
    
    x = 100+3j				# complex
    x = complex(100+3j) 	# complex
    
    0 giữ số lượng chính xác nổi và chúng là chính xác lên đến 15 chữ số thập phân.
  • x = 2					# int
    x = int(2)				# int	
    
    x = 2.5					# float
    x = float(2.5)			# float	
    
    x = 100+3j				# complex
    x = complex(100+3j) 	# complex
    
    1 - Một số phức tạp chứa phần thực và tưởng tượng.
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex

2.3. Danh sách, Tuple, phạm vi

Trong Python, Danh sách là một chuỗi được đặt hàng của một số dữ liệu được viết bằng dấu ngoặc vuông (____ 25) và dấu phẩy (________ 26). Một danh sách có thể chứa dữ liệu của các loại khác nhau.list is an ordered sequence of some data written using square brackets(

randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
5) and commas(
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
6). A list can contain data of different types.

Nhà điều hành Lát [

randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
7] có thể được sử dụng để truy cập dữ liệu trong danh sách. can be used to access the data in the list.

Toán tử nối (

randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
8) và toán tử lặp lại (
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
9) hoạt động tương tự kiểu dữ liệu str.concatenation operator (
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
8)
and repetition operator (
randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
9)
works similar the str data type.

Một phạm vi có thể được coi là

charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
1, được đưa ra khỏi
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2 bằng cách sử dụng toán tử cắt.range can be considered as
charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
1, taken out of a
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2 using slicing operator.

Một tuple tương tự như

x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2-ngoại trừ
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
3 là cấu trúc dữ liệu chỉ đọc và chúng tôi có thể sửa đổi kích thước và giá trị của các mục của một tuple. Ngoài ra, các mặt hàng được đặt trong ngoặc đơn
charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
5.tuple is similar to the
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2 – except
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
3 is a read-only data structure and we can’t modify the size and value of the items of a tuple. Also, items are enclosed in parentheses
charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
5.

randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment

2.4. DIGN

Dict hoặc Dictionary là một tập hợp của một cặp vật phẩm có giá trị khóa. Một khóa có thể giữ bất kỳ loại dữ liệu nguyên thủy nào trong khi giá trị là một đối tượng Python tùy ý. or dictionary is an ordered set of a key-value pair of items. A key can hold any primitive data type whereas value is an arbitrary Python object.

Các mục trong từ điển được phân tách bằng dấu phẩy và được đặt trong niềng răng xoăn

charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
6.

charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])

2.5. Đặt, Frozenset

Bộ trong Python có thể được định nghĩa là bộ sưu tập không được đặt hàng của các mục khác nhau được đặt trong niềng răng xoăn ____.set in python can be defined as the unordered collection of various items enclosed within the curly braces

charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
6.

Các yếu tố của tập hợp không thể được trùng lặp. Các yếu tố của bộ Python phải là bất biến.can not be duplicate. The elements of the python set must be immutable.

Không giống như

x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
2, không có
charsMap = {1:'a', 2:'b', 3:'c', 4:'d'};   

print (charsMap); 		# prints {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
print("1st entry is " + charsMap[1]);  # prints 1st entry is a
print (charsMap.keys());  		# prints dict_keys([1, 2, 3, 4])
print (charsMap.values());   	# prints dict_values(['a', 'b', 'c', 'd'])
9 cho các phần tử đã đặt. Điều đó có nghĩa là chúng ta chỉ có thể lặp qua các yếu tố của
x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
6.

Các bộ đông lạnh là dạng bất biến của các bộ bình thường. Điều đó có nghĩa là chúng tôi không thể xóa hoặc thêm bất kỳ mục nào vào bộ đóng băng.frozen sets are the immutable form of the normal sets. It means we cannot remove or add any item into the frozen set.

digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'

2.6. bool

Các giá trị bool là hai đối tượng không đổi

digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
1 và
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
2. Chúng được sử dụng để đại diện cho các giá trị sự thật. Trong bối cảnh số, chúng hoạt động như số nguyên 0 và 1, tương ứng.
values are the two constant objects
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
1 and
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
2. They are used to represent truth values. In numeric contexts, they behave like the integers 0 and 1, respectively.

x = True
y = False

print(x)	#True
print(y)	#False

print(bool(1))	#True
print(bool(0))	#False

2.7. byte, bytearray, memoryView

Byte và bytearray được sử dụng để thao tác dữ liệu nhị phân. MemoryView sử dụng giao thức bộ đệm để truy cập bộ nhớ của các đối tượng nhị phân khác mà không cần tạo bản sao. and bytearray are used for manipulating binary data. The memoryview uses the buffer protocol to access the memory of other binary objects without needing to make a copy.

Đối tượng byte là các chuỗi bất biến của các byte đơn. Chúng ta chỉ nên sử dụng chúng khi làm việc với dữ liệu tương thích ASCII.immutable sequences of single bytes. We should use them only when working with ASCII compatible data.

Cú pháp cho các chữ

x = 2					# int
x = int(2)				# int	

x = 2.5					# float
x = float(2.5)			# float	

x = 100+3j				# complex
x = complex(100+3j) 	# complex
9 cũng giống như các chữ
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
4, ngoại trừ tiền tố
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
5 được thêm vào.

Các đối tượng

randomList = [1, "one", 2, "two"]
print (randomList);  				# prints [1, 'one', 2, 'two']
print (randomList + randomList);  	# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']
print (randomList * 2);  			# prints [1, 'one', 2, 'two', 1, 'one', 2, 'two']

alphabets  = ["a", "b", "c", "d", "e", "f", "g", "h"]  

print (alphabets[3:]);  			# range - prints ['d', 'e', 'f', 'g', 'h']
print (alphabets[0:2]);  			# range - prints ['a', 'b']

randomTuple = (1, "one", 2, "two")
print (randomTuple[0:2]);  			# range - prints (1, 'one')

randomTuple[0] = 0		# TypeError: 'tuple' object does not support item assignment
0 luôn được tạo bằng cách gọi hàm tạo
digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
7. Đây là những đối tượng có thể thay đổi.mutable objects.

x = b'char_data'
x = b"char_data"

y = bytearray(5)

z = memoryview(bytes(5))

print(x)	# b'char_data'
print(y)	# bytearray(b'\x00\x00\x00\x00\x00')
print(z)	# 

3. loại () hàm

Hàm

digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}   

print(digits)  			# prints {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

print(type(digits))  	# prints 

print("looping through the set elements ... ")  
for i in digits:  
    print(i)  			# prints 0 1 2 3 4 5 6 7 8 9 in new lines

digits.remove(0)	# allowed in normal set

print(digits)		# {1, 2, 3, 4, 5, 6, 7, 8, 9}

frozenSetOfDigits = frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})   

frozenSetOfDigits.remove(0)	# AttributeError: 'frozenset' object has no attribute 'remove'
8 có thể được sử dụng để có được loại dữ liệu của bất kỳ đối tượng nào.

x = 5
print(type(x))			# 

y = 'howtodoinjava.com'
print(type(y))			# 

Hãy gửi cho tôi câu hỏi của bạn trong bình luận.

Học hỏi hạnh phúc !!

Tham khảo: Tài liệu Python

Làm thế nào để bạn viết dữ liệu nhị phân trong Python?

Viết byte vào tệp trong Python Ví dụ 1: Mở tệp ở chế độ ghi nhị phân và sau đó chỉ định nội dung để ghi dưới dạng byte. Tiếp theo, sử dụng chức năng ghi để viết nội dung byte vào tệp nhị phân.use the write function to write the byte contents to a binary file.

Định dạng nhị phân ở Python là gì?

Một tệp nhị phân là một tệp có nội dung ở định dạng nhị phân bao gồm một loạt các byte tuần tự, mỗi loại có chiều dài tám bit.Nội dung phải được giải thích bởi một chương trình hoặc bộ xử lý phần cứng hiểu trước chính xác cách nội dung đó được định dạng và cách đọc dữ liệu.a file whose content is in a binary format consisting of a series of sequential bytes, each of which is eight bits in length. The content must be interpreted by a program or a hardware processor that understands in advance exactly how that content is formatted and how to read the data.

Các tệp Python là nhị phân hay văn bản?

Có hai loại tệp có thể được xử lý trong Python, tệp văn bản thông thường và tệp nhị phân (được viết bằng ngôn ngữ nhị phân, 0S và 1S).Tệp văn bản: Trong loại tệp này, mỗi dòng văn bản được chấm dứt với một ký tự đặc biệt có tên là EOL (cuối dòng), là ký tự dòng mới ('\ n') trong Python theo mặc định.binary files (written in binary language, 0s, and 1s). Text files: In this type of file, Each line of text is terminated with a special character called EOL (End of Line), which is the new line character ('\n') in python by default.

Có phải nhị phân là một loại dữ liệu?

Dữ liệu nhị phân là một loại dữ liệu được thể hiện hoặc hiển thị trong hệ thống số nhị phân.Dữ liệu nhị phân là danh mục dữ liệu duy nhất có thể được hiểu và thực hiện trực tiếp bởi máy tính.Nó được đại diện bằng số bằng sự kết hợp của số không và các số không.. Binary data is the only category of data that can be directly understood and executed by a computer. It is numerically represented by a combination of zeros and ones.