Page 437 - ComputerScience_Class_11
P. 437

iNtroductioN to PytHoN







                                                                       data tyPeS iN PytHoN
















                        Learning Objectives


                    12.1  Data Types                                  12.2  Numeric
                    12.3  Boolean                                     12.4  Sequence
                    12.5  None                                        12.6  Dictionary
                    12.7  Set                                         12.8  Mutable and Immutable


                 In the previous chapter, you learned that variables are like containers that hold data in a program. But what kind of data
                 can they hold? Just as in mathematics we have different types of numbers (natural, integers, real), in programming, we
                 have different data types. A data type is a classification that tells the Python interpreter what type of value a variable
                 holds and, more importantly, what operations can be performed on it.
                 Python is a dynamically typed language. This means you don't have to declare the data type of a variable explicitly. The
                 interpreter infers the type based on the value you assign. For example, if you write age = 25, Python understands age
                 is an integer. This makes coding faster and more flexible.
                 This chapter provides a detailed exploration of the fundamental built-in data types in Python, which are essential for
                 solving any computational problem.

                     12.1 DATA TYPES
                 A data type is a category that defines the kind of value a variable can store and the operations that can be performed
                 on it. It helps the computer understand how the data is represented and processed in memory. The data stored in
                 memory can be of many types. For example, a student roll number is stored as a numeric value and his or her address
                 is stored as alphanumeric characters. Python has various standard data types that are used to define the operations
                 possible on them and the storage method for each of them.
                 The following tree structure shows the various data types used in Python:

                                                                    Data Types




                                 Numeric         Boolean             Sequence      None      Dictionary     Set




                        Integer  Floating  Complex           String     List    Tuple





                                                                                               Data Types in Python  435
   432   433   434   435   436   437   438   439   440   441   442