Data Types

Introduction to Programming Input, Process, Output
9 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.60
List Price:  €92.30
You save:  €27.69
£55.40
List Price:  £79.14
You save:  £23.74
CA$95.14
List Price:  CA$135.92
You save:  CA$40.78
A$107.21
List Price:  A$153.17
You save:  A$45.95
S$94.29
List Price:  S$134.71
You save:  S$40.41
HK$547.55
List Price:  HK$782.26
You save:  HK$234.70
CHF 63.39
List Price:  CHF 90.56
You save:  CHF 27.17
NOK kr753.41
List Price:  NOK kr1,076.34
You save:  NOK kr322.93
DKK kr481.90
List Price:  DKK kr688.47
You save:  DKK kr206.56
NZ$116.54
List Price:  NZ$166.49
You save:  NZ$49.95
د.إ257.02
List Price:  د.إ367.19
You save:  د.إ110.16
৳7,699.83
List Price:  ৳11,000.23
You save:  ৳3,300.40
₹5,834.28
List Price:  ₹8,335.05
You save:  ₹2,500.76
RM331.26
List Price:  RM473.25
You save:  RM141.99
₦97,755.03
List Price:  ₦139,656.03
You save:  ₦41,901
₨19,509.87
List Price:  ₨27,872.43
You save:  ₨8,362.56
฿2,546.30
List Price:  ฿3,637.73
You save:  ฿1,091.43
₺2,255.86
List Price:  ₺3,222.80
You save:  ₺966.93
B$348.35
List Price:  B$497.67
You save:  B$149.31
R1,321.80
List Price:  R1,888.37
You save:  R566.56
Лв126.46
List Price:  Лв180.67
You save:  Лв54.20
₩94,455.35
List Price:  ₩134,942
You save:  ₩40,486.65
₪256.23
List Price:  ₪366.06
You save:  ₪109.83
₱3,937.46
List Price:  ₱5,625.18
You save:  ₱1,687.72
¥10,582.69
List Price:  ¥15,118.78
You save:  ¥4,536.09
MX$1,164.09
List Price:  MX$1,663.06
You save:  MX$498.96
QR255.79
List Price:  QR365.44
You save:  QR109.64
P961.07
List Price:  P1,373.02
You save:  P411.94
KSh9,203.68
List Price:  KSh13,148.68
You save:  KSh3,945
E£3,306.33
List Price:  E£4,723.53
You save:  E£1,417.20
ብር3,986
List Price:  ብር5,694.53
You save:  ብር1,708.53
Kz58,526.40
List Price:  Kz83,612.73
You save:  Kz25,086.33
CLP$68,613.99
List Price:  CLP$98,024.19
You save:  CLP$29,410.20
CN¥505.72
List Price:  CN¥722.49
You save:  CN¥216.77
RD$4,149.44
List Price:  RD$5,928.03
You save:  RD$1,778.58
DA9,428.56
List Price:  DA13,469.95
You save:  DA4,041.39
FJ$157.67
List Price:  FJ$225.25
You save:  FJ$67.58
Q547.27
List Price:  Q781.84
You save:  Q234.57
GY$14,690.75
List Price:  GY$20,987.69
You save:  GY$6,296.93
ISK kr9,671.91
List Price:  ISK kr13,817.61
You save:  ISK kr4,145.70
DH707.37
List Price:  DH1,010.57
You save:  DH303.20
L1,234.61
List Price:  L1,763.81
You save:  L529.19
ден3,973.74
List Price:  ден5,677.01
You save:  ден1,703.27
MOP$565.34
List Price:  MOP$807.66
You save:  MOP$242.32
N$1,327.13
List Price:  N$1,895.98
You save:  N$568.85
C$2,582.33
List Price:  C$3,689.21
You save:  C$1,106.87
रु9,350.11
List Price:  रु13,357.88
You save:  रु4,007.76
S/259.70
List Price:  S/371.02
You save:  S/111.31
K268.50
List Price:  K383.60
You save:  K115.09
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,783.85
List Price:  ZK2,548.47
You save:  ZK764.61
L321.17
List Price:  L458.83
You save:  L137.66
Kč1,633.99
List Price:  Kč2,334.38
You save:  Kč700.38
Ft25,496.77
List Price:  Ft36,425.52
You save:  Ft10,928.74
SEK kr741.62
List Price:  SEK kr1,059.50
You save:  SEK kr317.88
ARS$59,963.93
List Price:  ARS$85,666.43
You save:  ARS$25,702.49
Bs486.54
List Price:  Bs695.09
You save:  Bs208.54
COP$272,760.10
List Price:  COP$389,673.99
You save:  COP$116,913.89
₡35,355.24
List Price:  ₡50,509.65
You save:  ₡15,154.41
L1,731.96
List Price:  L2,474.33
You save:  L742.37
₲515,624.88
List Price:  ₲736,638.54
You save:  ₲221,013.66
$U2,646.58
List Price:  $U3,781
You save:  $U1,134.41
zł278.71
List Price:  zł398.17
You save:  zł119.46
Already have an account? Log In

Transcript

