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

From Wiki
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
= Operações com Arrays =
= Operações com Arrays =


== Básico ==
  #!/usr/bin/python
  #!/usr/bin/python
  from array import *  
  from array import *  
Line 12: Line 13:
  print vals[0]
  print vals[0]
  # 5
  # 5
 
  vals.reverse()
  vals.reverse()
  print vals
  print vals
Line 18: Line 19:
   
   
  for v in vals:
  for v in vals:
   print(v,end='')
   print(v,end=<nowiki>''</nowiki>)
  # 7965
  # 7965
   
   

Latest revision as of 02:41, 28 September 2018

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