-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforloop.py
More file actions
170 lines (155 loc) · 2.82 KB
/
forloop.py
File metadata and controls
170 lines (155 loc) · 2.82 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.
veg
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
veg
NameError: name 'veg' is not defined
veg=['brinjal','okra','bottle guard','kothmir']
veg
['brinjal', 'okra', 'bottle guard', 'kothmir']
for each_item in veg:
print(each_item)
print(veg)
brinjal
['brinjal', 'okra', 'bottle guard', 'kothmir']
okra
['brinjal', 'okra', 'bottle guard', 'kothmir']
bottle guard
['brinjal', 'okra', 'bottle guard', 'kothmir']
kothmir
['brinjal', 'okra', 'bottle guard', 'kothmir']
for each_item in veg:
print(each_item)
brinjal
okra
bottle guard
kothmir
fam_names=['jaffer','asma','ayman','zoya']
fam_names
['jaffer', 'asma', 'ayman', 'zoya']
fam_names[2]
'ayman'
#change into uppercase
fam_names.upper()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
fam_names.upper()
AttributeError: 'list' object has no attribute 'upper'
fam_names[0].upper()
'JAFFER'
for each_item in fam_names:
print(fam_names.upper())
Traceback (most recent call last):
File "<pyshell#17>", line 2, in <module>
print(fam_names.upper())
AttributeError: 'list' object has no attribute 'upper'
for each_item in fam_names:
print(fam_names[].upper())
SyntaxError: invalid syntax. Perhaps you forgot a comma?
for each_item in fam_names:
print(each_item.upper())
JAFFER
ASMA
AYMAN
ZOYA
for each in fam_names:
x=each.upper()
print(x)
JAFFER
ASMA
AYMAN
ZOYA
>>> for each in fam_names:
... print(each.islower())
...
...
True
True
True
True
>>> for each in fam_names:
... x=each.upper()
... print(x.islower())
...
...
False
False
False
False
>>> for each in fam_names:
... x=each.upper()
... print(x)
... print(x.islower())
...
JAFFER
False
ASMA
False
AYMAN
False
ZOYA
False
>>> for each in fam_names
SyntaxError: expected ':'
>>> for each in fam_names:
... len(each)
...
6
4
5
4
for each in fam_names:
print(each.upper() ,each.lower() ,each.capitalize())
JAFFER jaffer Jaffer
ASMA asma Asma
AYMAN ayman Ayman
ZOYA zoya Zoya
number=[12,14,24,56,76,78]
number
[12, 14, 24, 56, 76, 78]
for each in number:
number[0]+100
print(each)
112
12
112
14
112
24
112
56
112
76
112
78
for each in number:
number+100
print(each)
Traceback (most recent call last):
File "<pyshell#50>", line 2, in <module>
number+100
TypeError: can only concatenate list (not "int") to list
for each in number:
each+100
print(each)
112
12
114
14
124
24
156
56
176
76
178
78
for each in number:
print(each+100)
112
114
124
156
176
178