Found 27104 Articles for Server Side Programming

Why we can't use arrow operator in gets and puts?

Pythonista
Updated on 22-Jun-2020 09:11:02

102 Views

You can't read user input in an un-initialized pointer. Instead, have a variable of the struct data type and assign its address to pointer before accessing its inner elements by → operatorexample#include struct example{    char name[20]; }; main(){    struct example *ptr;    struct example e;    puts("enter name");    gets(e.name);    ptr=&e;    puts(ptr->name); }OutputTypical result of above codeenter name Disha You entered Disha

How to convert a string to a integer in C

Pythonista
Updated on 27-Jan-2020 12:41:27

450 Views

First extract characters from left bracket '(' using strchr() function.char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');Then add each character within brackets () to an char arraychar y[5]=""; int  p; for (p=1;p

How to Find HCF or GCD using Python?

Vikram Chiluka
Updated on 28-Oct-2022 11:31:48

1K+ Views

In this article, we will show you how to find the HCF (Highest Common Factor) or GCD (Greatest Common Factor) in Python. Below are the various methods to accomplish this task: Using For Loop Using Euclidean Algorithm Using While Loop Using Recursion(Naive method) Handling Negative Numbers in HCF What is H.C.F. or G.C.D? The largest positive integer that perfectly divides the two given numbers is known as the highest common factor (H.C.F.) or greatest common divisor (G.C.D.). Example - The HCF of 12 and 14, is 2. Using For Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to ... Read More

What are Ordered dictionaries in Python?

Jayashree
Updated on 02-Mar-2020 10:21:48

402 Views

An OrderedDict is a dictionary subclass that remembers the order in which its contents are added, supporting the usual dict methods.If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.>>> from collections import OrderedDict >>> d = {'banana': 3, 'apple':4, 'pear': 1, 'mango': 2} >>> od=OrderedDict(d.items()) >>> od OrderedDict([('banana', 3), ('apple', 4), ('pear', 1), ('mango', 2)]) >>> od=OrderedDict(sorted(d.items())) >>> od OrderedDict([('apple', 4), ('banana', 3), ('mango', 2), ('pear', 1)]) >>> t=od.popitem() >>> t ('pear', 1) >>> od=OrderedDict(d.items()) >>> t=od.popitem() >>> t ('mango', 2)

Where are operators mapped to magic methods in Python?

Vikram Chiluka
Updated on 09-Nov-2022 08:05:07

300 Views

In this article, we will explain to you where are operators mapped to magic methods in python. Python Magic methods are special methods that begin and end with double underscores. They are also known as dunder methods. Magic methods are not intended to be invoked directly by you, but rather invocation occurs by the class on a specific action. When you use the + operator to add two numbers, the __add__() method is called internally. Many magic methods in Python are defined by built−in classes. To get the number of magic methods inherited by a class, use the dir() function. ... Read More

What is the difference between operator and method on Python set?

Jayashree
Updated on 02-Mar-2020 10:21:19

344 Views

Python's set object represents built-in set class. Different set operations such as union, intersection, difference and symmetric difference can be performed either by calling corresponding methods or by using operators.Union by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.union(s2) {1, 2, 3, 4, 5, 6, 7, 8} >>> s2.union(s1)  {1, 2, 3, 4, 5, 6, 7, 8}Union by | operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1|s2  {1, 2, 3, 4, 5, 6, 7, 8}Intersection by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.intersection(s2) {4, 5} >>> s2.intersection(s1)  {4, 5}Intersection & operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1&s2 {4, 5} >>> s2&s1  {4, 5}Difference method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.difference(s2) {1, 2, 3} >>> s2.difference(s1)  {8, 6, 7}Difference - operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1-s2 {1, 2, 3} >>> s2-s1  {8, 6, 7}

How will you explain Python Operator Overloading?

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

143 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 or magic methods.The magic methods __lt__(), __gt__(), __eq__(), __ne__(), etc. are overridden in a class to overload == and != operators respectively.

How to perform square root without using math module in Python?

Vikram Chiluka
Updated on 28-Aug-2023 12:39:09

28K+ Views

In this article, we will show you how to perform square root without using a math module in Python. Below are the various methods to accomplish this task: Using exponential operator ** Using Mathematical Logic Using exponential operator ** Without using the math module, the simplest approach to find the square root of a number in Python is to use the built-in exponential operator ** (It is an exponent operator because it calculates the power of the first operand to the power of the second operand). Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ... Read More

How to calculate square root of a number in Python?

Vikram Chiluka
Updated on 27-Oct-2022 12:24:16

2K+ Views

In this article, we will show you how to calculate the square root of a number in Python. Below are the various methods to accomplish this task − Calculating square root using sqrt() Calculating the square root using the pow() function Calculating the square root using the exponent operator Calculating square root using the cmath module What is the square root of a number? The square root of a number is a value when multiplied by itself returns that same number. Example − 5 x 5 = 25, hence the square root of 25 is 5. However -5 ... Read More

How do you round up a float number in Python?

Vikram Chiluka
Updated on 26-Oct-2023 03:44:45

22K+ Views

In this article, we will show you how to round up a float number in Python. Round up float number using the round() function The round() function gives a floating point number with a specified number of decimals which is the rounded version of the specified number. The function will return the nearest integer because the default value for the number of decimals is 0. Syntax round(number, digits) Parameters number(required) − a number that should be rounded digits(optional) − up to the number of decimals to be rounded. 0 is the default. Python has an in-built function round() for ... Read More

Advertisements