Trong lập trình hướng đối tượng, khi chúng ta thiết kế một lớp, chúng ta sử dụng biến đối tượng và biến lớp.
- Biến thể hiện. Nếu giá trị của một biến thay đổi từ đối tượng này sang đối tượng khác, thì các biến đó được gọi là biến thể hiện
- Biến lớp. Biến lớp là một biến được khai báo bên trong lớp, nhưng bên ngoài bất kỳ phương thức thể hiện hoặc phương thức
1 nàoclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
Sau khi đọc bài viết này, bạn sẽ học được
- Cách tạo và truy cập các biến đối tượng
- Sửa đổi giá trị của các biến thể hiện
- Cách tự động thêm hoặc xóa các biến đối tượng
- Phạm vi của một biến thể hiện
Mục lục
Biến thể hiện trong Python là gì?
Nếu giá trị của một biến thay đổi từ đối tượng này sang đối tượng khác, thì các biến đó được gọi là biến thể hiện. Đối với mọi đối tượng, một bản sao riêng biệt của biến thể hiện sẽ được tạo
Các biến thể hiện không được chia sẻ bởi các đối tượng. Mỗi đối tượng có bản sao riêng của thuộc tính thể hiện. Điều này có nghĩa là đối với mỗi đối tượng của một lớp, giá trị biến thể hiện là khác nhau
Khi chúng ta tạo các lớp trong Python, các phương thức thể hiện được sử dụng thường xuyên. chúng ta cần tạo một đối tượng để thực thi khối mã hoặc hành động được xác định trong phương thức thể hiện
Các biến thể hiện được sử dụng trong phương thức thể hiện. Chúng tôi sử dụng phương thức thể hiện để thực hiện một tập hợp các hành động trên dữ liệu/giá trị do biến thể hiện cung cấp
Chúng ta có thể truy cập biến thể hiện bằng toán tử đối tượng và dấu chấm [
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
2]Trong Python, để làm việc với một biến đối tượng và phương thức, chúng ta sử dụng từ khóa
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
3. Chúng tôi sử dụng từ khóa class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
3 làm tham số đầu tiên cho một phương thức. class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
3 đề cập đến đối tượng hiện tạiTạo biến thể hiện
Các biến thể hiện được khai báo bên trong một phương thức bằng cách sử dụng từ khóa
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
3. Chúng tôi sử dụng một hàm tạo để xác định và khởi tạo các biến thể hiện. Hãy cùng xem ví dụ để khai báo một biến thể hiện trong PythonVí dụ
Trong ví dụ sau, chúng ta đang tạo hai biến thể hiện
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
7 và class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
8 trong lớp class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
9class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create first object
s1 = Student["Jessa", 20]
# access instance variable
print['Object 1']
print['Name:', s1.name]
print['Age:', s1.age]
# create second object
s2= Student["Kelly", 10]
# access instance variable
print['Object 2']
print['Name:', s2.name]
print['Age:', s2.age]
đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
0Ghi chú
- Khi chúng tôi tạo một đối tượng, chúng tôi đã chuyển các giá trị cho các biến thể hiện bằng hàm tạo
- Mỗi đối tượng chứa các giá trị khác nhau vì chúng ta đã chuyển các giá trị khác nhau cho hàm tạo để khởi tạo đối tượng
- Biến được khai báo bên ngoài
1 thuộc về lớp. Chúng được chia sẻ bởi tất cả các trường hợpclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
Sửa đổi giá trị của các biến thể hiện
Chúng ta có thể sửa đổi giá trị của biến thể hiện và gán giá trị mới cho nó bằng cách sử dụng tham chiếu đối tượng
Ghi chú. Khi bạn thay đổi giá trị của biến thể hiện của một đối tượng, các thay đổi sẽ không được phản ánh trong các đối tượng còn lại vì mỗi đối tượng duy trì một bản sao riêng của biến thể hiện
Ví dụ
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
3Các cách truy cập biến thể hiện
Có hai cách để truy cập biến thể hiện của lớp
- Trong phương thức thể hiện của lớp bằng cách sử dụng tham chiếu đối tượng [
3]class Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
- Sử dụng phương pháp
32class Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
ví dụ 1. Truy cập biến đối tượng trong phương thức đối tượng
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
6đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
7ví dụ 2. Truy cập biến thể hiện bằng cách sử dụng
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
32class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
9Truyền tham chiếu đối tượng và tên biến thể hiện cho phương thức
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
32 để lấy giá trị của một biến thể hiệnclass Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
1đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
2Quy ước đặt tên biến thể hiện
- Tên biến thể hiện phải là chữ thường. Ví dụ,
35class Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
- Các từ trong tên biến thể hiện phải được phân tách bằng dấu gạch dưới. Ví dụ,
36class Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
- Các biến thể hiện không công khai phải bắt đầu bằng một dấu gạch dưới
- Nếu một tên đối tượng cần được đọc sai, hai dấu gạch dưới có thể bắt đầu tên của nó
Tự động thêm biến đối tượng vào một đối tượng
Chúng ta có thể thêm các biến thể hiện từ bên ngoài lớp vào một đối tượng cụ thể. Sử dụng cú pháp sau để thêm biến đối tượng mới vào đối tượng
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
5Ví dụ
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
00đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
01Ghi chú
- Chúng ta không thể thêm một biến thể hiện vào một lớp từ bên ngoài vì các biến thể hiện thuộc về các đối tượng
- Việc thêm một biến thể hiện vào một đối tượng sẽ không được phản ánh trong các đối tượng còn lại vì mỗi đối tượng có một bản sao riêng của biến thể hiện
Tự động xóa biến thể hiện
Trong Python, chúng ta sử dụng câu lệnh
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
37 và hàm class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
38 để xóa thuộc tính của một đối tượng. Cả hai đều làm điều tương tự- tuyên bố
37. Từ khóaclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
37 dùng để xóa đối tượng. Trong Python, mọi thứ đều là một đối tượng, do đó, từ khóaclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
37 cũng có thể được sử dụng để xóa các biến, danh sách hoặc một phần của danh sách, v.v.class Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
- chức năng
38. Được sử dụng để xóa một biến đối tượng một cách linh hoạtclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
Ghi chú. Khi chúng tôi cố gắng truy cập thuộc tính đã xóa, nó sẽ phát sinh lỗi thuộc tính
ví dụ 1. Sử dụng câu lệnh
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
37class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
02đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
03chức năng
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
38Hàm delattr[] được sử dụng để xóa thuộc tính đã đặt tên khỏi đối tượng với sự cho phép trước của đối tượng. Sử dụng cú pháp sau
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
04
65. đối tượng có thuộc tính chúng tôi muốn xóaclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
66. tên của biến thể hiện mà chúng tôi muốn xóa khỏi đối tượngclass Student: # constructor def __init__[self, name, age]: # Instance variable self.name = name self.age = age # create object stud = Student["Jessa", 20] print['Before'] print['Name:', stud.name, 'Age:', stud.age] # modify instance variable stud.name = 'Emma' stud.age = 15 print['After'] print['Name:', stud.name, 'Age:', stud.age]
Ví dụ
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
05đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
06Truy cập biến thể hiện từ một lớp khác
Chúng ta có thể truy cập các biến thể hiện của một lớp từ một lớp khác bằng cách sử dụng tham chiếu đối tượng. Nó rất hữu ích khi chúng ta triển khai khái niệm kế thừa trong Python và chúng ta muốn truy cập biến thể hiện của lớp cha từ một lớp con
hãy hiểu điều này với sự trợ giúp của một ví dụ
Trong ví dụ này,
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
67 là một biến thể hiện của lớp class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
68. Chúng tôi đã kế thừa một lớp class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
68 để truy cập các biến thể hiện của nó trong lớp class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
70class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
07đầu ra
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
08Liệt kê tất cả các biến thể hiện của một đối tượng
Chúng ta có thể lấy danh sách tất cả các biến đối tượng mà đối tượng có. Sử dụng hàm
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
71 của một đối tượng để lấy tất cả các biến thể hiện cùng với giá trị của chúngHàm
class Student:
# constructor
def __init__[self, name, age]:
# Instance variable
self.name = name
self.age = age
# create object
stud = Student["Jessa", 20]
print['Before']
print['Name:', stud.name, 'Age:', stud.age]
# modify instance variable
stud.name = 'Emma'
stud.age = 15
print['After']
print['Name:', stud.name, 'Age:', stud.age]
71 trả về một từ điển chứa tên biến làm khóa và giá trị biến làm giá trị