Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

Bất cứ khi nào tôi chạy mã của mình, tôi nhận được: nameerror: name 'object_oriented_programming' không được xác định

Show

Làm cách nào để xác định tên Object_oriented_programming?

Code:

class Object_Oriented_Programming:
    
    class Inheritance():
        def __init__(self, name, age):
            self.name = name
            self.age = age

        class SchoolMember():
            '''Represents any school member.'''

            def __init__(self, name, age):
                self.name = name
                self.age = age
                print('(Initialized SchoolMember: {})'.format(self.name))

            def tell(self):
                '''Tell my details.'''
                print('Name:"{}" Age:"{}"'.format(
                    self.name, self.age), end=" ")

        class Teacher(SchoolMember):
            '''Represents a teacher.'''

            def __init__(self, name, age, salary):
                Object_Oriented_Programming.Inheritance.SchoolMember.__init__(
                    self, name, age)
                self.salary = salary
                print('(Initialized Teacher: {})'.format(self.name))

            def tell(self):
                Object_Oriented_Programming.Inheritance.SchoolMember.tell(self)
                print('Salary: "{:d}"'.format(self.salary))

hỏi ngày 21 tháng 2 lúc 17:08Feb 21 at 17:08

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

4

Theo như tôi quan tâm về mã, tôi đã chạy nó trên thiết bị đầu cuối và không có vấn đề gì, nó được thực hiện đơn giản và không có gì hiển thị vì không có gì được in.

Bây giờ, nếu bạn thực sự muốn biết cách xác định một đối tượng trong OOPS trong Python, thì đây là cách để làm điều đó:

  1. Đầu tiên thay vì tạo một lớp bên trong một lớp, bạn chỉ nên tạo một lớp và sau đó viết phương thức
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    8 bao gồm tất cả những thứ như tên hoặc tuổi.
  2. Khi nào với điều này, sau đó bạn có thể tạo một biến mới ở cuối và đặt nó = tên lớp (tên, tuổi). Ví dụ, tôi đã đính kèm một IMG để hiển thị cho bạn một đoạn mã.

Mã số

Tomerikoo

16.7K15 Huy hiệu vàng38 Huy hiệu bạc55 Huy hiệu Đồng15 gold badges38 silver badges55 bronze badges

Đã trả lời ngày 21 tháng 2 lúc 17:36Feb 21 at 17:36

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

5

mã số :

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()

Đã trả lời ngày 22 tháng 2 lúc 11:20Feb 22 at 11:20

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

1

Biến Python là các container lưu trữ giá trị. Python không phải là người đánh máy thống trị. Chúng tôi không cần phải khai báo các biến trước khi sử dụng chúng hoặc khai báo loại của chúng. Một biến được tạo ngay khi chúng ta gán một giá trị cho nó. Một biến Python là một tên được đặt cho một vị trí bộ nhớ. Nó là đơn vị lưu trữ cơ bản trong một chương trình.

Ví dụ về các biến Python

Python3

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
9
Geeksforgeeks
0
Geeksforgeeks
1

Geeksforgeeks
2
Geeksforgeeks
3

Output:

Geeksforgeeks

Notes:

  • Giá trị được lưu trữ trong một biến có thể được thay đổi trong quá trình thực hiện chương trình.
  • Một biến Python chỉ là một tên được đặt cho vị trí bộ nhớ, tất cả các hoạt động được thực hiện trên các hiệu ứng biến vị trí bộ nhớ đó.

Các quy tắc để tạo các biến trong Python

  • Một tên biến phải bắt đầu bằng một chữ cái hoặc ký tự dấu gạch dưới.
  • Một tên biến không thể bắt đầu với một số.
  • Một tên biến chỉ có thể chứa các ký tự alpha-numeric và nhấn mạnh (A-Z, 0-9 và _).
  • Tên biến là nhạy cảm trường hợp (tên, tên và tên là ba biến khác nhau).
  • Các từ dành riêng (từ khóa) không thể được sử dụng đặt tên biến.

Hãy cùng xem các biến biến đơn giản:

Python3

Geeksforgeeks
4
Geeksforgeeks
0
Geeksforgeeks
6

Geeksforgeeks
7
Geeksforgeeks
0
Geeksforgeeks
9

45
1456.8
John
0
Geeksforgeeks
0
45
1456.8
John
2

Geeksforgeeks
2
45
1456.8
John
4

Geeksforgeeks
2
45
1456.8
John
6

Geeksforgeeks
2
45
1456.8
John
8

Output:

