Documente Academic
Documente Profesional
Documente Cultură
Range() :
The range() is a built-in function of Python which returns a range object, which is nothing but a
sequence of integers. i.e., Python range() generates the integer numbers between the given start
integer to the stop integer, which is generally used to iterate over with for loop.
Syntax:
range (start, stop[, step])
range() takes three arguments.
Out of the three 2 arguments are optional. I.e., Start and Step are the optional arguments.
1. A start argument is a starting number of the sequence. i.e., lower limit. By default, it starts
with 0 if not specified.
2. A stop argument is an upper limit. i.e.generate numbers up to this number, The range()
function doesn’t include this number in the result.
3. The step is a difference between each number in the result. The default value of the step is
1 if not specified.
Frozenset
Frozen set is just an immutable version of a Python set object. While elements of a set can be
modified at any time, elements of frozen set remains the same after creation.
mylist = ['apple', 'banana', 'cherry']
x = frozenset(mylist)
x[1] = "strawberry"
Set
add(element)
remove(el)
works like discard(), but if el is not a member of the set, a KeyError will be raised.
>>> x = {"a","b","c","d","e"}
>>> x.remove("a")
>>> x
set(['c', 'b', 'e', 'd'])
pop()
pop() removes and returns an arbitrary set element. The method raises a KeyError if
the set is empty
>>> x = {"a","b","c","d","e"}
>>> x.pop()
'a'
bool() in Python
The bool() method is used to return or convert a value to a Boolean value i.e., True or False,
using the standard truth testing procedure.
Syntax:
bool([x])
The bool() method in general takes only one parameter(here x), on which the standard truth
testing procedure can be applied. If no parameter is passed, then by default it returns
False. So, passing a parameter is optional. It can return one of the two values.
Here are few cases, in which Python’s bool() method returns false. Except these all other
values return True.