Jayashree has Published 41 Articles

How to know Maximum and Minimum values for ints in Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:51:33

53 Views

Python's core library has two built-in functions max() and min() respectively to find maximum and minimum number from a sequence of numbers in the form of list or tuple object.example>>> max(23,21,45,43) 45 >>> l1=[20,50,40,30] >>> max(l1) 50 >>> t1=(30,50,20,40) >>> max(t1) 50 >>> min(l1) 20 >>> min(t1) 20 >>> min(23,21,45,43) 21

How to find sum a list of numbers in Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:30:30

105 Views

Python's built-in function sum() returns sum of numbers in an iterable object such as list or tuple. It takes two arguments, initial value which is optional and 0 by default and iterable objectExample>>> l1=[10,20,30,40,50] >>> ttl=sum(l1) >>> ttl 150 >>> ttl=sum(range(10)) >>> ttl 45

How to find the greatest number in a list of numbers in Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:27:17

162 Views

Python's built-in library function max() returns the largest number in an iterable or commaa separated list of numbers.>>> max(10,23,43,21) 43 >>> l1=[4,7,2,9,1] >>> max(l1) 9

How to generate armstrong numbers in Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:26:50

897 Views

Any three digit number is called an Armstrong number of sum of cube of its digits equals the number itself. In order to check if a number satisfies this condition, each digit from it is successively separated from right and its cube is cumulatively added. In the end if the ... Read More

How to print the Fibonacci Sequence using Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:25:51

536 Views

Fibonacci series contains numbers where each number is sum of previous two numbers. This type of series is generated using looping statement.Examplex=0 y=1 fibo=0 while fibo

How to create Python dictionary with duplicate keys?

Jayashree

Jayashree

Updated on 04-Dec-2019 06:37:43

4K+ Views

Python dictionary doesn't allow key to be repeated. However, we can use defaultdict to find a workaround. This class is defined in collections module.Use list as default factory for defaultdict object>>> from collections import defaultdict >>> d=defaultdict(list)Here is a list of tuples each with two items. First item is found to ... Read More

How to extract subset of key-value pairs from Python dictionary object?

Jayashree

Jayashree

Updated on 04-Dec-2019 05:31:43

2K+ Views

Use dictionary comprehension technique.We have dictionary object having name and percentage of students>>> marks = {    'Ravi': 45.23,    'Amar': 62.78,    'Ishan': 20.55,    'Hema': 67.20,    'Balu': 90.75 }To obtain dictionary of name and marks of students with percentage>50>>> passed = { key:value for key, value in ... Read More

How will you explain Python Operator Overloading?

Jayashree

Jayashree

Updated on 30-Jul-2019 22:30:22

133 Views

Every class in Python, whether built-in or user defined is inherited from object class. The object class has a number of properties whose name is preceded and followed by double underscores (__). Each of these properties is a wrapper around a method of same name. Such methods are called special ... Read More

How to create a Python dictionary from text file?

Jayashree

Jayashree

Updated on 30-Jul-2019 22:30:22

11K+ Views

Assuming a following text file (dict.txt) is present1 aaa2 bbb3 cccFollowing Python code reads the file using open() function. Each line as string is split at space character. First component is used as key and second as valued = {} with open("dict.txt") as f: for line in f:     ... Read More

What is @ operator in Python?

Jayashree

Jayashree

Updated on 30-Jul-2019 22:30:22

244 Views

@ symbol is used to define decorator in Python. Decorators provide a simple syntax for calling higher-order functions. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.we have two different kinds of decorators in Python:Function decoratorsClass ... Read More

Advertisements