Thursday 23 February 2023

3 Ways to store numbers in a python list

There are many methods to store numbers in a python list. Lets explore top 3 ways to store numbers in a python list. 

Top 3 ways to store numbers in a python list. To understand this, we will write a python code to store contact number of 3 students.

Python code to store contact number of 3 students in a list.

Example 1: 

# first create an empty list to store contact numbers
mobile_numbers = []

# add mobile numbers of 3 students to the list
mobile_numbers.append("2345678901")
mobile_numbers.append("3456789012")
mobile_numbers.append("4567890123")

# print the list to verify
print(mobile_numbers)


Description of the example 1:

This code will create an empty list (name of list: mobile_numbers) and then adds 3 mobile numbers to it. You can replace the mobile numbers with the actual mobile numbers of the students. Using append() function, add elements to the list. The print() function is used to verify the list.


Example 2

mobile_numbers = ['2345678901''3456789012''4567890123']
print(mobile_numbers)


Example 3

# Create an empty list to store contact numbers
student_numbers = []

# Read contact numbers and append it to a list

for i in range(5):
    number = input(f"Enter contact number of student{i+1}: ")
    student_numbers.append(number)

# Print list of contact numbers
print("Contact numbers of 5 students:")
print(student_numbers)

*  *  *  *  *


Thursday 16 February 2023

Brief note on Python Collections

Python Collections

Python collections are containers used to store and manage a collection of related data. These containers are built-in data types in Python and provide several operations to efficiently manipulate data. The Python collections include:

  1. List - It is an ordered collection of elements that can be of any data type. Lists are mutable, i.e., you can add, remove or modify elements.
  2. Tuple - It is an ordered collection of elements that can be of any data type. However, tuples are immutable, i.e., you cannot change the elements.
  3. Set - It is an unordered collection of unique elements. Sets are mutable, and you can add or remove elements.
  4. Dictionary - It is an unordered collection of key-value pairs. Dictionaries are mutable, and you can add, remove, or modify key-value pairs.

Python collections provide several functions and methods that allow you to perform various operations on the data. Some of these operations include sorting, filtering, searching, and iteration. 

By using Python collections, you can efficiently handle large amounts of data and build complex applications.

Get more details about Python programming collection at following link:


Top of Form