Practical - Python fundamentals working with data types and structures

10 minutes
Share the link to this page
You need to have access to the item to view this lesson.
One-time Fee
List Price:  $99.99
You save:  $30
List Price:  €91.91
You save:  €27.57
List Price:  £78.24
You save:  £23.47
List Price:  CA$136.26
You save:  CA$40.88
List Price:  A$150.08
You save:  A$45.03
List Price:  S$134.76
You save:  S$40.43
List Price:  HK$781
You save:  HK$234.32
CHF 63.74
List Price:  CHF 91.06
You save:  CHF 27.32
NOK kr733.71
List Price:  NOK kr1,048.21
You save:  NOK kr314.49
DKK kr480.07
List Price:  DKK kr685.84
You save:  DKK kr205.77
List Price:  NZ$162.33
You save:  NZ$48.70
List Price:  د.إ367.26
You save:  د.إ110.18
List Price:  ৳11,731.26
You save:  ৳3,519.73
List Price:  ₹8,317.71
You save:  ₹2,495.56
List Price:  RM469.33
You save:  RM140.81
List Price:  ₦148,231.17
You save:  ₦44,473.80
List Price:  ₨27,822.22
You save:  ₨8,347.50
List Price:  ฿3,663.18
You save:  ฿1,099.06
List Price:  ₺3,217.78
You save:  ₺965.43
List Price:  B$517.30
You save:  B$155.20
List Price:  R1,838.27
You save:  R551.53
List Price:  Лв179.77
You save:  Лв53.93
List Price:  ₩135,868.90
You save:  ₩40,764.74
List Price:  ₪367.61
You save:  ₪110.29
List Price:  ₱5,798.37
You save:  ₱1,739.68
List Price:  ¥15,685.04
You save:  ¥4,705.98
List Price:  MX$1,668
You save:  MX$500.45
List Price:  QR364.44
You save:  QR109.34
List Price:  P1,357.41
You save:  P407.26
List Price:  KSh13,248.67
You save:  KSh3,975
List Price:  E£4,750.52
You save:  E£1,425.30
List Price:  ብር5,701.46
You save:  ብር1,710.61
List Price:  Kz85,175.48
You save:  Kz25,555.20
List Price:  CLP$90,154.52
You save:  CLP$27,049.06
List Price:  CN¥710.85
You save:  CN¥213.27
List Price:  RD$5,887.39
You save:  RD$1,766.39
List Price:  DA13,451.22
You save:  DA4,035.77
List Price:  FJ$222.79
You save:  FJ$66.84
List Price:  Q776.56
You save:  Q232.99
List Price:  GY$20,927.06
You save:  GY$6,278.74
ISK kr9,619.42
List Price:  ISK kr13,742.62
You save:  ISK kr4,123.20
List Price:  DH992.71
You save:  DH297.84
List Price:  L1,770.84
You save:  L531.30
List Price:  ден5,663.20
You save:  ден1,699.13
List Price:  MOP$804.09
You save:  MOP$241.25
List Price:  N$1,836.24
You save:  N$550.92
List Price:  C$3,679.74
You save:  C$1,104.03
List Price:  रु13,290.03
You save:  रु3,987.40
List Price:  S/374.22
You save:  S/112.27
List Price:  K388.75
You save:  K116.63
List Price:  SAR375.02
You save:  SAR112.51
List Price:  ZK2,676.76
You save:  ZK803.10
List Price:  L457.35
You save:  L137.22
List Price:  Kč2,266.28
You save:  Kč679.95
List Price:  Ft35,262.40
You save:  Ft10,579.78
SEK kr737.43
List Price:  SEK kr1,053.51
You save:  SEK kr316.08
List Price:  ARS$89,341.06
You save:  ARS$26,805
List Price:  Bs690.78
You save:  Bs207.25
List Price:  COP$386,878.04
You save:  COP$116,075.02
List Price:  ₡51,410
You save:  ₡15,424.54
List Price:  L2,470.46
You save:  L741.21
List Price:  ₲752,075.57
You save:  ₲225,645.23
List Price:  $U3,849.38
You save:  $U1,154.93
List Price:  zł390.87
You save:  zł117.27
Already have an account? Log In


