Page 108 - TCS ICT Book 8
P. 108

The City School  2021-2022




             This illustrates another great aspect of python and that is dynamic typing. This

             concept is defined with respect to the point at which the variable data types are
             checked. In our code, the variable is score which holds the value 9 which is a number,
             or we can label it as a data. A variable just stores the value, whereas the value could

             be of different data types. The data type defines the type of data that is stored in the

             variable.
             Being said that, dynamic type languages are those in which the data type checking
             is done at the run time. We don’t have to declare the data type in our code in python.

             Python is smart enough to judge which data type is being held by the variable.

             Data Types in Python


             Values have types, every piece of data has to have a type associated with it so it
             knows what it is dealing with. Python sets the variable type based on the value that is

             assigned to it. Following are the data types which will be used throughout in coding:

             Numbers: integers and float
             String: any character or text

             Boolean: true or false


            5.6.  LIST in Python

             In Python, you can store your data into variables, but you can also put them in lists. A

             list is just an ordered collection of items which can be of any data type. Creating a list
             is as simple as putting different comma separated values between square brackets.

             Each element of a list is assigned a value by using an index.
             An example of list could be: newList=[10,20,30,”Samsung”]

             To call or print a specific element of list, write the following code:


            Sample code:

             # This defines a list called newList
             newList=[10,20,30,”Samsung”]

             # Prints the third element in the list; starting from 0

             print(newList[3])
















                                                                                                                108
   103   104   105   106   107   108   109   110   111   112   113