{"id":7915,"date":"2021-09-30T10:30:35","date_gmt":"2021-09-30T05:00:35","guid":{"rendered":"https:\/\/python-programs.com\/?p=7915"},"modified":"2021-11-22T18:35:34","modified_gmt":"2021-11-22T13:05:34","slug":"python-programs-for-class-12","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-programs-for-class-12\/","title":{"rendered":"Python Programs for Class 12 | Python Practical Programs for Class 12 Computer Science"},"content":{"rendered":"
Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output<\/a><\/p>\n CBSE Class 12 Computer Science Python Programs with Output<\/strong> are provided in this tutorial. Students who are pursuing 12th can refer to this page for practical files of python programs in order to prepare and learn well for the board exams. Basically, the Class XII python practical file must have 20 python programs and 5 SQL Queries. But today, in this tutorial, we are going to compile some of the important python programs for class 12 CBSE computer science.<\/p>\n Practicing more and more with the provided python practical programs for Class XII CBSE<\/strong> can make you win in the race of python programming and in your software career too. So, dive into this article completely and start learning python programming language<\/a> easily and efficiently.<\/p>\n Here are some of the python programs for class 12 pursuing students. Just take a look at them before kickstarting your programming preparation for board exams. Click on the available links and directly jump into the respective python program to understand & continue with other programs that are listed in the CBSE Class 12 Computer Science Python Programming Practical File.<\/strong><\/p>\n Task is to perform Arithmetic Operations in python<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We’ll write a program that produces a random number between a specific range.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will convert the given temp in celsius to fahrenheit as below.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will write a program to check if the given number is positive number , negative number or zero using if else conditional statements.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will write a program which checks whether the given number is even number or odd number using if else conditional statements.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will check whether the given number is leap year or not.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will find the ascii value of given character in python using ord() function.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will display the grades of students based on given marks using if elif else statements.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given two ranges(lower limit range and upper limit range) the task is to print the sum of all numbers in the given range.<\/p>\n i)Using for loop<\/strong><\/p>\n We will use for loop and range function to literate from lower range limit and upper range limit.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n ii)Using mathematical formula of sum of n natural numbers<\/strong><\/p>\n We we subtract the sum of upper range limit with lower range limit.<\/p>\n sum of n natural numbers =( n * (n+1) ) \/2<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given two ranges(lower limit range and upper limit range) the task is to print all even numbers in given range<\/p>\n We will use for loop and range function to literate from lower range limit and upper range limit and print all the numbers which are divisible by 2 that\u00a0 is even numbers<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will print the star pyramid using nested for loops<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will print the number pyramid using nested for loops<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given two ranges(lower limit range and upper limit range) the task is to print all fibonacci numbers in given range<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use the for loop to print all numbers from 1 to n except 5 multiples.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given a string the task is to split the given string and join the string<\/p>\n Example split the string with ‘@’ character and join with ‘-‘ character.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will sort the given list using sort() function<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given\u00a0 list of strings the task is to sort the strings using sort() function.<\/p>\n We will use the split() function to split the string with spaces and store it in list.<\/p>\n Sort the list.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given a list and the task is to search for a given element in the list .<\/p>\n We will use the count function to search an element in given list.<\/p>\n If the count is 0 then the element is not present in list<\/p>\n Else the given element is present in list<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Given a list and the task is to find the frequency of a given element in the list .<\/p>\n We will use the count function to find frequency of given element in given list.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use slicing to print the given list in reverse order<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use slicing to print the odd indexed elements in the given list .<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use the + operator to add(append) the two lists in python as below:<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use the counter function to calculate the frequency of each element in the given list in efficient way.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use counter function and print all the keys in it<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use slicing to print the even indexed elements in the given list .<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We have two methods to print the given lists elements in the same line<\/p>\n i)Using end\u00a0<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n ii)Using * operator<\/strong><\/p>\n We can use * operator to print all the elements of given list in single line<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use counter function and print all the keys in it to print all distinct characters in given string<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We will use the sort() and reverse=True to sort the given list in descending order<\/p>\nList of Python Programs for Class 12 Practical File with Output PDF<\/h2>\n
\n
1)Program for Arithmetic Operations in Python<\/h3>\n
#python program which performs simple arithmetic operations\r\n# given two numbers\r\n# given first number\r\nnumberone = 29\r\nnumbertwo = 13\r\n# adding the given two numbers\r\naddnumb = numberone+numbertwo\r\n# printing the result of sum of two numbers\r\nprint(\"Adding the given two numbers\", numberone, \"+\", numbertwo, \"=\", addnumb)\r\n# subtracting the given two numbers\r\ndiffnumb = numberone-numbertwo\r\n# printing the result of difference of two numbers\r\nprint(\"Subtracting the given two numbers\",\r\n numberone, \"-\", numbertwo, \"=\", diffnumb)\r\n# multiply the given two numbers\r\nmulnumb = numberone*numbertwo\r\n# printing the result of product of two numbers\r\nprint(\"Multiplying the given two numbers\",\r\n numberone, \"*\", numbertwo, \"=\", mulnumb)\r\n# diving the given two numbers\r\ndivnumb = numberone+numbertwo\r\n# printing the result of sum of two numbers\r\nprint(\"Dividing the given two numbers\",\r\n numberone, \"\/\", numbertwo, \"=\", divnumb)\r\n<\/pre>\n
Adding the given two numbers 29 + 13 = 42\r\nSubtracting the given two numbers 29 - 13 = 16\r\nMultiplying the given two numbers 29 * 13 = 377\r\nDividing the given two numbers 29 \/ 13 = 42<\/pre>\n
2)Program to Generate a Random Number<\/h3>\n
# Program which generates the random number between a specific range.\r\n# importing random module as below\r\nimport random\r\n# generating random number\r\nrandNumber = random.randint(1, 450)\r\n# print the random number which is generated above\r\nprint(\"Generating random numbers between 1 to 450 = \", randNumber)\r\n<\/pre>\n
Generating random numbers between 1 to 450 = 420<\/pre>\n
3)Program to Convert Celsius To Fahrenheit<\/h3>\n
# Python program\u00a0for converting celsius to fahrenheit temperature.\r\n# given temp in celsius\r\ncelsiusTemp = 42.5\r\n\r\n# converting the given temp in celsius to fahrenheit temperature\r\nfahrenheitTemp = (celsiusTemp * 1.8) + 32\r\n# print the converted temperature value\r\nprint('Converting the given temp in celsius =',\r\n celsiusTemp, \" to Fahrenhiet = \", fahrenheitTemp)\r\n<\/pre>\n
Converting the given temp in celsius = 42.5 to Fahrenhiet = 108.5<\/pre>\n
4)Python Program to Check if a Number is Positive, Negative or zero<\/h3>\n
# Python Program to Check if a Number is Positive number, Negative number or zero\r\n# Function which prints whether the given number\r\n#is positive number ,negative number or zero\r\n\r\n\r\ndef checkNumber(given_Num):\r\n # checking if the given number is positive number\r\n if(given_Num > 0):\r\n print(\"The given number\", given_Num, \"is positive\")\r\n # checking if the given number is negative number\r\n elif(given_Num < 0):\r\n print(\"The given number\", given_Num, \"is negative\")\r\n # if the above conditions are not satisfied then the given number is zero\r\n else:\r\n print(\"The given number\", given_Num, \"is zero\")\r\n\r\n\r\n# given numbers\r\n# given number 1\r\ngiven_num1 = 169\r\n# passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0)\r\ncheckNumber(given_num1)\r\n# given number 2\r\ngiven_num1 = -374\r\n# passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0)\r\ncheckNumber(given_num1)\r\n\r\n# given number 3\r\ngiven_num1 = 0\r\n# passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0)\r\ncheckNumber(given_num1)\r\n<\/pre>\n
The given number 169 is positive\r\nThe given number -374 is negative\r\nThe given number 0 is zero<\/pre>\n
5)Python Program to Check if a Number is Odd or Even<\/h3>\n
# Python Program to Check if a Number is Odd or Even\r\n# Function which prints whether the given number\r\n# is even number ,odd number\r\n\r\n\r\ndef checkNumber(given_Num):\r\n # checking if the given number is even number\r\n if(given_Num % 2 == 0):\r\n print(\"The given number\", given_Num, \"is even number\")\r\n # checking if the given number is odd number that is if given number is not even then it is odd number\r\n else:\r\n print(\"The given number\", given_Num, \"is odd number\")\r\n\r\n\r\n# given numbers\r\n# given number 1\r\ngiven_num1 = 169\r\n# passing the given number to checkNumber Function which\r\n# prints the type of number(even number or odd number)\r\ncheckNumber(given_num1)\r\n# given number 2\r\ngiven_num1 = 26\r\n# passing the given number to checkNumber Function which\r\n# prints the type of number(even number or odd number)\r\ncheckNumber(given_num1)\r\n<\/pre>\n
The given number 169 is odd number\r\nThe given number 26 is even number<\/pre>\n
6)Python Program to Check Leap Year<\/h3>\n
# Python program to check if year is a leap year\r\n# given year\r\ngiven_year = 2024\r\n\r\nif (given_year % 4) == 0:\r\n if (given_year % 100) == 0:\r\n if (given_year % 400) == 0:\r\n print(\"Given year\", given_year, \"is leap year\")\r\n else:\r\n print(\"Given year\", given_year, \"is not leap year\")\r\n else:\r\n print(\"Given year\", given_year, \"is leap year\")\r\nelse:\r\n print(\"Given year\", given_year, \"is not leap year\")\r\n<\/pre>\n
Given year 2024 is leap year<\/pre>\n
7)Python Program to Find ASCII Value of given_Character<\/h3>\n
# Python Program to Find ASCII Value of given_Character\r\n# given character\r\ngiven_character = 's'\r\n# finding ascii value of given character\r\nasciiValue = ord(given_character)\r\n# printing ascii value of given character\r\nprint(\" ascii value of given character\", given_character, \"=\", asciiValue)\r\n<\/pre>\n
ascii value of given character s = 115<\/pre>\n
8)Python program to print grades based on marks scored by a student<\/h3>\n
# Python program to print grades based on marks scored by a student\r\n# given marks scored by student\r\ngiven_marks = 68\r\nmarkGrade = given_marks\/\/10\r\n# cheecking if grade greater than 9\r\nif(markGrade >= 9):\r\n print(\"grade A+\")\r\nelif(markGrade < 9 and markGrade >= 8):\r\n print(\"grade A\")\r\nelif(markGrade < 8 and markGrade >= 7):\r\n print(\"grade B+\")\r\nelif(markGrade < 7 and markGrade >= 6):\r\n print(\"grade B\")\r\nelif(markGrade < 6 and markGrade >= 5):\r\n print(\"grade C+\")\r\nelse:\r\n print(\"Fail\")\r\n<\/pre>\n
grade B<\/pre>\n
9)Python program to print the sum of all numbers in the given range<\/h3>\n
# Python program to print the sum of all numbers in the given range\r\n# given lower limit range\r\nlower_range = 17\r\n# given upper limit range\r\nupper_range = 126\r\n# initializing sum of range to 0\r\nrangeSum = 0\r\n# Using for loop to traverse from lower limit range to upper limit range\r\nfor i in range(lower_range, upper_range+1):\r\n rangeSum = rangeSum+i\r\nprint(\"the sum of all numbers between\",\r\n lower_range, \"to\", upper_range, \"=\", rangeSum)\r\n<\/pre>\n
the sum of all numbers between 17 to 126 = 7865<\/pre>\n
# Python program to print the sum of all numbers in the given range\r\n# given lower limit range\r\nlower_range = 17\r\n# given upper limit range\r\nupper_range = 126\r\nlow_range = lower_range-1\r\n# calculating the sum of natural numbers from 1 to lower limit range\r\nlowSum = (low_range*(low_range+1))\/2\r\n# calculating the sum of natural numbers from 1 to upper limit range\r\nhighSum = (upper_range*(upper_range+1))\/2\r\n# calculating the sum of all numbers between the given range\r\nrangeSum = highSum-lowSum\r\n# printing the sum of all natural numbers between the given range\r\nprint(\"the sum of all numbers between\",\r\n lower_range, \"to\", upper_range, \"=\", int(rangeSum))\r\n<\/pre>\n
the sum of all numbers between 17 to 126 = 7865<\/pre>\n
10)Python program to print all even numbers in given range<\/h3>\n
# Python program to print the even numbers in\r\n# given range(lower limit range and upper limit range)\r\n# given lower limit range\r\nlower_range = 17\r\n# given upper limit range\r\nupper_range = 126\r\n# printing the even numbers in the giveen range using looop\r\n# Iterate from lowe limit range to upper limit range\r\nfor numb in range(lower_range, upper_range+1):\r\n # checking if the number is divisible by 2\r\n if(numb % 2 == 0):\r\n # we will print the number if the number is divisible by 2\r\n print(numb)\r\n<\/pre>\n
18\r\n20\r\n22\r\n24\r\n26\r\n28\r\n30\r\n32\r\n34\r\n36\r\n38\r\n40\r\n42\r\n44\r\n46\r\n48\r\n50\r\n52\r\n54\r\n56\r\n58\r\n60\r\n62\r\n64\r\n66\r\n68\r\n70\r\n72\r\n74\r\n76\r\n78\r\n80\r\n82\r\n84\r\n86\r\n88\r\n90\r\n92\r\n94\r\n96\r\n98\r\n100\r\n102\r\n104\r\n106\r\n108\r\n110\r\n112\r\n114\r\n116\r\n118\r\n120\r\n122\r\n124\r\n126<\/pre>\n
11)Python program to print\u00a0 star pyramid pattern<\/h3>\n
# Python program to print\u00a0 star pyramid pattern\r\n# given number of rows\r\ngiven_rows = 15\r\nfor i in range(given_rows+1):\r\n for j in range(i):\r\n print(\"*\", end=\" \")\r\n print()\r\n<\/pre>\n
* \r\n* * \r\n* * * \r\n* * * * \r\n* * * * * \r\n* * * * * * \r\n* * * * * * * \r\n* * * * * * * * \r\n* * * * * * * * * \r\n* * * * * * * * * * \r\n* * * * * * * * * * * \r\n* * * * * * * * * * * * \r\n* * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * *<\/pre>\n
12)Python program to print\u00a0 number pyramid pattern<\/h3>\n
# Python program to print\u00a0 star pyramid pattern\r\n# given number of rows\r\ngiven_rows = 15\r\nfor i in range(1, given_rows+1):\r\n for j in range(1, i+1):\r\n print(j, end=\" \")\r\n print()\r\n<\/pre>\n
1 \r\n1 2 \r\n1 2 3 \r\n1 2 3 4 \r\n1 2 3 4 5 \r\n1 2 3 4 5 6 \r\n1 2 3 4 5 6 7 \r\n1 2 3 4 5 6 7 8 \r\n1 2 3 4 5 6 7 8 9 \r\n1 2 3 4 5 6 7 8 9 10 \r\n1 2 3 4 5 6 7 8 9 10 11 \r\n1 2 3 4 5 6 7 8 9 10 11 12 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15<\/pre>\n
13)Python program to print Fibonacci numbers to given limit<\/h3>\n
# Python program to print the all the fibonacci numbers in the given range\r\n# given lower limit range\r\nlower_range = 2\r\n# given upper limit range\r\nupper_range = 1000\r\nfirst, second = 0, 1\r\n# using while loop\r\nwhile (first < upper_range):\r\n if(upper_range >= lower_range and first <= upper_range):\r\n print(first)\r\n first, second = second, first+second\r\n<\/pre>\n
0\r\n1\r\n1\r\n2\r\n3\r\n5\r\n8\r\n13\r\n21\r\n34\r\n55\r\n89\r\n144\r\n233\r\n377\r\n610\r\n987<\/pre>\n
14)Python program to print numbers from 1 to n except 5 multiples<\/h3>\n
# Python program to print numbers from 1 to n except 5 multiples\r\n# given number\r\nnumb = 49\r\n# using for loop to iterate from 1 to n\r\nfor num in range(1, numb+1):\r\n # if number is not divisible by 5 then print it\r\n if(num % 5 != 0):\r\n print(num)\r\n<\/pre>\n
1\r\n2\r\n3\r\n4\r\n6\r\n7\r\n8\r\n9\r\n11\r\n12\r\n13\r\n14\r\n16\r\n17\r\n18\r\n19\r\n21\r\n22\r\n23\r\n24\r\n26\r\n27\r\n28\r\n29\r\n31\r\n32\r\n33\r\n34\r\n36\r\n37\r\n38\r\n39\r\n41\r\n42\r\n43\r\n44\r\n46\r\n47\r\n48\r\n49\r\n\r\n<\/pre>\n
15)Python program to split and join a string<\/h3>\n
#python program to split and join a string\r\n# given string\r\nstring = \"Hello@this@is@BTechGeeks\"\r\n# splitting thee given string with @ character\r\nstring = string.split('@')\r\nprint(\"After splitting the string the given string =\", *string)\r\n# joining the given string\r\nstring = '-'.join(string)\r\nprint(\"After joining the string the given string =\", string)\r\n<\/pre>\n
After splitting the string the given string = Hello this is BTechGeeks\r\nAfter joining the string the given string = Hello-this-is-BTechGeeks<\/pre>\n
16)Python program to sort the given list<\/h3>\n
# Python program to sort the given list\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\"]\r\n# printing the list before sorting\r\nprint(\"Before sorting the list given list :\")\r\nprint(given_list)\r\n# sorting the given list using sort() function\r\ngiven_list.sort()\r\n# printing thre list after sorting\r\nprint(\"after sorting the list given list :\")\r\nprint(given_list)\r\n<\/pre>\n
Before sorting the list given list :\r\n['Hello', 'This', 'Is', 'BTechGeeks']\r\nafter sorting the list given list :\r\n['BTechGeeks', 'Hello', 'Is', 'This']<\/pre>\n
17)Python program to sort a string<\/h3>\n
# Python program to sort a string\r\ngiven_string = \"Hello This Is BTechGeeks\"\r\n# split the given string using spilt() function(string is separated by spaces)\r\ngiven_string = given_string.split()\r\n# printing the string before sorting\r\nprint(\"Before sorting the sorting given sorting :\")\r\nprint(*given_string)\r\n# sorting the given string(list) using sort() function\r\ngiven_string.sort()\r\n# printing the string after sorting\r\nprint(\"after sorting the string given string :\")\r\nprint(*given_string)\r\n<\/pre>\n
Before sorting the sorting given sorting :\r\nHello This Is BTechGeeks\r\nafter sorting the string given string :\r\nBTechGeeks Hello Is This<\/pre>\n
18)Python Program to Search an element in given list<\/h3>\n
# Python program to search an element in given list\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\"]\r\n# given element to search\r\nelement = \"BTechGeeks\"\r\n# using count function to check whether the given element the present in list or not\r\ncountelement = given_list.count(element)\r\n# if count of element is zero then element is not present in list\r\nif(countelement == 0):\r\n print(\"The given element\", element, \"is not present in given list\")\r\nelse:\r\n print(\"The given element\", element, \"is present in given list\")\r\n<\/pre>\n
The given element BTechGeeks is present in given list<\/pre>\n
19)Python program to count the frequency of given element in list<\/h3>\n
# Python program to count the frequency of given element in list\r\ngiven_list = [\"Hello\", \"BTechGeeks\", \"This\", \"Is\", \"BTechGeeks\"]\r\n\r\n# given element to search\r\nelement = \"BTechGeeks\"\r\n# using count function to count the given element in list\r\ncountelement = given_list.count(element)\r\n# printing the count\r\nprint(\"The given element\", element, \"occurs\",\r\n countelement, \"times in the given list\")\r\n<\/pre>\n
The given element BTechGeeks occurs 2 times in the given list<\/pre>\n
20)Python program to print list in reverse order<\/h3>\n
# Python program to print list in reverse order\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\"]\r\n# printing the list before reversing\r\nprint(\"printing the list before reversing :\")\r\nprint(given_list)\r\n# reversing the given list\r\ngiven_list = given_list[::-1]\r\n# printing the list after reversing\r\nprint(\"printing the list after reversing :\")\r\nprint(given_list)\r\n<\/pre>\n
printing the list before reversing :\r\n['Hello', 'This', 'Is', 'BTechGeeks']\r\nprinting the list after reversing :\r\n['BTechGeeks', 'Is', 'This', 'Hello']<\/pre>\n
21)Python program to Print odd indexed elements in given list<\/h3>\n
# Python program to Print odd indexed elements in given list\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\", \"Online\", \"Platform\"]\r\n# odd indexed elements in given list using slicing\r\nodd_elements = given_list[1::2]\r\n# printing the odd indexed elements in given list\r\nfor i in odd_elements:\r\n print(i)\r\n<\/pre>\n
This\r\nBTechGeeks\r\nPlatform<\/pre>\n
22)Python program for Adding two lists in Python(Appending two lists)<\/h3>\n
# Python program for Adding two lists in Python(Appending two lists)\r\n# given list 1\r\ngiven_list1 = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\", \"Online\", \"Platform\"]\r\n# given list 2\r\ngiven_list2 = [\"Good\", \"Morning\", \"Python\"]\r\n# adding two lists using + operator\r\n# we add all the elements of second list to first list\r\ngiven_list1 = given_list1+given_list2\r\n# print the result after adding the two lists\r\nfor i in given_list1:\r\n print(i)\r\n<\/pre>\n
Hello\r\nThis\r\nIs\r\nBTechGeeks\r\nOnline\r\nPlatform\r\nGood\r\nMorning\r\nPython<\/pre>\n
23)Python program for finding frequency of each element in the given list<\/h3>\n
# Python program for finding frequency of each element in the given list\r\n# importing counter function from collections\r\nfrom collections import Counter\r\n# given list which may contains the duplicates\r\ngiven_list1 = [\"Hello\", \"this\", \"is\", \"this\", \"is\", \"BTechGeeks\", \"Hello\",\r\n \"is\", \"is\", \"this\", \"BTechGeeks\", \"is\", \"this\", \"Hello\", \"python\"]\r\n# finding frequency of each elements using Counter() function\r\nfreqcyCounter = Counter(given_list1)\r\n# printing the frequency of each element\r\nfor key in freqcyCounter:\r\n # frequency of the respective key\r\n count = freqcyCounter[key]\r\n # print the element and its frequency\r\n print(\"The element\", key, \"Has frequency =\", count)\r\n<\/pre>\n
The element Hello Has frequency = 3\r\nThe element this Has frequency = 4\r\nThe element is Has frequency = 5\r\nThe element BTechGeeks Has frequency = 2\r\nThe element python Has frequency = 1<\/pre>\n
24)Python program for printing all distinct elements in given list<\/h3>\n
# Python program for printing all distinct elements in given list\r\n# importing counter function from collections\r\nfrom collections import Counter\r\n# given list which may contains the duplicates\r\ngiven_list1 = [\"Hello\", \"this\", \"is\", \"this\", \"is\", \"BTechGeeks\", \"Hello\",\r\n \"is\", \"is\", \"this\", \"BTechGeeks\", \"is\", \"this\", \"Hello\", \"python\"]\r\n# finding frequency of each elements using Counter() function\r\nfreqcyCounter = Counter(given_list1)\r\n# printing the distinct elements of the given list\r\nprint(\"printing the distinct elements of the given list :\")\r\nfor key in freqcyCounter:\r\n print(key)\r\n<\/pre>\n
printing the distinct elements of the given list :\r\nHello\r\nthis\r\nis\r\nBTechGeeks\r\npython<\/pre>\n
25)Python program to Print even indexed elements in given list<\/h3>\n
# Python program to Print even indexed elements in given list\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\", \"Online\", \"Platform\"]\r\n# odd indexed elements in given list using slicing\r\nodd_elements = given_list[::2]\r\n# printing the even indexed elements in given list\r\nprint(\"printing the even indexed elements in given list :\")\r\nfor i in odd_elements:\r\n print(i)\r\n<\/pre>\n
printing the even indexed elements in given list :\r\nHello\r\nIs\r\nOnline<\/pre>\n
26)Python program to Print the given list elements in the same line<\/h3>\n
# Python program to Print the given list elements in the same line\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\", \"Online\", \"Platform\"]\r\n\r\n# Traveersing the list using for loop\r\n# printing the given list elements\r\nprint(\"printing the given list elements :\")\r\nfor element in given_list:\r\n print(element, end=\" \")\r\n<\/pre>\n
printing the given list elements :\r\nHello This Is BTechGeeks Online Platform<\/pre>\n
# Python program to Print the given list elements in the same line\r\ngiven_list = [\"Hello\", \"This\", \"Is\", \"BTechGeeks\", \"Online\", \"Platform\"]\r\n# printing the given list elements\r\nprint(\"printing the given list elements :\")\r\nprint(*given_list)\r\n<\/pre>\n
printing the given list elements :\r\nHello This Is BTechGeeks Online Platform<\/pre>\n
27)Python program to count distinct characters in the given string<\/h3>\n
# Python program to count distinct characters in the given string\r\n# importing counter function from collections\r\nfrom collections import Counter\r\n# given string\r\nstring = \"Hello@--472BtechGeeks!!;<>?\"\r\n# using counter function\r\ndistchars = Counter(string)\r\n# Traversing through distchars dictionary\r\n# printing the distinct characters in given string\r\nprint(\"printing the distinct characters in given string\", string)\r\nfor key in distchars:\r\n print(key)\r\n<\/pre>\n
printing the distinct characters in given string Hello@--472BtechGeeks!!;<>?\r\nH\r\ne\r\nl\r\no\r\n@\r\n-\r\n4\r\n7\r\n2\r\nB\r\nt\r\nc\r\nh\r\nG\r\nk\r\ns\r\n!\r\n;\r\n<\r\n>\r\n?<\/pre>\n
28)Python program to Sort the given list elements in descending order<\/h3>\n