+ 12

What are the data-types in python?

16th Nov 2018, 2:10 PM
Deepak n p
34 Antworten
+ 18
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
16th Nov 2018, 3:34 PM
David Carroll
David Carroll - avatar
+ 12
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?
16th Nov 2018, 3:03 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 8
Int, float, string, boolean,…
16th Nov 2018, 2:20 PM
Roneel
Roneel - avatar
+ 8
Here is a really good summary of the data types in Python. https://www.programiz.com/python-programming/variables-datatypes#types
16th Nov 2018, 2:51 PM
David Carroll
David Carroll - avatar
+ 4
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?
16th Nov 2018, 2:45 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
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 ...
16th Nov 2018, 2:51 PM
HonFu
HonFu - avatar
+ 4
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.
16th Nov 2018, 2:54 PM
Anya
Anya - avatar
+ 4
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.
16th Nov 2018, 3:06 PM
Anya
Anya - avatar
+ 4
Anya so NoneType is not a type, even though "None" is a value of this type? I guess I need sleep 😂
16th Nov 2018, 3:52 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
Deepak n p I imagine it would be difficult to support data types with precision or size variants in a dynamic language where the type is inferred and set based on the value at the time of assignment. Without explicit type declaration, differentiating between an int32 and an int64 or float variants based on the assigned values alone would not be possible. I speculate this is the reason languages like Javascript, PHP, and Python started out with the largest of the assumed data type variants.
16th Nov 2018, 3:53 PM
David Carroll
David Carroll - avatar
+ 3
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
16th Nov 2018, 3:32 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
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
24th Dec 2019, 7:36 PM
Gwendolyn Phillips de Ashborough
Gwendolyn Phillips de Ashborough - avatar
+ 2
🙏🙏🙏🙏🙏 Kishalaya Saha
16th Nov 2018, 2:48 PM
Roneel
Roneel - avatar
+ 2
Kishalaya Saha Actually I had some smell in question that it's asking what data types are. Not listing all the datatypes.
16th Nov 2018, 2:52 PM
Roneel
Roneel - avatar
+ 2
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
16th Nov 2018, 3:13 PM
Anya
Anya - avatar
+ 2
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?
16th Nov 2018, 3:31 PM
Deepak n p
+ 2
Kishalaya Saha . Null or none is the representation of absence of data. So doesn't fit in a type.
16th Nov 2018, 3:44 PM
Anya
Anya - avatar
+ 2
int,float,string,boolean,none
20th Oct 2020, 11:43 AM
Ousmane Leye
Ousmane Leye - avatar
+ 1
Right, I forgot the special types like maps and the like. ^^' Yeah, not all that simple!
16th Nov 2018, 2:58 PM
HonFu
HonFu - avatar
+ 1
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
7th Sep 2019, 10:37 AM
Subham Mehta
Subham Mehta - avatar