Python Tuple

13 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
€65.22
List Price:  €93.18
You save:  €27.95
£56.04
List Price:  £80.07
You save:  £24.02
CA$96.09
List Price:  CA$137.28
You save:  CA$41.18
A$106.44
List Price:  A$152.07
You save:  A$45.62
S$94.93
List Price:  S$135.63
You save:  S$40.69
HK$547
List Price:  HK$781.46
You save:  HK$234.46
CHF 63.65
List Price:  CHF 90.94
You save:  CHF 27.28
NOK kr765.05
List Price:  NOK kr1,092.98
You save:  NOK kr327.92
DKK kr486.48
List Price:  DKK kr695
You save:  DKK kr208.52
NZ$116.68
List Price:  NZ$166.69
You save:  NZ$50.01
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,685.71
List Price:  ৳10,980.05
You save:  ৳3,294.34
₹5,844.71
List Price:  ₹8,349.95
You save:  ₹2,505.23
RM331.80
List Price:  RM474.03
You save:  RM142.22
₦98,423.43
List Price:  ₦140,610.93
You save:  ₦42,187.50
₨19,474.95
List Price:  ₨27,822.55
You save:  ₨8,347.60
฿2,584.73
List Price:  ฿3,692.63
You save:  ฿1,107.90
₺2,255.06
List Price:  ₺3,221.65
You save:  ₺966.59
B$356.31
List Price:  B$509.04
You save:  B$152.73
R1,298.99
List Price:  R1,855.78
You save:  R556.79
Лв127.57
List Price:  Лв182.26
You save:  Лв54.68
₩95,950.21
List Price:  ₩137,077.60
You save:  ₩41,127.39
₪261.40
List Price:  ₪373.45
You save:  ₪112.04
₱4,015.50
List Price:  ₱5,736.67
You save:  ₱1,721.17
¥10,912.42
List Price:  ¥15,589.84
You save:  ¥4,677.42
MX$1,187.01
List Price:  MX$1,695.81
You save:  MX$508.79
QR254.79
List Price:  QR364.01
You save:  QR109.21
P956.45
List Price:  P1,366.42
You save:  P409.96
KSh9,168.69
List Price:  KSh13,098.69
You save:  KSh3,930
E£3,313.80
List Price:  E£4,734.21
You save:  E£1,420.40
ብር4,020.93
List Price:  ብር5,744.43
You save:  ብር1,723.50
Kz58,536.36
List Price:  Kz83,626.96
You save:  Kz25,090.59
CLP$65,519.73
List Price:  CLP$93,603.63
You save:  CLP$28,083.90
CN¥505.79
List Price:  CN¥722.59
You save:  CN¥216.80
RD$4,064.05
List Price:  RD$5,806.04
You save:  RD$1,741.98
DA9,434.16
List Price:  DA13,477.95
You save:  DA4,043.79
FJ$159.43
List Price:  FJ$227.77
You save:  FJ$68.34
Q544.12
List Price:  Q777.35
You save:  Q233.22
GY$14,659.33
List Price:  GY$20,942.80
You save:  GY$6,283.47
ISK kr9,804.19
List Price:  ISK kr14,006.59
You save:  ISK kr4,202.40
DH702
List Price:  DH1,002.91
You save:  DH300.90
L1,236.68
List Price:  L1,766.77
You save:  L530.08
ден4,019.08
List Price:  ден5,741.79
You save:  ден1,722.70
MOP$563.89
List Price:  MOP$805.60
You save:  MOP$241.70
N$1,302.92
List Price:  N$1,861.40
You save:  N$558.47
C$2,577.98
List Price:  C$3,682.99
You save:  C$1,105
रु9,357.62
List Price:  रु13,368.60
You save:  रु4,010.98
S/260.83
List Price:  S/372.63
You save:  S/111.80
K271.34
List Price:  K387.65
You save:  K116.30
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,913.50
List Price:  ZK2,733.69
You save:  ZK820.18
L324.50
List Price:  L463.60
You save:  L139.09
Kč1,630.34
List Price:  Kč2,329.15
You save:  Kč698.81
Ft25,331.89
List Price:  Ft36,189.97
You save:  Ft10,858.07
SEK kr764.93
List Price:  SEK kr1,092.80
You save:  SEK kr327.87
ARS$61,714.55
List Price:  ARS$88,167.42
You save:  ARS$26,452.87
Bs483.86
List Price:  Bs691.26
You save:  Bs207.40
COP$272,553.83
List Price:  COP$389,379.31
You save:  COP$116,825.47
₡35,845.57
List Price:  ₡51,210.15
You save:  ₡15,364.58
L1,730.57
List Price:  L2,472.36
You save:  L741.78
₲523,213.21
List Price:  ₲747,479.48
You save:  ₲224,266.27
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł280.23
List Price:  zł400.34
You save:  zł120.11
Already have an account? Log In

Transcript

Welcome to the Python session. So today we'll be starting with Python tupple. So tupple is used to store the sequence of immutable Python objects tupple is similar to the list, since the value of the item stored in the list can be changed, whereas the topple is immutable. and the value of the item stored in the topple cannot be changed. So a topple is a data structure that is an immutable or unchangeable ordered sequence of element. Because topples are immutable.

The values cannot be modified. doubles are used for grouping data. Each element or value that is inside of a topple is called an item topples are similar to list, but the values can't be modified because of this, when you stop In your code, you are conveying to others that you don't intend for there to be change to the sequence of values. Additionally, because the values do not change, your code can be optimized through the use of tupple. In Python, as a code will be slightly faster for double than for list. So a topple can be written as a collection of comma separated value enclosed with us small brackets or the first bracket.