45
1456.8
John

Tuyên bố biến

Hãy cùng xem cách khai báo biến và in biến.

Python3

45
1456.8
John
9
Geeksforgeeks
0
100
1

Geeksforgeeks
2
100
3

Output:

100

Tử lại biến

Chúng tôi có thể khai báo lại biến Python một khi chúng tôi đã khai báo biến.

Python3

45
1456.8
John
9
Geeksforgeeks
0
100
1

Geeksforgeeks
2
100
8
100
9
Before declare:  100
After re-declare: 120.3
0

Tử lại biến

Geeksforgeeks
2
100
8
Before declare:  100
After re-declare: 120.3
6
Before declare:  100
After re-declare: 120.3
0

Output:

Before declare:  100
After re-declare: 120.3

Chúng tôi có thể khai báo lại biến Python một khi chúng tôi đã khai báo biến.

45
1456.8
John
9
Geeksforgeeks
0
Before declare:  100
After re-declare: 120.3
3
For example: 

Python3

Gán một giá trị duy nhất cho nhiều biến

Geeksforgeeks
2
10
10
10
6

Geeksforgeeks
2
10
10
10
8

Geeksforgeeks
2
1
20.2
GeeksforGeeks
0

Output:

10
10
10

Ngoài ra, Python cho phép gán một giá trị duy nhất cho một số biến đồng thời với các toán tử = = các toán tử. & Nbsp; ví dụ: & nbsp;

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
10
10
10
0
Geeksforgeeks
0
10
10
10
2
Geeksforgeeks
0
10
10
10
4

Python3

1
20.2
GeeksforGeeks
1
Geeksforgeeks
0
1
20.2
GeeksforGeeks
3
1
20.2
GeeksforGeeks
4
1
20.2
GeeksforGeeks
5
1
20.2
GeeksforGeeks
4
1
20.2
GeeksforGeeks
7

Geeksforgeeks
2
10
10
10
6

Geeksforgeeks
2
10
10
10
8

Geeksforgeeks
2
1
20.2
GeeksforGeeks
0

Output:

1
20.2
GeeksforGeeks

Chúng ta có thể sử dụng cùng tên cho các loại khác nhau không? & NBSP;the same name for different types? 

Nếu chúng ta sử dụng cùng một tên, biến bắt đầu đề cập đến một giá trị và loại mới. & Nbsp;

Python3

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
10
10
10
4

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
1
20.2
GeeksforGeeks
7

Geeksforgeeks
2
10
10
10
6

Output:

GeeksforGeeks

Làm thế nào + toán tử hoạt động với các biến? & Nbsp; 

Python3

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
10
10
10
4

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
1
20.2
GeeksforGeeks
7

Geeksforgeeks
2
TypeError: unsupported operand type(s) for +: 'int' and 'str'
9
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
00
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
01

Làm thế nào + toán tử hoạt động với các biến? & Nbsp;

10
10
10
0
Geeksforgeeks
0
TypeError: unsupported operand type(s) for +: 'int' and 'str'
7

Geeksforgeeks
2
TypeError: unsupported operand type(s) for +: 'int' and 'str'
9
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
00
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
01

Before declare: 100 After re-declare: 120.38Geeksforgeeks0 class train: def __init__(self, name, fare, seats, code): self.name = name self.fare = fare self.seats = seats self.code = code def train_Status(self): print(f"The name of the train is {self.name}") print(f"The seats is {self. seats}") def fare_Info(self): print(f"The fare is {self. fare}") def code_Info(self): print(f"The code is {self. code}") def tickets_Info(self): if(self.seats > 0): print( f"The seats are available for you...\nYour seat number is {self.seats}") self.seats = self.seats - 1 elif(self.seats == 0): print("The seats are not available for you...") else: print("The server isnt updated yet. \nPlease try again later.") @staticmethod def greeting(): print("Welcome to Rajdhani express!!") Inter = train("Inter Express", 180, 12, 239340) Inter.greeting() Inter.fare_Info() Inter.train_Status() Inter.tickets_Info() Inter.train_Status() Inter.code_Info() 04 

10
10
10
0
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
07

Python3

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
10
10
10
4

10
10
10
0
Geeksforgeeks
0
TypeError: unsupported operand type(s) for +: 'int' and 'str'
7

Geeksforgeeks
2
TypeError: unsupported operand type(s) for +: 'int' and 'str'
9
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
00
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
01

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
04

TypeError: unsupported operand type(s) for +: 'int' and 'str'

