Python Tutorial – How to Use Global Variables in a Function | Python Programs Examples

In this post we are going to use learn about how to use global variables in a function, its usage and basic examples of python programs. Variables in Programming Language Variables are defined as a place where the data is put to store in memory just take an example of your belonging before keeping them … Read more

How Immutable Is Different from Mutable Types, In python Programming

Mutable are those which could be edited after it is defined for example list whose elements can be edited even after defining, whereas in case of immutable we can not edit them for example String. What is Mutable? Mutuable are those data Types that can be edited after Declaration For example once a datatype is … Read more

What are Variables in Python | Rules for Naming Variables | Local vs Global Variables

In this post we are going to discuss variables in python, how to create variables, types of variables and basic examples. We will also see the rules for naming the python variables. What are Variables in Python Variables are the place or a virtual location that is stored in memory with a certain name to … Read more

How can I Randomly Select an Item from a List | Python List Problems with Answers

In this post we are going to learn about python list – how to select an element randomly, basic concepts of list, how to iterate the list , size of the list, adding element into a list along with examples and python programs. List in Python Lists are just like dynamically sized arrays, Just like … Read more

What is Ordered Dictionary and Default Dictionary in Python?

What is Ordered Dictionary and Default Dictionary in Python?

Dictionary in Python Dictionary is an unordered collection of mutable values indexed by unique keys. Values in a dictionary can be of any datatype, mutable and can be duplicated, whereas keys can’t be repeated and are immutable. Dictionaries are just like map(), storing, and retrieving elements by referencing a key. As dictionaries are referenced by … Read more

Some Basic Python Tuple Programs-2

Some Basic Python Tuple Programs-2

Python Program to check if a tuple and a list are identical tuple = (9, 8, 7, 6, 5) list = [9, 8, 7, 6, 5] #using loop flag1 = True for i in range(0, len(tuple)): if tuple[i] != list[i]: flag1 = False break if flag1: print(f”{tuple} and {list} are identical”) else: print(f”{tuple} and {list} … Read more

Some Basic Python List Programs-3

Some Basic Python List Programs-3

Python program to remove duplicates from a list list1 = [2, 6, 9, 8, 4, 8, 6, 6, 5, 7, 2, 4] #using list comprehension list2 = [] [list2.append(ele) for ele in list1 if ele not in list2] print(list2) #Output: [2, 6, 9, 8, 4, 5, 7] #using list comprehension and enumerate() list3 = [ele … Read more

Some Basic Python String Programs-3

Some Basic Python String Programs-3

Python program to move Word to Rear-end str1 = “Beta Python: Python for U ” word = “Python” #using slicing and find() str2 = str1[:str1.find(word)] + str1[str1.find(word) + len(word):] + word print(str2) #Output: Beta : Python for U Python #using replace() str3 = str1.replace(word,””) + word print(str3) #Output: Beta : for U Python Slicing extracts … Read more

Some Basic Python Tuple Programs-3

Some Basic Python Tuple Programs-3

Python program to find the minimum and maximum value in a list of tuples tuple_list = [(6, 5), (3, 8), (1, 6), (4, 7), (3, 1)] ele1 = tuple(map(max, zip(*tuple_list))) ele2 = tuple(map(min, zip(*tuple_list))) print(ele1, el2) #Output: (6, 8) (1, 1) The built-in max() function returns the largest element in an iterable. The built-in min() … Read more

Some Basic Python String Programs-4

Some Basic Python String Programs-4

Python program to check if the string is ASCII string = “Beta Python: Python for U” #using all() and ord() if all(ord(ch) < 128 for ch in string): print(f”{string} is ASCII string”) else: print(f”{string} is not an ASCII string”) #Output: Beta Python: Python for U is ASCII string #using lambda and encode() if lambda ch: … Read more

%d bloggers like this: