Python: Operações com Arrays

From Wiki
Revision as of 02:41, 28 September 2018 by Ebasso (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Arrays em python só podem ser de apenas um tipo

Operações com Arrays

Básico

#!/usr/bin/python
from array import * 

vals = array('i',[5,9,6,7])
print vals
# array('i', [5, 6, 9, 7])

print vals[0]
# 5

vals.reverse()
print vals
# array('i', [7, 9, 6, 5])

for v in vals:
  print(v,end='')
# 7965

newArray = array(vals.typecode, (v*2 for v in vals))
print(newArray)
# array('i', [14, 18, 12, 10])

Ver também