Subscribe this Blog

Wikipedia

Search results

Notifications and New Posts!

Thursday, September 10, 2020

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

 ADVANCED PROGRAMMING CONCEPTS - Python
Thursday, 10 September13:30 – 15:30
Join with Google Meet
https://meet.google.com/hid-dmnv-qxw

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. 10 minutes before

Organiser: Sachin Bhosale

To know attendance - Click here

Reference : https://www.w3schools.com/python/

Today's Learning : We started to understand python literal in details - List

Python programs:
Program No. 1:
# Change Item Value
# To change the value of a specific item, refer to the index number:
# Example
# Change the second item:

thislist = ["apple", "banana", "cherry"]
print("Before changing item value=",thislist)
thislist[2] = 20.2
print("After changing item value=",thislist)
Output:
Before changing item value= ['apple', 'banana', 'cherry']
After changing item value= ['apple', 'banana', 20.2]

Program No. 2:
thislist = ["apple", "banana", "cherry"]
print("Before changing item value=",thislist)
thislist[3] = 20.2
print("After changing item value=",thislist)
Output:
Before changing item value= ['apple', 'banana', 'cherry']
Traceback (most recent call last):
  File "C:/Users/Hp/PycharmProjects/python_list/8.py", line 8, in <module>
    thislist[3] = 20.2
IndexError: list assignment index out of range


Program No. 3:
# List Length
# To determine how many items a list has, use the len() function:
# Example
# Print the number of items in the list:

thislist = [7,5,4,3,11,0.52,"SVERI"]
print(len(thislist))
Output:
Total Number of items present in the thislist= 7


Program No. 4:
# Add Items
# To add an item to the end of the list, use the append() method:
# Example
# Using the append() method to append an item:
#TypeError: append() takes exactly one argument (2 given)

thislist = ["apple", "banana", "cherry"]
print("Before adding item: ",thislist)
thislist.append("orange")
print("After adding item: ",thislist)

Output:
Before adding item:  ['apple', 'banana', 'cherry']
After adding item:  ['apple', 'banana', 'cherry', 'orange']


Program No. 5:
# To add an item at the specified index, use the insert() method:
# Example
# Insert an item as the second position:

thislist = ["apple", "banana", "cherry"]
print("Before inserting: ",thislist)
thislist.insert(1, "orange")
print("after inserting at specific location: ",thislist)

Output:
Before inserting:  ['apple', 'banana', 'cherry']
after inserting at specific location:  ['apple', 'orange', 'banana', 'cherry']

With kind regards,

#sdbhosale


Google Meet Session:



No comments:

Post a Comment