count,index,copy in a list
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> ##list methods
>>> ##count
>>> list=[1,234,345,10,10,10,20,020,20,50,50,050]
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> list=[10,10,10,20,20,20,234,40,24,40,40,40,5050,5050,5050]
>>> list.count(10)
3
>>> count(40)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
count(40)
NameError: name 'count' is not defined
>>> list.count(40)
4
>>> ##index
>>>
>>>
>>> list.index(4)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
list.index(4)
ValueError: 4 is not in list
>>> list.index(40)
7
>>> list=[1,4,9,16,25,36,49,64,81,100]
>>> list.copy(even)
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
list.copy(even)
NameError: name 'even' is not defined
>>> list1=list.copy()
>>>
>>> list1
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
>>> even=[4,8,16]
>>> list1.copy(even):
SyntaxError: invalid syntax
>>> even.copy()
[4, 8, 16]
>>> ##copy is like copying all like photocopy** remember
Comments
Post a Comment