PAss

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Python Pass Statement

The null statement is another name for the pass statement.


A Comment is not ignored by the Python interpreter, whereas a pass
statement is not. Hence, they two are different Python keywords.
We can use the pass statement as a placeholder when unsure what code to
provide. So, we only have to place the pass on that line. Pass may be used
when we don't wish any code to be executed. We can simply insert a pass in
places where empty code is prohibited, such as loops, functions, class
definitions, or if-else statements.
Code:
sequence = {"Python", "Pass", "Statement", "Placeholder"}
for value in sequence:
if value == "Pass":
pass # leaving an empty if block using the pass keyword
else:
print("Not reached pass keyword: ", value)

Python String
Python string is the collection of the characters surrounded by single quotes,
double quotes, or triple quotes. The computer does not understand the
characters; internally, it stores manipulated character as the combination of
the 0's and 1's.

#Using single quotes


str1 = 'Hello Python'
print(str1)
#Using double quotes
str2 = "Hello Python"
print(str2)

#Using triple quotes


str3 = '''''Triple quotes are generally used for
represent the multiline or
docstring'''
print(str3)
Python Functions
Python functions are simple to define and essential to intermediate-level
programming. The exact criteria hold to function names as they do to
variable names. The goal is to group up certain often performed actions and
define a function. Rather than rewriting the same code block over and over
for varied input variables, we may call the function and repurpose the code
included within it with different variables.
Code:

def square( num ):


"""
This function computes the square of the number.
"""
return num**2
object_ = square(9)
print( "The square of the number is: ", object_ )

Calling a Function

A function is defined by using the def keyword and giving it a name,


specifying the arguments that must be passed to the function, and
structuring the code block.

Code:

# Defining a function
def a_function( string ):
"This prints the value of length of string"
return len(string)

# Calling the function we defined


print( "Length of the string Functions is: ", a_function( "Functions" ) )
print( "Length of the string Python is: ", a_function( "Python" ) )

Python abs() Function


The python abs() function is used to return the absolute value of a number.
It takes only one argument, a number whose absolute value is to be
returned. The argument can be an integer and floating-point number. If the
argument is a complex number, then, abs() returns its magnitude.

Code:

# integer number
integer = -20
print('Absolute value of -40 is:', abs(integer))

# floating number
floating = -20.83
print('Absolute value of -40.83 is:', abs(floating))

Python bin() Function


The python bin() function is used to return the binary representation of a
specified integer. A result always starts with the prefix 0b.
code
x = 10
y = bin(x)
print (y)

Python bool ()
The python bool() converts a value to boolean(True or False) using the
standard truth testing procedure.
Python sum () Function
As the name says, python sum () function is used to get the sum of
numbers of an iterable, i.e., list.
Code:
s = sum([1, 2,4 ])
print(s)

s = sum([1, 2, 4], 10)


print(s)

Python eval() Function

The python eval() function parses the expression passed to it and runs
python expression(code) within the program

x=8
print (eval ('x + 1'))

Python len() Function


The python len() function is used to return the length (the number of
items) of an object.
Python len() Function Example
strA = 'Python'
print(len(strA))

Python complex()
Python complex () function is used to convert numbers or string into a
complex number. This method takes two optional parameters and
returns a complex number. The first parameter is called a real and
second as imaginary parts.
Python help() Function
Python help() function is used to get help related to the object passed
during the call. It takes an optional parameter and returns help
information. If no argument is given, it shows the Python help console. It
internally calls python's help function.
# Calling function
info = help() # No argument
# Displaying result
print(info)

Python filter() Function


Python filter() function is used to get filtered elements. This function
takes two arguments, first is a function and the second is iterable. The
filter function returns a sequence from those elements of iterable for
which function returns True.
# Python filter() function example
def filterdata(x):
if x>5:
return x
# Calling function
result = filter(filterdata,(1,2,6))
# Displaying result
print(list(result))

Python sorted() Function


Python sorted() function is used to sort elements. By default, it sorts
elements in ascending order but can be sorted descending also. It takes
four arguments and returns collection in sorted order. In the case of a
dictionary, it sorts only keys, not values. The signature of the function is
given below.

sorted (iterable[, cmp[, key[, reverse]]])


# Python sorted() function example
str = "javatpoint" # declaring string
# Calling function
sorted1 = sorted(str) # sorting string
# Displaying result
print(sorted1)

You might also like