Lists in python (Codecademy - Python 3)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

sorted(original_list)

creates a new list from the sorted items in the original_list

Nested list

a list which also has another list as an element in it

Output of :- language = ['p','y','t','h','o','n'] print(my_list[4.0])

Error (only integer value can be used for indexing)

Can a list be added to another list using the append() , insert() , extend() method ? (Yes/No)

Yes

output of :- list = [1 , 2 , 2] list.remove(2) print(list)

[ 1 , 2 ]

output of :- list = [1 , 2 , 3 , 4] list.append(9) print(list)

[1 , 2 , 3 ,4,9]

output of :- n_list = ["Happy",[2,0,1,5]] print(n_list[0][1])

a

Way to create list in python

a list is created by placing all the elements inside a square bracket [ ] , separated by commas.

by this method one element or list at a time can be added at the end of the list

append()

Output of :- language = ['p','y','t','h','o','n'] print(my_list[3])

h

Which in - built function is used to determine the length of the list in python

len()

A _______ ________ is the position at which any element is present in the list. Index in the list starts from 0, so if a list has 5 elements the index will start from 0 and go on till 4. In order to access an element in a list we need to use index operator [].

list index

List

list is a sequence of value of any data type (integer, float, string, Boolean etc.)

tupple

list that can't be changed

In this type of indexing the last element/ item is referred to as -1 and the first item is referred to as -n ( n is the total number of elements)

negative indexing

len(listname)

returns the length of the list

this operation is used to print a specific range of elements from the list

slicing

list.sort()

sorts elements in list


Ensembles d'études connexes

Musculoskeletal (Ch. 35-37) med-surg II

View Set

Module 14 - Infancy and Childhood - Retrieval Practice & Review

View Set

Marketing Quiz (Ch. 12, 13, 14, 15)

View Set

Exam 3 Immune/Respiratory questions

View Set

Chapter 21 World History, Sec 2,3,4

View Set

CCNA Introduction to Networks Chapter 10

View Set

Google Certified Educator Level 2

View Set