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

From Wiki
Line 18: Line 18:
   
   
  for v in vals:
  for v in vals:
   print(v,end='')
   print(v,end=<nowiki>''</nowiki>)
  # 7965
  # 7965
   
   

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