#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jun 14 14:49:29 2023 @author: richardson """ # manipulation with arrays c=[3,"hilfr",3.7] # c is a list print(c) for b in c: # note flexibility of for statement print("The type of "+str(b)+" is "+str(type(b))) print(c[1]) # c[0] is the first element of the list, # c(1) is the second element, etc. # making a list cl = [] # an empty list for j in range(2,40): cl += [j**2] # ** means ^ in python # The ^ is a bitwise operation # A += B means A = A+B # [1,2,3]+[11,2]=[1,2,3,11,2] # so + for lists is concatenation print(cl) # shortcut to the above: list comprehension cl2 = [j**2 for j in range(2,40)] print(cl2) cl3 = [j**2 for j in range(2,40) if j%7!=0] # list of squares starting with 2^2 and ending with 39^2 but # not including multiples of 7 print(cl3) # we can make matrices as lists of lists A = [[2,3],[-1,7]] print(A) print(A[1][0]) # this is the second row, 1st column of the matrix A+=[[11,17]] print(A) print(A[2][0])