Subscribe this Blog

Wikipedia

Search results

Notifications and New Posts!

Thursday, September 17, 2020

Google Meet Session - 17th September 2020 ADVANCED PROGRAMMING CONCEPTS - Python (TY A and B)

 ADVANCED PROGRAMMING CONCEPTS - Python

Thursday, 17 September13:30 – 15:30
Weekly on Thursday, until 30 Nov 2020
Join with Google Meet
meet.google.com/hid-dmnv-qxw
Join by phone
Description:Subject : ADVANCED PROGRAMMING CONCEPTS - Python To 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


To know Attendance: Click here
Reference : https://www.w3schools.com/python/

Today's Learning:

Revision of Python List -Literal 
 
Program No. 1:
# Tuple
# A tuple is a collection which is ordered and unchangeable.
# In Python tuples are written with round brackets.
# Example
# Create a Tuple:

thistuple = ("apple", "banana", "cherry")
print(thistuple)
print(type(thistuple))
Output:
('apple', 'banana', 'cherry')
<class 'tuple'>

Program No. 2:
# Access Tuple Items
# You can access tuple items by referring to the index number,
# inside square brackets:
# Example
# Print the second item in the tuple:

thistuple = ("apple", "banana", "cherry","chiku")
print(thistuple[0:2])
Output:
('apple', 'banana')


Program No. 3:
# 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 tuple:

thistuple = ("chiku","apple", "banana", "cherry")
print(thistuple[-4])
Output:
chiku


Program No. 4:
# 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 tuple with the specified items.
# Example
# Return the third, fourth, and fifth item:
# Note: The search will start at index
# 2 (included) and end at index 5 (not included).
# Remember that the first item has index 0.

thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[0:3])
Output:
('apple', 'banana', 'cherry')


Program No. 5:
# Range of Negative Indexes
# Specify negative indexes if
# you want to start the search from the end of the tuple:
# Example
# This example returns the items
# from index -4 (included) to index -1 (excluded)

thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[-10:-1])
Output:
('apple', 'banana', 'cherry', 'orange', 'kiwi', 'melon')


Program No. 6:
# Change Tuple Values
# Once a tuple is created, you cannot change its values.
# Tuples are unchangeable, or immutable.

# But there is a workaround. You can convert the tuple into a list,
# change the list, and convert the list back into a tuple.
# Example
# Convert the tuple into a list to be able to change it:

x = ("apple", "banana", "cherry")
print(x)
print(type(x))
y = list(x)
print(type(y))
print(y)
y[1] = "kiwi"
x = tuple(y)
print(x)
Output:
('apple','kiwi','cherry')

With kind regards,

#sdbhosale



Google Meet Session Video:



No comments:

Post a Comment