+ 12
What are the data-types in python?
34 Respuestas
+ 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
+ 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?
+ 8
Int, float, string, boolean,…
+ 8
Here is a really good summary of the data types in Python.
https://www.programiz.com/python-programming/variables-datatypes#types
+ 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 ...
+ 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.
+ 4
Anya so NoneType is not a type, even though "None" is a value of this type?
I guess I need sleep 😂
+ 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.
+ 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
+ 2
🙏🙏🙏🙏🙏
Kishalaya Saha
+ 2
Kishalaya Saha
Actually I had some smell in question that it's asking what data types are. Not listing all the datatypes.
+ 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
+ 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?
+ 2
Kishalaya Saha . Null or none is the representation of absence of data. So doesn't fit in a type.
+ 2
int,float,string,boolean,none
+ 1
Right, I forgot the special types like maps and the like. ^^'
Yeah, not all that simple!
+ 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