10 10 100Geeksforgeeks0 class train: def __init__(self, name, fare, seats, code): self.name = name self.fare = fare self.seats = seats self.code = code def train_Status(self): print(f"The name of the train is {self.name}") print(f"The seats is {self. seats}") def fare_Info(self): print(f"The fare is {self. fare}") def code_Info(self): print(f"The code is {self. code}") def tickets_Info(self): if(self.seats > 0): print( f"The seats are available for you...\nYour seat number is {self.seats}") self.seats = self.seats - 1 elif(self.seats == 0): print("The seats are not available for you...") else: print("The server isnt updated yet. \nPlease try again later.") @staticmethod def greeting(): print("Welcome to Rajdhani express!!") Inter = train("Inter Express", 180, 12, 239340) Inter.greeting() Inter.fare_Info() Inter.train_Status() Inter.tickets_Info() Inter.train_Status() Inter.code_Info() 07

Chúng ta cũng có thể sử dụng + cho các loại khác nhau? & NBSP;are the ones that are defined and declared inside a function. We can not call this variable outside the function.

Python3

Không sử dụng cho các loại khác nhau sẽ tạo ra một lỗi. & NBSP;

Đầu ra: & nbsp;

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
Geeksforgeeks
2
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
30

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
31

Output:

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
0

Các biến Python toàn cầu và địa phương are the ones that are defined and declared outside a function, and we need to use them inside a function.

Python3

Không sử dụng cho các loại khác nhau sẽ tạo ra một lỗi. & NBSP;

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
Geeksforgeeks
2
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
30

Đầu ra: & nbsp;

Các biến Python toàn cầu và địa phương

Output:

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
1

Các biến cục bộ là các biến được xác định và khai báo bên trong một hàm. Chúng ta không thể gọi biến này bên ngoài chức năng.

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
22
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
23

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
25
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
27

  • Các biến toàn cầu là những biến được xác định và khai báo bên ngoài một hàm và chúng ta cần sử dụng chúng bên trong một hàm.
  •         class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    25
    Geeksforgeeks
    0
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    39
  •         class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    31
  • Từ khóa toàn cầu trong Python

Example:

Từ khóa toàn cầu là một từ khóa cho phép người dùng sửa đổi một biến bên ngoài phạm vi hiện tại. Nó được sử dụng để tạo các biến toàn cầu từ một phạm vi không toàn cầu, tức là bên trong một hàm. Từ khóa toàn cầu chỉ được sử dụng bên trong một chức năng khi chúng tôi muốn thực hiện các bài tập hoặc khi chúng tôi muốn thay đổi một biến. Toàn cầu là không cần thiết để in và truy cập.

Quy tắc từ khóa toàn cầu:

Nếu một biến được gán một giá trị ở bất cứ đâu trong cơ thể chức năng, thì nó được coi là địa phương trừ khi được tuyên bố rõ ràng là toàn cầu.

Các biến chỉ được tham chiếu bên trong một hàm là toàn cầu ngầm.

Chúng tôi sử dụng từ khóa toàn cầu để sử dụng một biến toàn cầu bên trong một hàm.

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
58
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
59

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
60

Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
63
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
59

Output:

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
2

Không cần phải sử dụng từ khóa toàn cầu bên ngoài một chức năng.

Python3

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
41
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
43

  •         class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    22
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    45
  •         class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    24
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    47
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    48
  •         class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    24
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    41
    Geeksforgeeks
    0
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    41
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    00
            class train:
        def __init__(self, name, fare, seats, code):
            self.name = name
            self.fare = fare
            self.seats = seats
            self.code = code
    
        def train_Status(self):
            print(f"The name of the train is {self.name}")
            print(f"The seats is {self. seats}")
    
        def fare_Info(self):
            print(f"The fare is {self. fare}")
    
        def code_Info(self):
            print(f"The code is {self. code}")
    
        def tickets_Info(self):
            if(self.seats > 0):
                print(
                    f"The seats are available for you...\nYour seat number is {self.seats}")
                self.seats = self.seats - 1
            elif(self.seats == 0):
                print("The seats are not available for you...")
            else:
                print("The server isnt updated yet. \nPlease try again later.")
    
        @staticmethod
        def greeting():
            print("Welcome to Rajdhani express!!")
    
    
    Inter = train("Inter Express", 180, 12, 239340)
    Inter.greeting()
    Inter.fare_Info()
    Inter.train_Status()
    Inter.tickets_Info()
    Inter.train_Status()
    Inter.code_Info()
    
    54
  • Loại biến trong python
  • 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.