So let's just first create a tupple you can give any name to the capital. So today we starting with double sided rectangle here, and then I'll show you how to create a double. So click T is a name of a topple. So first bracket, this is the how we create double for lists, we use square brackets for tupple. We'll use the first bracket so double, then I'll write the items so I write a few millings dog, cat, goat, cow monkey. So, let us create this tupple with five intimate so run it and now print d c it has created a tupple and a topple will be always shown in the first bracket and with this the values will be encoded within quotes so in this way the topics will be created.

So here we have created a string or a character tupple. Now, are we creating a tupple or mixed up you can say where I will store both the character value and the numeric value. So I'll write a name here. Suppose T one and heroes two Few values. Suppose Iran rate doctor can give a comma. And beside that and right leaning in give a comma, right nurse, give a comma, and here, right 20.

Now run this and print this T one. So print t underscore one, see it printed perfectly because it has no error. So in this way you can create doubles by using just character string by using both character and numerous string. And also you can create only numeric string. So let me create one numeric double. So here I'm right one comma two, comma four, comma, five comma eight.

As many as number you want to give you can so run and then print t score two So, it has printed my numeric. Now indexing of a topple. So, just like list it the same index of a tupple means the position of the element position of each item of a topic. So it will start from zero and then it will go on as 12345 like this. So the first element of the tupple is considered as index zero, then index one, then index two and then index three. In this way it will go on now, let me just call up index so in right here print within bracket give the tupple name, so my name is T and working on the first step, then within this square bracket, provide an index number.

So, I provide zero here let's see what it prints. So what it prints it prints dog. So, here in the terminal t zero is the first element. So, it has an index number zero. So, the dog has the dog is the first element. So, it has an index number zero.

So, whenever I give the index number zero here, it printed dog. Now the same way, if you write print T and given index number three, what it will print, so it will print cow because here look at here. So 012323 is the index number of cow. So it has printed cow here. Now, if you right train print T and just write minus two, then what happened? c printed mine cow because look at this list of elements or topples, you can stop starting from the end, this is minus one, this is minus two.

So, just like list it It can have a negative index also. So, if you start counting from the end, then it will start from minus one. So minus one, minus two, minus three minus four and minus five. Now if you write print T and minus four, what it will print? It will print cat because minus one minus two minus three minus four. So minus four is in its number of cats starting from the end.

So you can print it is printing cat. Now, you can also give a range of index. So if I write two is two, four, then what are the numbers that it will print? Let me foresee this so 01234 so it will print 012 that is starting from here goat and cow monkey it will not be Print because in the last number is n minus one that is within print n minus one, so four, four minus one is three, it will print up to three, index number three. So just run it, see it printed on the golden cow, it is same as list, the only difference between these and a topple is you can modify a list, but in tupple, you cannot modify. Now if you just write print T, and within this square bracket, right minus five is two minus three so run see credit dog and cat because suffering from here, minus one minus two minus three minus four minus five, so minus five and minus four it will print it will not print a string because the next number just it will print the before number not the exact index it will print for the last time rings that will provide.

So, in this way you can index tupple next thing that we can do is slicing. So slicing apart Apple, let's look at that. So slicing that, that is basically a range of values that we provide that we have already done in indexing the previous example that we have done is basically slicing that is we are providing a range and we're calling a part of a topic that is called slicing. Now, one more thing that you can do in slicing is just provide the end end range don't provide the beginning. So what it will print, it will print everything before 0123 Okay. Now, if you provide only the beginning, so just provide one and provide nothing at the end.

So, what it will print, it will start printing from the second number second value, and then it will print everything after that. So this is what slicing is. So if you provide a range from this, like this, this also slicing If you give like negative index This is also surprising. And if you provide like this, this is also slicing, slicing is basically selecting a range of elements in a tupple This is called slicing. Now one more thing that I will show you is like print give the topic name. So here I write Apple to element using t to topple.

Now here right three numbers starting from one index number give up to say how many elements I've created a vn. Let's just first look at 1-234-512-3456 six elements are there. So I'm right here five and then again you semicolon a semicolon and then give two so what this is referring to what this numbers are referring to, this is the range one is to five and then what to what two is defining I've already taught you this in list. This tool is defining that is it will just omit The contiguity value and it will just print the alternate values see what it printed it printed two and five, because starting from here it will print this then it will omit this then it will print this then again it will omit everything okay. So, this is how it will print now, if it is zero over here what it will print?

So, it has printed 148 because it printed first number then omitted the second one they need to print this one then again omitted the second one and then again printed this one okay it will not print this one because the last number is always n minus one I told you. So, it has printed these three numbers, no concatenation of a topic. So I will now do concatenation. Okay, now, let me first create one more tougher then I will do concatenation. So here it is. Right, Tiger, both lion zebra.

Okay, take me do with this for eight minutes. So I run this now, I want to join this to tackle one is t three and the one that I've created in the beginning that is t this one. So I want to join this too. So what can I do? I need to create a new topic. So I'll create t 454 is a new topic now and right here de classe d3.

Run it and then print default. See it has concatenated that to topples So the first values are the from the first step and the next four values are from the last couple that we have just now created. So in this way you can concatenate two topples. Now, in this RT three topics that we have created, let me use an operator here. So I'll write print tear three, and then I'll use a star operator and write to what it will do. It will repeat the whole topple once again.

So, this is the first step and it has now repeated over here. Now if you just write, print, t three into three, that is start three, what it will do, it will repeat this value three times. So in this way, you can repeat the tupple as many as number of times you want so we have used two operators one is plus and his star plus is for concatenation and star is for repeating those samples, the number of times you've specified, so I'll be ending my video over here. Keep practicing. See you in the next video. Thank you

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.