-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram_06_Tuples.py
More file actions
92 lines (65 loc) · 1.6 KB
/
Program_06_Tuples.py
File metadata and controls
92 lines (65 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 30 05:07:59 2022
@author: shanu
"""
#Tuple is a list of values grouped together
#A tuple is a collection which is ordered and unchangeable.
# In Python tuples are written with round brackets.
#Tuples are for one object with different values
#like geometry points
point= (13, 20,6)
#to access the element in tuple
point[0]
point[1]
#Range of index
point[0:2]
point[1:3]
point[1:4]
#using Negative index
point[-1]
point[-1:-3] #wrong
point[-3:-1]
#Once a tuple is created, you cannot change its values.
# Tuples are unchangeable, or immutable.
#Note: You cannot remove items in a tuple
point[0]= 5 #will throw an error
#But there is a workaround. You can convert the tuple into a list, change the list,
# and convert the list back into a tupl3
list_point= list(point)
print(list_point)
list_point[0]=12
print(list_point)
list_point= tuple(list_point)
print(list_point)
#Addition
point+(9,8,7)
#Repetition
point * 3
#To determine if a specified item is present in a tuple
12 in point
#Determine Tuple length
len(point)
#Join two tuples
mod_points=point+list_point
#get the occurance of each value
mod_points.count(12)
mod_points.count(20)
#get the index for particular value
mod_points.index(12)
mod_points.index(6)
#Tuple Traversal
for num in point:
print(num)
#delete the value from tuple
#Note: You cannot remove items in a tuple
del point
'''
Write a program to compute the area
and circumference of a circle using a
function.
'''
def calculate_circle(radius):
area= 3.14*radius*radius
circumference= 2*3.14*radius
return (area, circumference)