list_int=range(10)
for i in range(10):
list_int[i]=i+1
print "list_int["+str(i)+"] is initialized with "+str(list_int[i])+"\n"
import sys
list_int=range(10)
total_byte= sys.getsizeof(int)*10
print "The size of int is "+str(sys.getsizeof(int))+" byte long"
print "The array of 10 ints has total "+str(total_byte)+" bytes"
print "The address of the first element: "+str(id(list_int[0]))
print "The address of the last element: "+str(id(list_int[9]))
list_int=range(10)
for i in range(10):
list_int[i]=i+1
ptr_int=list_int
print "The start address of the array: "+str(id(ptr_int[0]))
print "The value of the first element: "+str(ptr_int[0])
ptr_int=id(list_int[0])
print "The address of the first element: "+str(ptr_int)
print "The value of the first element: "+str(list_int[0])
array_ch=['H','e','l','l','o','!','\0']
for i in range(7):
print "array_ch["+str(i)+"] contains: "+str(array_ch[i])
'''Method I'''
print "Put all elements together(Method I):"
for ch in array_ch:
print ch,
''' Method II'''
print "\nPut all elements together(Method II):"
print "".join(array_ch)
array_ch=['C',' ','i','s',' ','p','o','w','e','r','f','u','l','!','\0']
i=0
while(array_ch[i]!='\0'):
print ""+array_ch[i],
i=i+1
print "\n"
two_dim=[[1,2,3,4,5],[10,20,30,40,50],[100,200,300,400,500]]
for i in range(3):
print "\n"
for j in range(5):
print "%6u" % two_dim[i][j],
print "\n"
import sys
array_ch=['C',' ','i','s',' ','p','o','w','e','r','f','u','l','!','\0']
list_int=[[1,1,1],[2,2,8],[3,9,27],[4,16,64],[5,25,125],[6,36,216],[7,49,343]]
print "The size of array_ch[] is %d bytes.\n" %sys.getsizeof(array_ch)
print "The size of list_int[][] is %d bytes.\n" %sys.getsizeof(list_int)