Subscribe this Blog

Wikipedia

Search results

Notifications and New Posts!

Saturday, September 19, 2020

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

 ADVANCED PROGRAMMING CONCEPTS - Python

Saturday, 19 September16:00 – 17:00
Weekly on Saturday, until 30 Nov 2020
Join with Google Meet
https://meet.google.com/fza-dxad-utd
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
  1. 5 minutes before
Organiser: Sachin Bhosale

To know attendance : Click here (Sorry! I forgot to mark attendance!)

Program No. 1:
# Tuple Length
# To determine how many items a tuple has, use the len() method:
# Example
# Print the number of items in the tuple:

thistuple = ("apple", "banana", "cherry","kiwi","chiku")
print(len(thistuple))
Output:
5

Program No. 2:
# Add Items
# Once a tuple is created, you cannot add items to it.
# Tuples are unchangeable.
# Example
# You cannot add items to a tuple:

thistuple = ("apple", "banana", "cherry")
thistuple[1] = "orange" # This will raise an error
print(thistuple)
Output:
Traceback (most recent call last):
  File "C:/Users/Hp/PycharmProjects/python_tuple/8.py", line 9, in <module>
    thistuple[1] = "orange" # This will raise an error
TypeError: 'tuple' object does not support item assignment

Program No. 3:
# Create Tuple With One Item
# To create a tuple with only one item, you have to add a comma after the item,
# otherwise Python will not recognize it as a tuple.
# Example
# One item tuple, remember the commma:

thistuple = ("apple",)
print(type(thistuple))

#NOT a tuple
thistuple = ("apple")
print(type(thistuple))
Output:
<class 'tuple'>
<class 'str'>

Program No. 4:
# Remove Items
# Note: You cannot remove items in a tuple.
# Tuples are unchangeable, so you cannot remove items from it,
# but you can delete the tuple completely:
# Example
# The del keyword can delete the tuple completely:

thistuple = ("apple", "banana", "cherry")
del thistuple
#print(thistuple)
#this will raise an error because the tuple no longer exists
Output:


Program No. 5:
# Remove Items
# Note: You cannot remove items in a tuple.
# Tuples are unchangeable, so you cannot remove items from it,
# but you can delete the tuple completely:
# Example
# The del keyword can delete the tuple completely:

thistuple = ("apple", "banana", "cherry")
del thistuple
print(thistuple)
#this will raise an error because the tuple no longer exists
Output:
Traceback (most recent call last):
  File "C:/Users/Hp/PycharmProjects/python_tuple/10.py", line 10, in <module>
    print(thistuple)
NameError: name 'thistuple' is not defined

Program No. 6:
# Join Two Tuples
# To join two or more tuples you can use the + operator:
# Example
# Join two tuples:
tuple1 = ("a", "b" , "c")
tuple2 = (1,)
tuple4=(2.0,)

tuple3 = tuple1 + tuple2 + tuple4
print(tuple3)
Output:
('a', 'b', 'c', 1, 2.0)

Program No. 7:
# Join Two Tuples
# To join two or more tuples you can use the + operator:
# Example
# Join two tuples:
tuple1 = ("a", "b" , "c")
tuple2 = (1,)
tuple4=(2.0)

tuple3 = tuple1 + tuple2 + tuple4
print(tuple3)
Output:
Traceback (most recent call last):
  File "C:/Users/Hp/PycharmProjects/python_tuple/11.py", line 9, in <module>
    tuple3 = tuple1 + tuple2 + tuple4
TypeError: can only concatenate tuple (not "float") to tuple

Program No. 8:
# The tuple() Constructor
# It is also possible to use the tuple() constructor to make a tuple.
# Example
# Using the tuple() method to make a tuple:


thistuple = tuple(["apple", "banana", "cherry"]) # note the double round-brackets or Square bracket
print(thistuple)
print(type(thistuple))
Output:
('apple', 'banana', 'cherry')
<class 'tuple'>

Program No. 9:
# Tuple Methods
# In case of tuple, following two methods are python methods. They are not built-in methods
# Method Description
# count() Returns the number of times a specified value occurs in a tuple
# index() Searches the tuple for a specified value and returns the position of where it was found

thistuple=("Ganesh","Ramesh","Rupesh","Rupesh","Ganesh","ganesh")

values_in_thistuple=thistuple.count("Ganesh")

print("Ganesh","is present ",values_in_thistuple,"times!")

print(thistuple.count("Ganesh"))
print(thistuple.index("Ramesh"))
Output:
Ganesh is present  2 times!
2
1

Let's Learn Set - python literal now

Program No. 1:
# Set
# A set is a collection which is unordered and unindexed.
# In Python sets are written with curly brackets.
#Note: Sets are unordered, so you cannot be sure in which order the items will appear.
# Example
# Create a Set:

thisset = {"apple", "banana", "cherry",1,2.0}
print(type(thisset))
print(thisset)
Output:
<class 'set'>
{'apple', 1, 'cherry', 2.0, 'banana'}

Program No. 2:
# Access Items
# You cannot access items in a set by referring to an index,
# since sets are unordered the items has no index.
# But you can loop through the set items using a for loop,
# or ask if a specified value is present in a set, by using the in keyword.
# Example
# Loop through the set, and print the values:

set1 = {"apple", "banana", "cherry","kiwi"}

for w in set1:
  print(w)
  print("welcome")

Output:
apple
welcome
kiwi
welcome
banana
welcome
cherry
welcome

Program No. 3:
# Access Items
# You cannot access items in a set by referring to an index,
# since sets are unordered the items has no index.
# But you can loop through the set items using a for loop,
# or ask if a specified value is present in a set, by using the in keyword.
# Example
# Loop through the set, and print the values:

set1 = {"apple", "banana", "cherry","kiwi"}

for w in set1:
  print(w)
print("welcome")
Output:
banana
kiwi
apple
cherry
welcome

With kind regards,

#sdbhosale


Recorded Google Meet Session Session with OBS


YouTube Channel.

<! -- The End -->

No comments:

Post a Comment