Found 27104 Articles for Server Side Programming

Can we use continue statement in a Python if clause?

Malhar Lathkar
Updated on 26-Feb-2020 11:05:28

114 Views

Python's continue statement is a loop control statement. It causes starting next iteration of loop after abandoning current iteration. Invariably is is executed conditionally i.e. in if blockwhile expr==True:     stmt1     stmt2     if expr2==True:        continue     stmt3     stmt4However, it can't be used in an if block if it is not a part of loop. If used, interpreter will throw syntax error.

Can we use break statement in a Python if clause?

Malhar Lathkar
Updated on 26-Feb-2020 11:06:04

128 Views

Python's break keyword is used as decision control statement. It causes the remaining iterations to be abandoned and control of execution goes to next statement after the end of loop. Invariably it is executed conditionally and appears inside if block within a loop.while expr==True:     stmt1         stmt2         if expr2==True:        break     stmt3     stmt4   However it can't be used in an if block if it is not a part of loop. 

How to exit from a Python if clause?

Malhar Lathkar
Updated on 30-Jul-2019 22:30:21

473 Views

It is not possible to exit from an if block of Python code. The break keyword does appear in if block but it has to inside a loop. It is however possible to exit from entire program from inside if block by sys.exit()

What does colon ':' operator do in Python?

Malhar Lathkar
Updated on 18-Jun-2020 12:59:27

8K+ Views

The : symbol is used for more than one purpose in PythonAs slice operator with sequence −The − operator slices a part from a sequence object such as list, tuple or string. It takes two arguments. First is the index of start of slice and second is index of end of slice. Both operands are optional. If first operand is omitted, it is 0 by default. If second is omitted, it is set to end of sequence.>>> a=[1, 2, 3, 4, 5] >>> a[1:3] [2, 3] >>> a[:3] [1, 2, 3] >>> a[2:] [3, 4, 5] >>> s='computer' >>> s[:3] ... Read More

What is the purpose of the `//` operator in python?

Malhar Lathkar
Updated on 26-Feb-2020 10:55:31

261 Views

In Python, // is defined as floor division operator. It returns integer part of a floating point result of division. For example 10//3 returns 3>>> 10//3 3 >>> 125.5//2.5 50.0 >>> 12.5//1.5 8.0However in case of negative division, returned value is rounded towards negative infinity.>>> -10//3 -4 >>> -73//9 -9

What are the >> and << operators in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:59:01

139 Views

The symbols > are defined as left and right shift operators respectively in Python. They are bitwise operators. First operand is a bitwise representation of numeric object and second is the number of positions by which bit formation is desired to be shifted to left or right.The >> a=60 >>> bin(a) '0b111100' >>> b=a> b 240 >>> bin(b) '0b11110000'You can see two bits on right set to 0On the other hand >> operator shifts pattern to right. Most significant bits are set to 0>>> a=60 >>> bin(a) '0b111100' >>> b=a>>2 >>> b 15 >>> bin(a) '0b111100'

How does == operator works in Python 3?

Malhar Lathkar
Updated on 26-Feb-2020 10:58:05

109 Views

The == symbol is defined as equality operator. It returns true if expressions on either side are equal and false if they are not equal>>> (10+2) == 12 True >>> 5*5 == 5**2 True >>> (10/3)==3 False >>> 'computer'=="computer" True >>> 'COMPUTER'.lower()=='computer' True

What is right shift (>>) operator in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:37:00

10K+ Views

In Python >> is called right shift operator. It is a bitwise operator. It requires a bitwise representation of object as first operand. Bits are shifted to right by number of bits stipulated by second operand. Leading bits as towards left as a result of shifting are set to 0.>>> bin(a)     #binary equivalent 0110 0100 '0b1100100' >>> b=a>>2     #binary equivalent 0001 1101 >>> b 25 >>> bin(b) '0b11001'

What does 'not in' operator do in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:40:31

224 Views

In Python, in and not in operators are called membership operators. Their purpose is to check if an object is a member of a certain sequence object like string, list, or tuple. The not in operator returns false if object is present in sequence, true if not found>>> 'p' not in 'Tutorialspoint' False >>> 'c' not in 'Tutorialspoint' True >>> 10 not in range(0,5)

What does 'in' operator do in Python?

Malhar Lathkar
Updated on 26-Feb-2020 10:41:06

501 Views

In Python, in and not in operators are called membership operators. Their purpose is to check if an object is a member of a certain sequence object like string, list, or tuple. The in operator returns true if object is present in sequence, false if not found>>> 'p' in 'Tutorialspoint' True >>> 'c' in 'Tutorialspoint' False >>> 10 in range(0,5) False

Advertisements