Python List Operations, Summaries of Computer science

A series of python code snippets that demonstrate various operations on a list called 'a_list'. The operations include accessing elements by index, slicing the list, iterating through the list, reversing the list, and creating a new list by multiplying each element of the original list by 3. Additionally, there is a code snippet that checks if each element in the list is even or odd. This document could be useful for students learning python programming, particularly those studying data structures and list manipulation. It could serve as study notes, lecture notes, or a summary for a python programming course, providing a concise overview of common list operations in python.

Typology: Summaries

2011/2012

Uploaded on 12/04/2022

box-lem
box-lem 🇺🇸

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
a_list = [3, 5, 6, 12]
1) a_list[0]
2) a_list[3]
3) a_list[1:4]
4) for i in a_list:
print(i)
5) a_list.reverse()
print(a_list)
6) a_list=[3,5,6,12]
lst=[]
a_list=[3,5,6,12]
for i in a_list:
a=i*3
lst.append(a)
print(lst)
7) a_list=[3,5,6,12]
for i in range(len(a_list)):
if a_list[x] % 2 == 0:
a_list= True
else:
a_list =False
print(a_list)

Partial preview of the text

Download Python List Operations and more Summaries Computer science in PDF only on Docsity!

a_list = [3, 5, 6, 12]

  1. a_list[0]
  2. a_list[3]
  3. a_list[1:4]
  4. for i in a_list: print(i)
  5. a_list.reverse() print(a_list)
  6. a_list=[3,5,6,12] lst=[] a_list=[3,5,6,12] for i in a_list: a=i* lst.append(a) print(lst)
  7. a_list=[3,5,6,12] for i in range(len(a_list)): if a_list[x] % 2 == 0: a_list= True else: a_list =False print(a_list)