Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
as per question, in Python2.7, i want to declare a list object that only allows objects of class 'X' to be managed (appended, deleted etc.).

Can I do this simply, do I need a class hierarchy, or...??

in C, I might do:-
C#
GenericList<float> list1 = new GenericList<float>();

Any attempt to add an object other than type float, would result in an error.

type
Thanks

What I have tried:

Nothing - don't know how to do this , python seems loosely typed.
Posted
Updated 15-Jun-18 2:24am

1 solution

You can use 2. Built-in Functions — isinstance[^] to check the type of an object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900