Jayashree has Published 15 Articles

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

Jayashree

Jayashree

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

38K+ 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 do I find the largest integer less than x in Python?

Jayashree

Jayashree

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

3K+ 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 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]

Python: Cannot understand why the error - cannot concatenate 'str' and 'int' object ?

Jayashree

Jayashree

Updated on 13-Mar-2020 05:15:39

186 Views

This can be corrected by putting n+1 in brackets i.e. (n+1)for num in range(5):     print ("%d" % (num+1))Using %d casts the object following % to string. Since a string object can't be concatnated with a number (1 in this case) interpreter displays typeerror.

How to check whether a number is prime or not using Python?

Jayashree

Jayashree

Updated on 02-Mar-2020 10:06:49

833 Views

Principle used in following solution to this problem is to divide given number with all from 3 its square root, a number's square root is largest possible factor beyond which it is not necessary to check if it is divisible by any other number to decide that it is prime ... Read More

How do we check in Python whether a string contains only numbers?

Jayashree

Jayashree

Updated on 02-Mar-2020 10:00:52

254 Views

Python has an in-built function isdigit() which returns true if all characters in a string are digit (between 0-9)>>> string='9764135408' >>> string.isdigit() True >>> string='091-9764135408' >>> string.isdigit() FalseYou can also use regex expression to check if string contains digits only.>>> import re >>> bool(re.match('^[0-9]+$', '9764135408')) True >>> bool(re.match('^[0-9]+$', '091-9764135408')) FalseRead More

How to print a value for a given key for Python dictionary?

Jayashree

Jayashree

Updated on 26-Feb-2020 11:22:05

7K+ Views

Python dictionary is collection of key value pairs. Value associated with a certain key is returned by get() method.>>> D1={'a':11,'b':22,'c':33} >>> D1.get('b') 22You can also obtain value by using key inside square brackets.>>> D1['c'] 33

How does Python dictionary keys() Method work?

Jayashree

Jayashree

Updated on 25-Feb-2020 11:24:09

375 Views

The keys() method of Python dictionary class returns a view object consisting of keys used in the dictionary.>>> d1 = {'name': 'Ravi', 'age': 21, 'marks': 60, 'course': 'Computer Engg'} >>>d1.keys() dict_keys(['name', 'age', 'marks', 'course'])It can be stored as a list object. If new key-value pair is added, the view object ... Read More

How to Find Armstrong Number in an Interval using Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:58:37

798 Views

If sum of cubes of individual digits in a number add up to the number itself, it is called armstrong number. for example 153=1**3+5**3+3**3ExampleFollowing Python program find armstrong numbers between 100 to 1000for num in range(100, 1000):   temp=num   sum=0   while temp>0:       digit=temp%10     ... Read More

How to Find Factorial of Number Using Recursion in Python?

Jayashree

Jayashree

Updated on 21-Feb-2020 12:54:14

870 Views

We can write a recursive function in Python to find the factorial of a number. Recursion means that a function calls itself repeatedly to work through different stages of the same task. This technique is useful for tasks that follow a repetitive pattern or have a step-by-step structure, like calculating ... Read More

Advertisements