Welcome to Lesson 10. We're still working on our input, output and processing. And in this section, we're going to talk about data types. Welcome back. See you in the next slide. So what a data type actually is, is when we work with numbers, when we work with strings, whatever it is that we are working with, we really need to tell our program what type of data is so that it knows how to process it.

So the data types are different category categorized values. Python actually has five standard data types, but there are other programs that have even more data types. C sharp is quite a bit more complicated when it comes to data types. There's a whole lot, a whole lot more data types in there. But the most important thing is that you understand what the data types are. So there are five standard ones that we're just going to cover just to kind of get you used to it.

So We have numbers, we have strings, which remember is the value that you want to show on the screen, you can put in a sentence or whatever you want. There's a list. There's a tuple. And there's a dictionary. Now let's talk on the next slide a little bit more about numbers. So, in the number type of the data type, there are different types of numbers.

There's an int. So for example, that's any number, but it has no decimal values. So say, number 10, for example, even 12345, any of those numbers are int data types. You cannot use anything with a decimal in there or you might have an error with your programs. So we have to limit the end to real numbers. We have long and what long is, is it just gives us a really long amount of numbers.

So we could go now 999999999 it takes so many long numbers, though we don't always use long, because if we use long, it's going to take up more memory space in our program. Okay? So it might be used if you have a smaller number as long as it doesn't get too large. Float is where we're going to use decimals. So for our example, we have zero dot zero, we have a negative 15 dot to zero. So these numbers can be positive or they can be net negative, and typically they're up to six positions.

And then we also have complex, so three dot one for j, for example, 876 j, for example, they're quite a bit more complex. And we'll maybe talk about those in a little bit more detail, but we really want to just First of all, let you know that there are different number types we have int, long, float and complex. And we use them for specific reasons. So we have a real number that isn't too huge we're going to use and if we have a lot of numbers in there, you know, if you're going to have six digits or more, you're going to want to use long float if you need a decimal, and then complex if you need to make a really complex arithmetic to put together, okay. Another data type that you're going to use more commonly than probably anything else is strings. Python strings are indicated to the compiler by using the str keyword.

So we can say str equals hello world, we have to put it in quotes, because that is a rule of Python. Okay. For every language that I know, I don't know all of them, obviously, but for every language that I know, strings are always in quotes. So that's a pretty good default rule. Right there, you're going to add two strings together using the plus sign. So if I have name equals to john, that's gonna be my variables name, I can print, my name is that will print out john.

And maybe I want to add Smith to the end of it. So I use this plus sign. And then I add the quote Smith name is used, because that's going to put the value that is inside the variable, we see that that is equal to john. So the name is going to be john. So when you have the print out, it says My name is john smith. We often use the plus with variables, so the compiler knows to add that on.

To those are a little bit different because you're telling the compiler that you're going to use a list of things. It's not just going to be one variable. Or one number or anything like that, it's going to be a list of things. So tuples is a sequence data type similar to lists, it must be enclosed in parentheses, it cannot be updated. And it's typically thought of as a read only list. So if your list is never going to change, you can use tuples.

But if you plan to change it, I don't recommend that you use a tuple. So here's an example below it says example tuple equal john, comma Smith, comma 124, Third Street comma anywhere comma state comma 55555. So if you had a list of all these elements of john, the comma is going to separate each and every one that belongs in the list. So you might have first name, last name, street address, city, state, and zip code for example. If you use the commands print to ball is gonna print that whole list. If you say print tuple zero is going to print the first element in the list.

The first position in the list always starts with zero, that is never going to change that is a rule, it is something that you'll have to remember. So in this case, if we say print tuple, the first element in our list there is john and that's what's going to be printed. If we say print tuple, one colon five. That means we're going to print the element starting from two because remember, our position starts from zero, it says 012345. Then if we're in the second position, that's actually going to be number one. So one colon five means that it's going to print the elements starting at one, and then it's going to print everything up until number five, so it's going to print it's going to skip john because that's in the zero position.

It's going to print Smith. 124 Third Street, anywhere, stay 5555. But 5555 is not going to print. Okay? That's important to know. Because if you start at one, Smith 2124, Third Street three anywhere for state, it goes until five.

So we need to remember that it's going to start in position one, but it's going to stop at five, which means five is not going to print. If we click, or if we type print tiny tuple times two, then it's going to print the whole list twice. And just want to reiterate, reiterate again on the print tuple one, colon five. Just remember, each spot always starts with zero in a list. So john has zeros Smith is one, one to four Third Street is to anywhere is three, state is four, and 55555 is number five. So if it starts at one, it will start and it will print Smith.

It'll print two because it's between one and five, it'll pick three, because it's between one and five, and it will print four, because it's between one and five. It stops at five and will not print five. All right, yay. Now you know a little bit more about data types. They're important, every programming language. Some languages have more data types than others.

So why would we use an int instead of using along every time? Well remember what we said it comes down to how much space you're using in the program. And if you use too much space, you know, it's gonna run slower for the user and things like that. So we want to try to make sure for performance reasons There we use what we need to use when it comes to space. I'm so glad you could be here for this lesson and I will see you in the next lesson.

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.