Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Study guide

Python Beginner Course Note-3

Rating
-
Sold
-
Pages
32
Uploaded on
15-09-2020
Written in
2019/2020

This is the continuation of my crash course on Python. This material contains compact, briefed concepts about lists and tuples in Python. These are the most basic and interesting topics of Python. Failing to know them with the variety of examples (as given here) will cause you difficulty in grasping deeper concepts.

Show more Read less
Institution
Course

Content preview

Day-3: List
and Tuple
23/06/2018
Workshop on “Introduction to
Python”




Department Of
Computer Science
Engineering

SKFGI, Mankundu

,1.Python Data Structure
A data Structure is a group of data element that are put together under one
name. Data Structure defines a particular way of sorting and organizing data
in a computer so that it can be used efficiently.

There are 3 different data structure in the Python programming language:
1.1. Sequence: It is most basic data structure in python. In the sequence
data structure each element has a specific index .this index value is start
from 0and its automatically incremented for the next element in the
sequence. There are several types of sequences in Python, the following
three are the most important.
1.1.1Lists are the most versatile sequence type. The elements of a list can
be any object, and lists are mutable - they can be changed. Elements can
be reassigned or removed, and new elements can be inserted. Allows
duplicate members.
1.1.2Tuples are like lists, but they are immutable - they can't be changed.
Allows duplicate members.
1.1.3 Strings are a special type of sequence that can only store characters,
and they have a special notation. String is also immutable
1.2. Set is a collection which is unordered and unindexed. No duplicate
members.
1.3. Dictionary is a collection which is unordered, changeable and indexed.
No duplicate members.


2. Python List

Lists are one of the most powerful data strucure in Python. They are just like
the arrays declared in other languages. But the most powerful thing is that

,list need not be always homogeneous. A single list can contain strings,
integers, as well as objects. Lists can also be used for implementing stacks
and queues. Lists are mutable, i.e., they can be altered once declared.


2.1How to create a list?
In Python programming, a list is created by placing all the items (elements)
inside a square bracket [ ], separated by commas.
It can have any number of items and they may be of different types
(integer, float, string etc.).
Example of list declarations:
Code Output
1. Empty list my_list = [] []
print(my_list)
2. List of integers my_list = [100, 200, 300] [100, 200, 300]
print(my_list)
3. List with mixed my_list = [1, "Mother", [1, 'Mother', 3.414]
data types 3.414]
print(my_list)
4. Nested list my_list = ["Morning", [8, 4, ['Morning', [8, 4, 6],
6], ['a']] ['a']]
print(my_list)
2.2List Index is used to access elements from a list
We can use the index operator [] to access an item in a list. Index starts
from 0. So, a list having 5 elements will have index from 0 to 4.
Example:
Code Output

aList = [123, 'xyz', 'zara', 'abc']; Index for xyz : 1

print( "Index for xyz : ", aList.index( 'xyz' ) ) Index for zara : 2

, print( "Index for zara : ", aList.index( 'zara' ))

2.3Negative indexing
Negative index is used in python to index starting from the last element of
the list, tuple or any other container class which supports indexing. -1 refers
to the last index, -2 refers to the second last index and so on.




Code Output

For lists: 5

array = [0,1,2,3,4,5]
print(array[-1])
array = [0,1,2,3,4,5] 2
print(array[-4])



2.4Slice lists in Python
Similar to string, list can also be sliced. We can access a range of items in a
list by using the slicing operator (colon) and square brackets[] are used to
slice along with the index. Syntax :
Seq=List[start:end:step]
Code Output

Connected book

Written for

Institution
Course

Document information

Uploaded on
September 15, 2020
Number of pages
32
Written in
2019/2020
Type
Study guide

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
snehat1410

Get to know the seller

Seller avatar
snehat1410 MAKAUT
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
5 year
Number of followers
1
Documents
14
Last sold
5 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions