Server Side Programming Articles - Page 1925 of 2650

Print a number strictly less than a given number such that all its digits are distinct in C++

sudhir sharma
Updated on 27-Jan-2020 06:24:36

306 Views

In this problem, we are given a number n. Our task is to print the largest number less than n such that all its digits are distinct.Let’s take an example to understand the problemInput: n = 2332 Output: 2319To solve this problem, we reverse the count of the numbers i.e. from n to 0. And check for number with distinct digits, if the current count values satisfy the condition print it and end the loop. Otherwise continue to loop. The max number of times the loop will run is always less than n.ExampleProgram to implement our solutions,  Live Demo#include ... Read More

Loop Control Statements in Python

Mohd Mohtashim
Updated on 24-Jan-2020 12:04:27

869 Views

Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.Python supports the following control statements. Click the following links to check their detail.Let us go through the loop control statements brieflySr.NoOperator & Description1break statementTerminates the loop statement and transfers execution to the statement immediately following the loop.2continue statementCauses the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.3pass statementThe pass statement in Python is used when a statement is required syntactically but you do not want any command ... Read More

Python Membership Operators

Mohd Mohtashim
Updated on 24-Jan-2020 12:00:24

202 Views

Python’s membership operators test for membership in a sequence, such as strings, lists, or tuples. There are two membership operators as explained below −Sr.NoOperator & DescriptionExample1inEvaluates to true if it finds a variable in the specified sequence and false otherwise.x in y, here in results in a 1 if x is a member of sequence y.2not inEvaluates to true if it does not finds a variable in the specified sequence and false otherwise.x not in y, here not in results in a 1 if x is not a member of sequence y.Example Live Demo#!/usr/bin/python a = 10 b = 20 list ... Read More

Data Type Conversion in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:41:39

9K+ Views

Sometimes, you may need to perform conversions between the built-in types. To convert between types, you simply use the type name as a function.There are several built-in functions to perform conversion from one data type to another. These functions return a new object representing the converted value.Sr.No.Function & Description1int(x [, base])Converts x to an integer. base specifies the base if x is a string.2long(x [, base] )Converts x to a long integer. base specifies the base if x is a string.3float(x)Converts x to a floating-point number.4complex(real [, imag])Creates a complex number.5str(x)Converts object x to a string representation.6repr(x)Converts object x to ... Read More

Dictionary Data Type in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:32:11

14K+ Views

Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.ExampleDictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]). For example − Live Demo#!/usr/bin/python dict = {} dict['one'] = "This is one" dict[2] = "This is two" tinydict = {'name': 'john', 'code':6734, 'dept': 'sales'} print dict['one'] # Prints value for 'one' key print ... Read More

Tuple Data Type in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:31:28

967 Views

A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.ExampleThe main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists. For example − Live Demo#!/usr/bin/python tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) tinytuple = (123, 'john') print tuple # Prints ... Read More

List Data Type in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:30:34

4K+ Views

Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type.ExampleThe values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1. The plus (+) sign is the list concatenation operator, and the asterisk (*) is ... Read More

String Data Type in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:29:57

3K+ Views

Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.ExampleThe plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. For example − Live Demo#!/usr/bin/python str = 'Hello World!' print str # Prints complete string print str[0] # Prints first character of the string ... Read More

Number Data Type in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:29:29

524 Views

Number data types store numeric values. Number objects are created when you assign a value to them. For example −var1 = 1var2 = 10You can also delete the reference to a number object by using the del statement. The syntax of the del statement is −del var1[, var2[, var3[...., varN]]]]You can delete a single object or multiple objects by using the del statement. For example −del vardel var_a, var_bPython supports four different numerical types −int (signed integers)long (long integers, they can also be represented in octal and hexadecimal)float (floating point real values)complex (complex numbers)ExamplesHere are some examples of numbers −intlongfloatcomplex1051924361L0.03.14j1051924361L0.03.14j100-0x19323L15.2015.20-7860122L-21.99.322e-36j0800xDEFABCECBDAECBFBAEl32.3+e18876j-0490535633629843L-90.-.6545+0J-0x260-052318172735L-32.54e1003e+26J0x69-4721885298529L70.2-E124.53e-7jPython ... Read More

Multiple Assignments to Single Value in Python

Mohd Mohtashim
Updated on 24-Jan-2020 11:25:29

621 Views

Python allows you to assign a single value to several variables simultaneously. For example −a = b = c = 1Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example −a,b,c = 1,2,"john"Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively, and one string object with the value "john" is assigned to the variable c.

Advertisements