Posts

Showing posts from December, 2023

Python for beginners- Dictionary Operations

 Dictionary is one of the type of collections in python. It combines variety of data items under a common name. Syntax be like,  Name={               "Membername1":"Value",               "Membername2":"Value",                ........................................                   "Membernamen":"Value"              } An example is given below... Eg: Creating a dictionary named "sunglass"  sunglass = {                       "brand": "Suntrack"                       "model": "Wideangle"                       "Year " : "2023"                      } To print the...

How to add a value, remove a value and emptying a list???

 List has many operations to perform. The basic operations like creating a list, changing a value, displaying a list, searching an element in a list and finding length of a variable is explained in part 1. https://www.blogger.com/blog/post/edit/5251857942821229/7649420483850529537 In part 2, the remaining operations are listed below. Adding a value Removing a value Empty a list Usage of constructor  The operations are explained below.   =>Adding a value:                 This can be achieved by two ways. First one is adding a value in the end of the list. Second one  deals with adding in a specified index.     Method1:Adding a value in the end of the list:      colorlist=["Red", "Green", "Yellow" ]      colorlist.append( "Orange")      print(colorlist)     W hile executing this code, you get the following output.       [ 'Red', 'Green',...

How to create a list and its operations???

Python collections      Collection is a set of elements stored in a sequence. In python, there are 4 types of collections. They are List Tuple Set Dictionary In the above collections, list has variety of operations to do. Lists   List is a collection in python. It can store any type of data. It has variety of operations to perform like creating, displaying, access, add, delete, search and so on. 1.Creating a list  This is the way of creating a new list in python. Colorlist is the list name. Red,Green,Yellow are the values.  colorlist=[“Red”,”Green”,”Yellow”] print(colorlist)  When you execute this code, you get the following output. ['Red', 'Green' ,'Yellow'] 2.Access the list items   After creating the list, you can access the items. Here,it displays the data in first position. list is always starts from index 0. colorlist=[“Red”,”Green”,”Yellow”] print(colorlist[1]...

Python program for beginners - String operations.

Image
 String is a collection of characters. It is stored in sequence as an array. Normally a string in python is assigned a value by the following syntax. Syntax: String_Variable= " String value " Eg: a= " Best wishes" where, a is a variable that represents string. "Best wishes" is the value assigned to string. Next, a simple python program to display this string is given below. a="Best wishes" print(a) The Program and its output are like this. The operations on a string variable are listed here. Extracting a character or set of characters. Finding the total number of characters (Length) in a string Converting upper case to Lowercase and vice versa. Adding two strings Replacing characters Splitting the string into sub string White space removing The sample code is given as below. Extracting a character or set of characters.           a="Best Wishes"           print (a[5:11])                   ...

Python program to generate fibonacci series

Image
 Maths has some wonderful sequences of numbers. one among that is Fibonacci series. The logic behind Fibonacci series is very simple. It starts with two numbers 0,1 as the first and second elements. the next number is the sum of the previous two numbers. Likewise ,it goes on until it reaches the number of the elements in the series. In python, it has following steps. This Fibonacci series program starts with getting the number of elements for the series.  Next, it assigns the values to the first two numbers.  It checks the number of elements is less than zero. If yes means, the number is a negative value. So, it prints a message that enter a positive number. Else if the number of elements is equal to 1, it print the the first number alone. Else, it starts a loop. It prints the first value. It adds the previous two numbers and store it into third variable. It exchanges the value of  second variable to first variable and  the value of third variable to second vari...