Multiple (Beginner level) Questions About data types (Help for Beginner, the concept is really confusing)

Context: I was reading an article on python data types and there I read this line “Python has many built in data types it supports.”. Now my questions are:


  1. Aren’t data types always built in? Aren’t all data types built in? and if a data type is not built, can we build it on our own?

  2. Plus, if a language does not support a data type, say integers, so does that mean that language can not take an integer as an input?

  3. Are they some type of functions like precoded things or like operators which are symbols that indicate the compiler what operation to perform (like maybe the compiler sees “” in a value and determines it is a string, how does it work really)? Or some type of variable or space in memory where if a value is integer type then it stores the value in that memory space? The concept is very abstract.

  4. Lastly, why are they used anyway? And how does the compiler “know” if the data type and so what if it knows?

  5. How do programmers build this data type? Like do they write code that says, there are different types of data and here is how to recognize these? How exactly does that happen?

Thank you for reading my long post and answering the questions in advance.

1 Like
  1. Data types aren’t always built in. A class, for example, is a user-defined data type since the user has to tell the compiler what code to associate with that class.

    By letting the user code their own data type, we can create complex data structures like linked lists that are made of user-defined nodes instead of a built-in primitive types.

  2. If a language doesn’t support integers, that doesn’t mean it couldn’t take them as an input. It just means that it would treat integer inputs as something else. For example, if the language only supports strings, it would treat any integer input as a string. That means that if you wanted to do some integer logic like 1+1, you’d have to code that functionality in yourself to get 2, otherwise you’d probably get 11.

  3. How the compiler decides a data type depends on the language. If it’s statically typed like Java, you need to specifically define the type of each variable at compile time, whether it’s a built-in primitive type or a type that you defined yourself.

    On the other hand, dynamically typed languages often try to guess what the type is by context at run-time. This means that if a number is left on its own, it might try to give it a numerical type. But if you put quotes around it, it’ll treat it as a string instead. This is quite abstract.

  4. We need data types in order to maintain consistency of operations between them, check that the right kind of data is being passed throughout the code, and ensure that the right amount of memory is allocated to any given variable.

    There are some data types that are large and require a lot of memory for each variable. If we know that a certain type of variable is only going to contain “true” or “false”, it wouldn’t make sense to give it as much memory as a variable that would contain a huge, astronomical number.

    Also, enforcing data types is important for code to run smoothly and correctly. If you work at a bank and write a function to calculate some kind of money transaction, you don’t want to accidentally allow a string to make its way in there and cause an unexpected error. By defining exactly what data should go where, you stop these kinds of bugs early and improve the performance of the system.

  5. Primitive types are built into the programming language at a fundamental level. Programmers that design languages will write code that defines how memory allocation should work for certain data types along with their behavior when they interact with other parts of code. Then, the compiler will decide how those operations translate to computer instructions and how they should be executed to run the code that you specified.

Let me know if you have any more questions.


Just a comment: @arct, that was an excellent answer!

1 Like

Thank you so much for the help @arct. I really have a clarity on things right now. My apologies for the late reply.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.