34 AnswersNew Answer
The confusion around data types may stem from the differences in how they are implemented across different languages. This is especially true when a Java developer is learning C# or vice versa. In Java, there are primitive data types and complex types. This is much different for C# where the distinction of types are value and reference types. An int in C#, is a value type, which is an object or, rather, an instance of a struct. This allows .NET to work with built-in (or primitive) types and complex types in a uniform manner. Python is similar to C# in that built-in data types are all objects that are instances of some class or struct complex type. Here is a good article to explain further: https://medium.com/omarelgabrys-blog/primitive-data-types-in-c-vs-java-5b8a597eef05
Yeah, Anya , I refer to the built-in type documentation quite often: https://docs.python.org/3/library/stdtypes.html David Carroll 's link seems to show a subset of that. But I'm still unsure whether I should call sequence types like list, tuple etc data types. To me, they're more like data structures. Or are they both?
Int, float, string, boolean,…
Here is a really good summary of the data types in Python. https://www.programiz.com/python-programming/variables-datatypes#types
Anya so NoneType is not a type, even though "None" is a value of this type? I guess I need sleep 😂
I have completed the Python tutorial too. And to be honest, if someone asks me to list all the built-in data types, I might make mistakes. List and tuple are data structures I guess, even though the docs sometimes call them "data type". So Roneel , would you please teach us?
I'd have a hard time knowing how well the tutorial prepares us, since I'm also learning from books. There, everything was treated equally as 'data-type': numbers, containers, booleans and the like. Well, if you think OOP, everything that has a 'capsule' can be considered a datatype. In Python that would be... well... everything? :) You can decide between built-ins, standard library types, self-defined types... singular or containing... Yeah, not that easy. From the top of my head (as in that book I mentioned): int, float, complex, str, list, set, frozenset, bytes, bytearray, bool, None, dict, tuple... damn, what have I missed ...
A simple division: Built-in data types Specialized data types In built in type you have : Numeric types. Like: int, float, complex. Sequence Mapping ... In specialized data types can be date and time, heap queue and many others. I recommend read Python documentation because exist a lot of types and classifications to explain.
HonFu and it's not simple. If you compare a standart classification of types and try to map into python classifications and vice-versa it'ts not easy. Even authors have many disagreements.
Anya, thanks so much! So in other words, it's confusing and no general consensus exists 😂 And where does "None" fit in in the official classification of data types? I couldn't locate it. It's listed in the page for built-in constants though: https://docs.python.org/3/library/constants.html
Python 3.8 has the Following Data Types: Python also provides some built-in data types, in particular, dict, list, set and frozenset, and tuple. The str class is used to hold Unicode strings, and the bytes and bytearray classes are used to hold binary data. datetime — Basic date and time types Aware and Naive Objects Constants Available Types Common Properties Determining if an Object is Aware or Naive timedelta Objects Examples of usage: timedelta date Objects Examples of Usage: date datetime Objects Examples of Usage: datetime time Objects Examples of Usage: time tzinfo Objects timezone Objects strftime() and strptime() Behavior strftime() and strptime() Format Codes Technical Detail calendar — General calendar-related functions collections — Container datatypes ChainMap objects ChainMap Examples and Recipes Counter objects deque objects deque Recipes defaultdict objects defaultdict Examples namedtuple() Factory Function f
🙏🙏🙏🙏🙏 Kishalaya Saha
Kishalaya Saha Actually I had some smell in question that it's asking what data types are. Not listing all the datatypes.
Kishalaya Saha both. Depends more which classification you want to use. In a more traditional classification list and tuples are called non primitive data structures. Non primitive data structures can be divided in Linear and Non Linear
Kishalaya Saha . Null or none is the representation of absence of data. So doesn't fit in a type.
Right, I forgot the special types like maps and the like. ^^' Yeah, not all that simple!
bool: Boolean (true/false) types. Supported precisions: 8 (default) bits.int: Signed integer types. Supported precisions: 8, 16, 32 (default) and 64 bits.uint: Unsigned integer types. Supported precisions: 8, 16, 32 (default) and 64 bits.float: Floating point types. Supported precisions: 16, 32, 64 (default) bits and extended precision floating point .complex: Complex number types. Supported precisions: 64 (32+32), 128 (64+64, default) bits and extended precision complex (see note on floating point types).string: Raw string types. Supported precisions: 8-bit positive multiples.time: Data/time types. Supported precisions: 32 and 64 (default) bits.enum: Enumerated types. Precision depends on base type. But sets and directories and tupuls are data types?
Data types are int, float, strg.. What these can be intialized automatically.. There is no need to declare any datatype in python as compared to cpp or c
Int >This is for numbers. float > This is for decimal numbers. string > This is for words, characters and numbers enclosed in single or double quotes. boolean>This is for True or false statements.