Jayashree has Published 41 Articles

What is the difference between ++i and i++ in c?

Jayashree

Jayashree

Updated on 12-Sep-2023 02:57:07

30K+ Views

In C, ++ and -- operators are called increment and decrement operators. They are unary operators needing only one operand. Hence ++ as well as -- operator can appear before or after the operand with same effect. That means both i++ and ++i will be equivalent.i=5; i++; printf("%d", i);and i=5 ++i; printf("%d", ... Read More

How to Find Factors of Number using Python?

Jayashree

Jayashree

Updated on 09-Sep-2023 09:30:35

9K+ Views

In order to find factors of a number, we have to run a loop over all numbers from 1 to itself and see if it is divisible.Examplenum=int(input("enter a number")) factors=[] for i in range(1, num+1):     if num%i==0:        factors.append(i) print ("Factors of {} = {}".format(num, ... Read More

How to create Python dictionary by enumerate function?

Jayashree

Jayashree

Updated on 09-Sep-2023 09:28:50

4K+ Views

Python enumerate() function takes any iterable as argument and returns enumerate object using which the iterable can be traversed. It contains index and corresponding item in the iterable object like list, tuple, or string.Such enumerate object with index and value is then converted to a dictionary using dictionary comprehension.>>> l1=['aa', ... Read More

How do I find the largest integer less than x in Python?

Jayashree

Jayashree

Updated on 27-Oct-2022 12:23:22

2K+ Views

In this article, we will show you how to find the largest integer less than x in python. The Greatest Integer Function [X] denotes an integral part of the real number x that is the closest and smallest integer to x. It's also called the X-floor. [x]=the largest integer less ... Read More

How to Check Leap Year using Python?

Jayashree

Jayashree

Updated on 22-Dec-2020 07:33:54

600 Views

Leap year comes after every four years. For normal year, if it is divisible by four, it is called leap year, whereas for century year, it should be divisible by 400. The following Python program shows whether the year is leap or notExampleyr=int(input('enter year')) if yr%100==0: #century year if yr%400==0: ... Read More

What is random.uniform method in Python?

Jayashree

Jayashree

Updated on 24-Jun-2020 07:00:09

110 Views

The uniform() function is defined in the random module of the standard Python library. It returns a random floating-point number between a given range of numbers>>> import random >>> random.uniform(10,100) 20.118467024396452 >>> random.uniform(10,100) 23.739576765885502

How to randomize the items of a list in Python?

Jayashree

Jayashree

Updated on 24-Jun-2020 06:59:23

1K+ Views

The random module in the Python standard library provides a shuffle() function that returns a sequence with its elements randomly placed.>>> import random >>> l1=['aa',22,'ff',15,90,5.55] >>> random.shuffle(l1) >>> l1 [22, 15, 90, 5.55, 'ff', 'aa'] >>> random.shuffle(l1) >>> l1 ['aa', 'ff', 90, 22, 5.55, 15]

Why do we use random.seed() in Python?

Jayashree

Jayashree

Updated on 24-Jun-2020 06:56:39

197 Views

The seed() method of random module initializes the random number generator.random.seed(a, b)If a is omitted or None, the current system time is used. If randomness sources are provided by the operating system, they are used instead of the system timeIf a is an int, it is used directly.With version 2 (the default), ... Read More

How to extract numbers from a string using Python?

Jayashree

Jayashree

Updated on 23-Jun-2020 06:13:54

411 Views

To extract each digit from a string −>>> str1='a34e 345 bcd 5he 78 xyz' >>> for s in str1: if s.isdigit():print (s) 3 4 3 4 5 5 7 8To extract only integers from a string in which words are separated by space character −>>> str1='h3110 23 cat 444.4 ... Read More

How to print out the first character of each list in Python?

Jayashree

Jayashree

Updated on 18-Jun-2020 13:35:47

4K+ Views

Assuming that the list is collection of strings, the first character of each string is obtained as follows −>>> L1=['aaa', 'bbb', 'ccc'] >>> for string in L1: print (string[0]) a b cIf list is a collection of list objects. First element of each list is obtained as follows −>>> ... Read More

Advertisements