Subscribe this Blog

Wikipedia

Search results

Notifications and New Posts!

Monday, August 31, 2020

Google Meet Session - 31st August 2020 ADVANCED PROGRAMMING CONCEPTS - Python (TY A and B)

ADVANCED PROGRAMMING CONCEPTS - Python
Monday, 31 August11:00 – 12:00
Join with Google Meet
https://meet.google.com/uht-egpu-qtx
Description: Prof. B.S. Savase sir is not available today, Therefore, we learn python today. Subject : ADVANCED PROGRAMMING CONCEPTS - PythonTo solve assignments Please join Google Classroom.Invitation of Google Classroom has been sent to your official email id.Please accept the google classroom invitation through official email id. Or directly by entering Class code of Google Classroom also you can join Google Class room to solve assignments.Class code of Google Classroom : 3ojdsjm
With kind regards,
SD Bhosale

Organiser: Sachin Bhosale

To know your attendance : Click here


Today's Learnings:
Python literal - List
# List is a collection which is ordered and changeable.# Allows duplicate members.
# Tuple is a collection which is ordered and unchangeable.# Allows duplicate members.
# Set is a collection which is unordered and unindexed.# No duplicate members.
# Dictionary is a collection which is unordered, changeable and indexed.
# No duplicate members.
# List# A list is a collection which is ordered and changeable.
# In Python lists are written with square brackets.
# Example
# Create a List:
thislist = ["apple", "banana", "cherry"]
a=[11,5,7,9]
b=[1.5,7.5,4.4]
print("Displaying list thislist:",thislist)
print("Displaying list a:",a)
print("Displaying list b:",b)
print("Datatype of list thislist",type(thislist))
print("Datatype of list a:", type(a))
print("Datatype of list b:",type(b))
Output:
Displaying list thislist: ['apple', 'banana', 'cherry']
Displaying list a: [11, 5, 7, 9]
Displaying list b: [1.5, 7.5, 4.4]
Datatype of list thislist <class 'list'>
Datatype of list a: <class 'list'>
Datatype of list b: <class 'list'>

# Access Items# You access the list items by referring to the index number:
# Example
# Print the second item of the list:
thislist = ["apple", "banana", "cherry",1,2.4]
print("First item or data from thislist",thislist[0])
print("Second item or data from thislist",thislist[1])
print("Third item or data from thislist",thislist[2])
print("Fourth item or data from thislist",thislist[3])
print("Fifth item or data from thislist",thislist[4])

print("Datatype of First item or data from thislist",type(thislist[0]))
print("Datatype of Second item or data from thislist",type(thislist[1]))
print("Datatype of Third item or data from thislist",type(thislist[2]))
print("Datatype of Fourth item or data from thislist",type(thislist[3]))
print("Datatype of Fifth item or data from thislist",type(thislist[4]))
Output:
First item or data from thislist apple
Second item or data from thislist banana
Third item or data from thislist cherry
Fourth item or data from thislist 1
Fifth item or data from thislist 2.4
Datatype of First item or data from thislist <class 'str'>
Datatype of Second item or data from thislist <class 'str'>
Datatype of Third item or data from thislist <class 'str'>
Datatype of Fourth item or data from thislist <class 'int'>
Datatype of Fifth item or data from thislist <class 'float'>

# Negative Indexing# Negative indexing means beginning from the end, 
# -1 refers to the last item,
# -2 refers to the second last item etc.
# Example# Print the last item of the list:

thislist = ["apple", "banana", "cherry"]
print("First value from the thislist: ",thislist[-3])
print("Middle value from the thislist: ",thislist[-2])
print("Last value from the thislist: ",thislist[-1])
Output:
First value from the thislist:  apple
Middle value from the thislist:  banana
Last value from the thislist:  cherry

# Range of Indexes OR Slicing
# You can specify a range of indexes by specifying 
# where to start and where to end the range.
# When specifying a range, the return value will be 
# a new list with the specified items.# Example
# Return the third, fourth, and fifth item:
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[0:3])
a=thislist[0:100]

print("This is new list after slicing: ",a)

# Note: The search will start at index 2 (included) # and end at index 5 (not included).
# Remember that the first item has index 0.
Output:
['apple', 'banana', 'cherry']
This is new list after slicing:  ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'melon', 'mango']

# By leaving out the start value, the range will start at the first item:
# Example
# This example returns the items from the beginning to "orange":
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[:4])
Output:
['apple', 'banana', 'cherry', 'orange']

# By leaving out the end value, 
# the range will go on to the end of the list:
# Example
# This example returns the items 
# from "cherry" and to the end:
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[2:])
Output:
['cherry', 'orange', 'kiwi', 'melon', 'mango']

# Range of Negative Indexes
# Specify negative indexes if you want# to start the search from the end of the list:
# Example# This example returns the items
# from index -4 (included) to index -1 (excluded)
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[-4:])
Output:
['orange', 'kiwi', 'melon', 'mango']

Google Meet Session Video:



No comments:

Post a Comment