Python: Operações com Arrays: Difference between revisions

From Wiki
Line 12: Line 12:
  print vals[0]
  print vals[0]
  # 5
  # 5
 
  vals.reverse()
  vals.reverse()
  print vals
  print vals

Revision as of 01:44, 28 September 2018

Arrays em python só podem ser de apenas um tipo

Operações com Arrays

#!/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