In the previous video, I showed you how to write a very simple Python script. In this video, I will show you how to work with data types and structures. As you can see, there is a text written at the top of the shell. That is the result of running a script. There is a message that says, this is a puzzle that you have to resolve. How did this message come up?

Try to pause the video and think about it. When you think you have the answer, click on Play and see what code produces this outcome? The answer is that this text appears. If you type print, parenthesis, nd the text written between quotation marks. For this tutorial, we will use idle Python since we will write small codes in interactive shell, we will set a variable called that equals to four, then press enter. After that, type print and between parentheses and hit enter, the result will appear.

Basically the shelf knows what r is from the previous line. Because it is stored in memory, we can do more with this memory data. We can add values, multiply the result and raise it to power. Remember to use parenthesis to group the operations. If you do not use parenthesis, the result is different. There are some rules to set variable.

Rule number one is style. You can use words or strings. To name a variable. lowercase letter, uppercase letters, lowercase strings, uppercase strings, lowercase or uppercase with underscore capitalized words and mixed case rule to make sure to avoid some characters, like lowercase L, uppercase O, uppercase I, as a single character variable names, since in some fonts, these characters are indistinguishable from numbers one and zero. Use uppercase l instead of lowercase l do not use numbers or special characters as first character of the string Some words such as print, while four, and others are reserved identifiers, there are some considerations when you use functions, constants, classes and modules. However, I will go into detail in the next videos.

Now, we can ask ourselves, how could we change or reassign the value of the variable? Well, right and set the new value for it. That is equal to 10. Then press enter. When you do this, print the value of the variable to check it if it is changed its value. Python works with dynamic assignment.

Notice that in this case, the very Ah holds an integer. However, this could change to make a new assignment, Write hello world, and then press enter, then check if its value holds the string, hello, world. Even though you do, you don't need to write any declarative statement. To set the variable with a different data type. You have to be careful when you manipulate variables into different points of the program. Let's make another example.

Right, B equal five and press enter. Then write C equal three and press Enter. Now print the multiplication of B by see and press enter. You will notice that the Oh Come up the shell is the multiplication of B by C. Now write the underscore sign and press ENTER again, you will get the outcome of when you check a last time. So you can use the print function when you don't want to save the result on the operation. In the variable underscore.

There are different types of data in Python. This is Boolean, numeric sequence and set mapping. The last three data types contain the standard data structures like lists, tuples, dictionaries, strings, and sets. So in this tutorial, we are going to work with numeric type Python supports for Different numerical type, short or signed integers, long integers represented by decimal, octal, and hexadecimal floating point, real value and complex numbers. Keep in mind that all integers in Python three are long integers. Hence, there is no separate number type as long.

For example, when you set a variable to minus 10 that is an equal minus 10, which holds an integer. On the other hand, if you write b equal minus 10.0 B will hold a floating point value. However, if we compare these values, two times equal sign these and press enter. You will notice the result is true since they represent the same value. Now check if you assign minus 10 plus 0.0 G to C complex number and then you compare with a or b. What did you get?

You should get true again, even when the type of number is different, okay. Once you do that, change the value of b by nine, then divide a by b and press enter. The result is minus 1.11. Notice that the result is a floating point value, even though both value A and B integers. However, if you try to make this operation in Python two, the result will be minus two and an integer value. Since both are integers, this is a difference when you work with version two and version three.

On the other hand, if you divide B by A, the result will be minus 0.9. So what would be the result? If you do the same operation in version two, the answer is minus one, since it's an integer division, in other words, the result will be an integer without a fractional part. So keep that in mind when you work with version two or three. If you want to make an integer division in version three, you have to use the slash, notice that you will get back minus two as a result of the operation, which is the truncated result of the division. Besides, if you want to evaluate the remainder of the Division of 14 by three, you have to type in 14 percentage sign three.

In this case, the result would be to Python allows you to assign a single value to several variables simultaneously. That is right, x equal y equals that equal one, and then press enter. After that, print each variable you will notice that all hold the same value. Also, multiple variables can be assigned at the same line, which keeps your script compact. To make this write x comma y comma Zed equals one, comma four, comma seven, and press Enter. Now check if x is equal to one, y is equal to four, and Zed is equal to seven.

That's all for this tutorial. I hope you like it. And you want to watch more tutorials about Python and GIS

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.