Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

1 of 2
Escualo
  • 42.5k
  • 27
  • 95
  • 139

From the Python Official Documentation:

9.7. Odds and Ends

Sometimes it is useful to have a data type similar to the Pascal "record" or C "struct", bundling together a few named data items. An empty class definition will do nicely:

class Employee:
 pass
john = Employee() # Create an empty employee record
# Fill the fields of the record 
john.name = 'John Doe' 
john.dept = 'computer lab' 
john.salary = 1000

This seems natural and simple: Pythonic. Remember the Zen! "Simple is better than complex" (number 3) and "If the implementation is easy to explain, it may be a good idea" (number 11)

Escualo
  • 42.5k
  • 27
  • 95
  • 139

AltStyle によって変換されたページ (->オリジナル) /