{"id":3076,"date":"2022-10-24T20:10:17","date_gmt":"2022-10-24T20:10:17","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3076"},"modified":"2022-10-24T20:10:19","modified_gmt":"2022-10-24T20:10:19","slug":"python-data-types","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-data-types\/","title":{"rendered":"PYTHON DATA TYPES"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>PYTHON DATA TYPES<\/strong><\/p>\n<p>Whenever we are writing python programs, we are usually dealing with some kind of data. For example, if we are writing a program to add two numbers, then the two numbers, which are to be added, are the data, and the result that we have after addition is also some data. In short, we are doing some different things with the data that we have. So, we need to be familiar with the data that we have.<\/p>\n<p>First of all, let\u2019s understand what data is.<\/p>\n<p>Well, data is some piece of information, and it can be anything, like your name, email, address, mobile number, etc&#8230; So, if it is a mobile number, it is going to be a number. On the other hand, if it is your name, it is going to be a string (set of characters), and so on.<\/p>\n<p>So, the data can be of different types like integers, floating point numbers, complex numbers, string, boolean data, etc.. So, to handle, or to work with different types of data, we have got some different data types, and we are going to have a look at those different data types now &#8211;<\/p>\n<p>If you are familiar with other some other programming languages, like C\/C++, or Java, we needed to declare the type of data that the variable was going to hold. But it is not the same thing here in python. Python is a dynamically typed language, which means that we do not specify what type of object is going to be referred by the variable. Instead, we just assign some value of some type to the variable, and then we can directly use that in the program.<\/p>\n<p>So, as we know that we will be using variables to store the values, and the variable has to have some name to access it. Let\u2019s take an example to store some kind of data into some variable.<\/p>\n<ul>\n<li>name = &#8220;GyaniPandit&#8221;<\/li>\n<li>num1 = 4<\/li>\n<li>num2 = 4.8<\/li>\n<li>isHuman = True<\/li>\n<li>complexnum = 3j<\/li>\n<\/ul>\n<p>Above are some variables which are assigned some values, and we did not specify the type of data which will be assigned to the variables. We just directly assigned it.<\/p>\n<p>So, when we do &#8211;<\/p>\n<p style=\"text-align: center;\">name = &#8220;GyaniPandit&#8221;<\/p>\n<p style=\"text-align: left;\">Let\u2019s have a look at some of the datatypes in Python<\/p>\n<ul>\n<li style=\"text-align: left;\">Numbers (integer, floating point number, complex number)<\/li>\n<li style=\"text-align: left;\">Boolean (bool) (this is for True or False things)<\/li>\n<li style=\"text-align: left;\">Strings. (Character is just a single-length string, as we will see later in detail, but string can be defined as a set of characters)<\/li>\n<li style=\"text-align: left;\">List &#8211; A list is used to store the collection of data. This will be seen later in the course.<\/li>\n<li style=\"text-align: left;\">Tuples &#8211; Tuples are also used to store collection of data, but the thing is that tuples are immutable.<\/li>\n<li style=\"text-align: left;\">Set &#8211; set is an unordered and un\u2013indexed collection of data, in which, only unique values are allowed.<\/li>\n<li style=\"text-align: left;\">Dictionary &#8211; This is used to store key \u2013 value pairs (just like a dictionary, which has a word and it\u2019s meaning). You can change or add the contents in the dictionary, but duplicate keys are not allowed in the dictionary. We will see this concept later in the course<\/li>\n<li style=\"text-align: left;\">frozenset \u2013 frozenset is an immutable version of a python set.<\/li>\n<li style=\"text-align: left;\">bytes \u2013 This is one of the inbuilt types for manipulating binary data. The bytes objects are immutable sequences of single bytes. Here, the allowed values are in the range of 0 to 255(both included)<\/li>\n<li style=\"text-align: left;\">bytearray \u2013 The bytearray object is a mutable counterpart for the bytes object. So, simply we can say that the bytes object is immutable, while the bytearray is mutable.<\/li>\n<li style=\"text-align: left;\">memoryview \u2013 The memoryview Let\u2019s us access the object&#8217;s internal data(the object should support buffer protocol).<\/li>\n<\/ul>\n<p style=\"text-align: left;\">We are soon going to play around with many of these concepts so don&#8217;t worry, this is not even an introduction to these concepts (just an acquaintance though, to the names of the concepts so that when we will see them later, they won\u2019t feel alien to you).<\/p>\n<p style=\"text-align: left;\">You just need to understand for now, that there are some different data types to deal with some different types of data. Soon, when we would start using this data, and gradually, we would become familiar with these data types. The thing is that in python, everything is an object, so the datatypes here, are actually classes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PYTHON DATA TYPES Whenever we are writing python programs, we are usually dealing with some kind of data. For example, if we are writing a program to add two numbers, then the two numbers, which are to be added, are the data, and the result that we have after addition is also some data. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3076","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3076"}],"version-history":[{"count":3,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3076\/revisions"}],"predecessor-version":[{"id":3541,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3076\/revisions\/3541"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}