0% found this document useful (0 votes)
2 views6 pages

Python Basics: Lists vs Arrays Explained

Lists and arrays in Python can both store indexed data of any type, but arrays allow arithmetic operations while lists will throw errors. Arrays must be declared while lists do not. Arrays are preferable over lists when storing large amounts of data or performing arithmetic on the data due to their more compact and efficient storage of information.

Uploaded by

Swapnil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python Basics: Lists vs Arrays Explained

Lists and arrays in Python can both store indexed data of any type, but arrays allow arithmetic operations while lists will throw errors. Arrays must be declared while lists do not. Arrays are preferable over lists when storing large amounts of data or performing arithmetic on the data due to their more compact and efficient storage of information.

Uploaded by

Swapnil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

e

[Link]
7611950613&mid=6B25AB44D38B94AC3F0F6B25AB44D38B94AC3F0F&view=detail&FORM=VIREHT

>>>[Link] = gets shape i.e number of rows and columns

>>> [Link](9).reshape(3,3)

Array([[0,1,2],

[3,4,5],

6,7,8]])

Talked to tarun. He said check emi

Jonny bairstow, chris gayle, david warner, ab de villiers, andre russel, keiron pollard, hardik pandya

Intro day 1Last Checkpoint: 8 minutes ago(autosaved) Logout

Python 3
Trusted

 File
 Edit
 View
 Insert
 Cell
 Kernel
 Widgets
 Help

Run

In [1]:
s = "this is good"
t = True
a=7
b=6
f = 9.7
print("hello sum", a+b)

hello sum 13
In [3]:

s = "this is good"
t = True
a=7
b=6
f = 9.7
print("hello sum", a+b)
d=4

hello sum 13
In [ ]:

In [4]:

s = "this is good"
t = True
a=7
b=6
f = 9.7
#print("hello sum", a+b)

In [5]:

if a > 10:
print("ok")
else:
print("not ok")
not ok
In [6]:

a = int(input("enter the number"))


if a == 1:
print("ok")
elif a==2:
print("ok2")
elif a==3:
print("ok3")
else:
print("not ok")
enter the number2
ok2
In [8]:

for i in range(1,4):
for j in range(1,4):
print(i)
1
1
1
2
2
2
3
3
3
In [11]:

for i in range(1,4):
for j in range(1,4):
print(i, end = "i=2")
1i=21i=21i=22i=22i=22i=23i=23i=23i=2
In [12]:

for i in range(1,4):
for j in range(1,4):
print(i, end = "")
111222333
In [13]:

for i in range(1,4):
for j in range(1,4):
print(i, end = "")
print("\n")
111

222
333

In [14]:

for i in range(1,4):
print("\n")
for j in range(1,4):
print(i, end = "")

111

222

333
In [15]:

s = lambda x: x*x
print(s(5))
25
In [16]:

s = lambda x,y: x+y


print(s(2,3))
5
In [ ]:
What is array?

Lists and arrays are used in Python to store data(any data type- strings,
integers etc), both can be indexed and iterated also. Difference between lists
and arrays are the functions that you can perform on them like for example
when you want to divide an array by 4, the result will be printed on request but
in case of a list, python will throw an error message. Here's how it works:

Arrays need to be declared whereas lists do not need declaration because they are a part of Python's syntax.
This is the reason lists are more often used than arrays. But in case you want to perform some arithmetic
function to your list, one should go with arrays instead.
If you want to store a large amount of data, then you should consider arrays because they can store data very
compactly and efficiently.

You might also like