Example:

Python3

Sau đây là loại dữ liệu tiêu chuẩn hoặc tích hợp của Python:

Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
70
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
71

Số

Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
77
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Geeksforgeeks
2
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
80

Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
83
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
85
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
86

Loại trình tự

Boolean

Geeksforgeeks
2
100
8
Geeksforgeeks
01
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Geeksforgeeks
2
Geeksforgeeks
04

Bộ

Geeksforgeeks
2
100
8
Geeksforgeeks
22
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Geeksforgeeks
2
100
8
Geeksforgeeks
05
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Output:

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
3

Từ điển

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
65
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
67

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
4

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
72
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
74y to the variable x.

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
5

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

Geeksforgeeks
2
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
83
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
91
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
86Shared Reference in Python.
Now, if we write:

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
6

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
93
Geeksforgeeks
0
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
95
100
8
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
97
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

IsY, then the previous object refers to the garbage values.

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
7

Hướng dẫn how do you define a name in python? - làm thế nào để bạn xác định một tên trong python?

Tài liệu tham khảo đối tượng

Vui lòng giới thiệu lớp, đối tượng và thành viên để biết thêm chi tiết. & NBSP;

Python3

Geeksforgeeks
28
Geeksforgeeks
29

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
Geeksforgeeks
31
Geeksforgeeks
0 ________ 233 & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;

        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
24
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
22
Geeksforgeeks
36
Geeksforgeeks
37
Geeksforgeeks
38

Geeksforgeeks
39
Geeksforgeeks
37
Geeksforgeeks
41
Geeksforgeeks
0
Geeksforgeeks
43

Before declare:  100
After re-declare: 120.3
8
Geeksforgeeks
0
Geeksforgeeks
46
Geeksforgeeks
47
        class train:
    def __init__(self, name, fare, seats, code):
        self.name = name
        self.fare = fare
        self.seats = seats
        self.code = code

    def train_Status(self):
        print(f"The name of the train is {self.name}")
        print(f"The seats is {self. seats}")

    def fare_Info(self):
        print(f"The fare is {self. fare}")

    def code_Info(self):
        print(f"The code is {self. code}")

    def tickets_Info(self):
        if(self.seats > 0):
            print(
                f"The seats are available for you...\nYour seat number is {self.seats}")
            self.seats = self.seats - 1
        elif(self.seats == 0):
            print("The seats are not available for you...")
        else:
            print("The server isnt updated yet. \nPlease try again later.")

    @staticmethod
    def greeting():
        print("Welcome to Rajdhani express!!")


Inter = train("Inter Express", 180, 12, 239340)
Inter.greeting()
Inter.fare_Info()
Inter.train_Status()
Inter.tickets_Info()
Inter.train_Status()
Inter.code_Info()
78

Geeksforgeeks
2
Geeksforgeeks
55

Geeksforgeeks
2
Geeksforgeeks
57

Geeksforgeeks
2
Geeksforgeeks
59

Geeksforgeeks
2
Geeksforgeeks
61


Làm thế nào để bạn xác định tên trong Python 3?

Dưới đây là các quy tắc đơn giản để xác định một chức năng trong Python. Các khối chức năng bắt đầu với từ khóa def theo sau là tên hàm và dấu ngoặc đơn (()). Bất kỳ tham số đầu vào hoặc đối số nên được đặt trong các dấu ngoặc đơn này. Bạn cũng có thể xác định các tham số bên trong các dấu ngoặc đơn này.Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.

Làm cách nào để xác định một biến trong Python?

Python không có lệnh để khai báo một biến.Một biến được tạo ngay khi bạn chỉ định một giá trị cho nó.. A variable is created the moment you first assign a value to it.

Làm thế nào để bạn đặt một biến một tên?

Các quy tắc cho các biến đặt tên:..
Tất cả các tên biến phải bắt đầu bằng một chữ cái của bảng chữ cái hoặc một.gạch dưới (_).....
Sau chữ cái đầu tiên, tên biến cũng có thể chứa các chữ cái và số.....
Các ký tự chữ hoa khác biệt với các ký tự thường.....
Bạn không thể sử dụng từ khóa C ++ (từ dành riêng) làm tên biến ..

Tên có phải là một biến trong Python không?

Tên biến là nhạy cảm trường hợp (tên, tên và tên là ba biến khác nhau).Các từ dành riêng (từ khóa) không thể được sử dụng đặt tên biến.). The reserved words(keywords) cannot be used naming the variable.