Practical - Python fundamentals working with data types and structures

10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.33
List Price:  €91.91
You save:  €27.57
£54.76
List Price:  £78.24
You save:  £23.47
CA$95.38
List Price:  CA$136.26
You save:  CA$40.88
A$105.05
List Price:  A$150.08
You save:  A$45.03
S$94.33
List Price:  S$134.76
You save:  S$40.43
HK$546.67
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
NZ$113.63
List Price:  NZ$162.33
You save:  NZ$48.70
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,211.53
List Price:  ৳11,731.26
You save:  ৳3,519.73
₹5,822.15
List Price:  ₹8,317.71
You save:  ₹2,495.56
RM328.51
List Price:  RM469.33
You save:  RM140.81
₦103,757.37
List Price:  ₦148,231.17
You save:  ₦44,473.80
₨19,474.72
List Price:  ₨27,822.22
You save:  ₨8,347.50
฿2,564.11
List Price:  ฿3,663.18
You save:  ฿1,099.06
₺2,252.35
List Price:  ₺3,217.78
You save:  ₺965.43
B$362.10
List Price:  B$517.30
You save:  B$155.20
R1,286.74
List Price:  R1,838.27
You save:  R551.53
Лв125.83
List Price:  Лв179.77
You save:  Лв53.93
₩95,104.15
List Price:  ₩135,868.90
You save:  ₩40,764.74
₪257.31
List Price:  ₪367.61
You save:  ₪110.29
₱4,058.68
List Price:  ₱5,798.37
You save:  ₱1,739.68
¥10,979.06
List Price:  ¥15,685.04
You save:  ¥4,705.98
MX$1,167.55
List Price:  MX$1,668
You save:  MX$500.45
QR255.10
List Price:  QR364.44
You save:  QR109.34
P950.14
List Price:  P1,357.41
You save:  P407.26
KSh9,273.67
List Price:  KSh13,248.67
You save:  KSh3,975
E£3,325.22
List Price:  E£4,750.52
You save:  E£1,425.30
ብር3,990.85
List Price:  ብር5,701.46
You save:  ብር1,710.61
Kz59,620.28
List Price:  Kz85,175.48
You save:  Kz25,555.20
CLP$63,105.46
List Price:  CLP$90,154.52
You save:  CLP$27,049.06
CN¥497.57
List Price:  CN¥710.85
You save:  CN¥213.27
RD$4,120.99
List Price:  RD$5,887.39
You save:  RD$1,766.39
DA9,415.45
List Price:  DA13,451.22
You save:  DA4,035.77
FJ$155.95
List Price:  FJ$222.79
You save:  FJ$66.84
Q543.57
List Price:  Q776.56
You save:  Q232.99
GY$14,648.31
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
DH694.87
List Price:  DH992.71
You save:  DH297.84
L1,239.53
List Price:  L1,770.84
You save:  L531.30
ден3,964.07
List Price:  ден5,663.20
You save:  ден1,699.13
MOP$562.84
List Price:  MOP$804.09
You save:  MOP$241.25
N$1,285.31
List Price:  N$1,836.24
You save:  N$550.92
C$2,575.71
List Price:  C$3,679.74
You save:  C$1,104.03
रु9,302.62
List Price:  रु13,290.03
You save:  रु3,987.40
S/261.94
List Price:  S/374.22
You save:  S/112.27
K272.11
List Price:  K388.75
You save:  K116.63
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,873.65
List Price:  ZK2,676.76
You save:  ZK803.10
L320.13
List Price:  L457.35
You save:  L137.22
Kč1,586.33
List Price:  Kč2,266.28
You save:  Kč679.95
Ft24,682.62
List Price:  Ft35,262.40
You save:  Ft10,579.78
SEK kr737.43
List Price:  SEK kr1,053.51
You save:  SEK kr316.08
ARS$62,536.06
List Price:  ARS$89,341.06
You save:  ARS$26,805
Bs483.53
List Price:  Bs690.78
You save:  Bs207.25
COP$270,803.02
List Price:  COP$386,878.04
You save:  COP$116,075.02
₡35,985.46
List Price:  ₡51,410
You save:  ₡15,424.54
L1,729.24
List Price:  L2,470.46
You save:  L741.21
₲526,430.33
List Price:  ₲752,075.57
You save:  ₲225,645.23
$U2,694.45
List Price:  $U3,849.38
You save:  $U1,154.93
zł273.60
List Price:  zł390.87
You save:  zł117.27
Already have an account? Log In

Transcript

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

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.