-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_5String_List_Tuple.py
More file actions
86 lines (57 loc) · 2.05 KB
/
Python_5String_List_Tuple.py
File metadata and controls
86 lines (57 loc) · 2.05 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
"""
String List Tuple
String is Group of Characters or a simple word
string is identified by str
string is written in Double quote " "
it can also be written in single quote ' '
"""
name = "Om Bacchuwar"
print(type(name))
age = 20
print(type(age))
"""
🟢Operations performed on String
1- Concatenation
"""
a = "a" + "b"
print("This is the example of concatenation where while declaring the variable the string is seperated by +. so it will be ",a)
"""
2- Finding Length
"""
name = "Om"
print(name, " has the length of ", len(name)," by len function we can find the length of the given string.")
"""
🟢List : Collection of items
here we can save all the items or we can say the values , in short we can save multiple values of different types
"""
om_list = ["om " , 6122002, 6.122002 ]
print("Items present in my list namely om_list are : ",om_list)
"""
🟢Operations performed on list
1- Append : Adding an element in the list
"""
om_list.append("Python pdhle bhadwe")
print(om_list, " Here as you can see python pdhle bhadwe element has been added.")
"""
2- Remove : Removing an element from the list
"""
om_list.remove("om ")
print(om_list," Here as you can see om has been removed successfully using remove operation in the list.")
"""
🟢Tuple : Tuple is similar as list like we can add multiple elements , but here the catch is that we cannot
change anything basically we cannot perform any kind of operations in the TUPLE.
🚫🚫🚫We can never change the data within the TUPLE.⭐⭐⭐
we can only index
"""
om_tuple = ("Om",6,12,2002)
one = om_tuple[0]
two = om_tuple[1]
three = om_tuple[2]
four = om_tuple[3]
print("Have a look at the tuple ")
print(om_tuple)
print("First element of the tuple is ",one," or we can directly write the index value om_tuple[0] for the first element of the tuple that will be ",om_tuple[0])
print("Second element of the tuple is ",two)
print("Three element of the tuple is ",three)
print("Fourth element of the tuple is ",four)
print("We have printed values from the tuple using the index of the tuple.")