jagomart
digital resources
picture1_Python Pdf 184474 | Alevel 1 Python 7apr Ss


 133x       Filetype PDF       File size 0.54 MB       Source: www.nielit.gov.in


File: Python Pdf 184474 | Alevel 1 Python 7apr Ss
programming and problem solving through python language o level a level chapter 3 introduction to python language data types the data stored in memory can be of many types for ...

icon picture PDF Filetype PDF | Posted on 01 Feb 2023 | 2 years ago
Partial capture of text on file.
                     
                    Programming and Problem Solving through Python  Language 
                    O Level / A Level 
                     
                    Chapter -3: Introduction to Python Language 
                     
                    Data Types 
                     
                    The data stored in memory can be of many types. For example, a person's age 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. Variables can store data of different types, and different types can do 
                    different things. 
                     
                     Python has five standard data types − 
                             Numbers 
                             String 
                             List 
                             Tuple 
                             Dictionary 
                     
                    Python has the following data types built-in by default, in these categories: 
                     
                              Text Type:                      str 
                              Numeric Types:                  int, float, complex 
                              Sequence Types:                 list, tuple, range 
                              Mapping Type:                   dict 
                              Set Types:                      set, frozenset 
                              Boolean Type:                   bool 
                              Binary Types:                   bytes, bytearray, memoryview 
                     
                    Example of Data Types 
                     
                              Example                                                                         Data Type 
                              x = "Hello World"                                                               str 
                              x = 20                                                                          int 
                              x = 20.5                                                                        float 
                              x = 1j                                                                          complex 
                       x = ["apple", "banana", "cherry"]                            list 
                       x = ("apple", "banana", "cherry")                            tuple 
                       x = range(6)                                                 range 
                       x = {"name" : "John", "age" : 36}                            dict 
                       x = {"apple", "banana", "cherry"}                            set 
                       x = frozenset({"apple", "banana", "cherry"})                 frozenset 
                       x = True                                                     bool 
                       x = b"Hello"                                                 bytes 
                       x = bytearray(5)                                             bytearray 
                       x = memoryview(bytes(5))                                     memoryview 
                 
                Setting the Specific Data Type 
                 
                If you want to specify the data type, you can use the following constructor functions: 
                 
                       Example                                                   Data Type 
                       x = str("Hello World")                                    str 
                       x = int(20)                                               int 
                       x = float(20.5)                                           float 
                       x = complex(1j)                                           complex 
                       x = list(("apple", "banana", "cherry"))                   list 
                       x = tuple(("apple", "banana", "cherry"))                  tuple 
                       x = range(6)                                              range 
                       x = dict(name="John", age=36)                             dict 
                       x = set(("apple", "banana", "cherry"))                    set 
                       x = frozenset(("apple", "banana", "cherry"))              frozenset 
                       x = bool(5)                                               bool 
                       x = bytes(5)                                              bytes 
                       x = bytearray(5)                                          bytearray 
                       x = memoryview(bytes(5))                                  memoryview 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                     
                    Python Numbers 
                     
                    Number data types store numeric values. 
                     
                                                                                   −
                     Python supports four different numerical types   
                             int (signed integers) 
                             long (long integers, they can also be represented in octal and hexadecimal) 
                             float (floating point real values) 
                             complex (complex numbers) 
                                   o    Python allows you to use a lowercase l with long, but it is recommended that you 
                                        use only an uppercase L to avoid confusion with the number 1. Python displays 
                                        long integers with an uppercase L. 
                                   o    A complex number consists of an ordered pair of real floating-point numbers 
                                        denoted by x + yj, where x and y are the real numbers and j is the imaginary unit. 
                    Int 
                     
                        Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. 
                         
                        Example  Integers: 
                        x = 1 
                        y = 35656222554887711 
                        z = -3255522 
                     
                    Float 
                     
                        Float, or "floating point number" is a number, positive or negative, containing one or more 
                        decimals. 
                         
                        Example  Floats: 
                        x = 1.10 
                        y = 1.0 
                        z = -35.59 
                         
                        Float can also be scientific numbers with an "e" to indicate the power of 10. 
                         
                        Example Floats: 
                        x = 35e3 
                        y = 12E4 
                        z = -87.7e100 
                     
                    Complex 
                     
                        Complex numbers are written with a "j" as the imaginary part: 
                        Example   Complex: 
                        x = 3+5j 
                        y = 5j 
                        z = -5j 
        
       Type Conversion 
        
       We can convert from one type to another with the int(), float(), and complex() methods: 
        
       Example 
        
       Convert from one type to another: 
       x = 1 # int 
       y = 2.8 # float 
       z = 1j # complex 
        
       #convert from int to float: 
       a = float(x) 
        
       #convert from float to int: 
       b = int(y) 
        
       #convert from int to complex: 
       c = complex(x) 
        
       print(a) 
       print(b) 
       print(c) 
        
       print(type(a)) 
       print(type(b)) 
       print(type(c)) 
        
The words contained in this file might help you see if this file matches what you are looking for:

...Programming and problem solving through python language o level a chapter introduction to data types the stored in memory can be of many for example person s age is as numeric value his or her address alphanumeric characters has various standard that are used define operations possible on them storage method each variables store different do things five numbers string list tuple dictionary following built by default these categories text type str int float complex sequence range mapping dict set frozenset boolean bool binary bytes bytearray memoryview x hello world j apple banana cherry name john true b setting specific if you want specify use constructor functions number values supports four numerical signed integers long they also represented octal hexadecimal floating point real allows lowercase l with but it recommended only an uppercase avoid confusion displays consists ordered pair denoted yj where y imaginary unit integer whole positive negative without decimals unlimited length...

no reviews yet
Please Login to review.