Python‎ > ‎Built-in‎ > ‎

print()

http://www.adilwaseem.com/

Definition
The method print any thing place inside the brackets with defined way.

Syntax
print(x)

Parameters
x=string, number, variable, iterable

Examples
The pyramid returns with the if statement execution after testing equation of the values of two variable. 
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def test(request):
    x=range(1,0)
    y=13
    if y in x:
        return Response('y is in x')
    else:
        return Response('y is not in x')

def main():
    config = Configurator()
    config.add_route('index', '/')                        
    config.add_view(test, route_name='index')
    app = config.make_wsgi_app()
    return app

if __name__ == '__main__':
    app = main()
    server = make_server('0.0.0.0', 1000, app)
    print ('Starting up server on http://localhost:1000')
    server.serve_forever()





The for loop returns the headers values.
 >>> import requests
>>> r=requests.get('http://www.pythonlake.com/aboutus')
>>> for s in r.headers:
...     print(s)
... 
x-xss-protection
transfer-encoding
x-content-type-options
vary
expires
content-type
server
date
cache-control
accept-ranges
last-modified
x-robots-tag
alternate-protocol


The request request is subject to the exception of ConnectionError in finding the turtle parameters in the www.pythonlake.com homepage.
>>> import requests
 >>> try:
...     r=requests.get('http://www.pythonlake.com',params='www.pythonlake.com')
...     t=r.text
...     t.find('turtle')
... except:
...     print(e)
...     
103986
>>> 


The code return with the exception of HTTPError because URL error.
 >>> try:
...     r=requests.get('http://www.pythonlake.c/turtle',params='turtle')
...     t=r.text
...     print(t)
... except:
...     print(e)
...     
<class 'requests.exceptions.HTTPError'>


The tkinter Button generated the Random number through Random.random() method.
 >>> from tkinter import*
>>> master=Tk()
>>> def Random_number():
                import random
                random1=random.random()
                print(random1)
>>> button=Button(master, text="Generate Random Number", command=Random_number).pack()





>>> 0.3113241804334048
0.5353597978093854
0.6206780899289036
0.1329108837599009
0.09253008814720265
0.7965295953913955
0.5464788670836471
0.05573566853264078
0.5957291155959824
0.5136834489919084
0.24383631011415896
0.8615995927200537


print(computation value)
The print() can print any computation value.
 >>> print ((12-5)/3)
2.3333333333333335
>>> print (44*4+33)
209
>>> 

print(str)
The method print the string value.
 >>> 
>>> print ("hello, world")
hello, world

The method return with the value of box.
 class box:
    def __init__(self, h, w):
        self.x = h
        self.y = w
z = box(3.0, -4.5)
z.x*z.y
print(z.x*z.y)

>>> 
-13.5
>>> 


print(variable)

Printing variables require no quotes, only need comma in between variable name.
 >>> 
>>> x="Python"
>>> y="Lake"
>>> print(x, y)
Python Lake

print(execute if statement)
The method tested the variable through if statement whether it is number or not.
 x="12233"
if x.isalnum():
        print("yes, you're right")
>>> 
yes, you're right
>>>


If statement is used to print the alphabets in lower and uppercase through string.ascii_letters.
import string
search1=str(input("Type your search: "))
if search1=="alpalphabets" or "English letter" or "letters":
        print(string.ascii_letters)
>>>
Type your search: alphabets
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM
NOPQRSTUVWXYZ
>>>

print(tuple())
Return with:
 tuple=(44,22,13,22,45,555,32,33)
print(tuple)
>>> 
(44, 22, 13, 22, 45, 555, 32, 33)
>>>

print(list)
The method list the decimal value and limit the decimal point to '1.00' through quantize.
from decimal import Decimal
list1=list()
list.append((Decimal(2.10).copy_negate().quantize(Decimal('1.00')),
                                 Decimal(1.3).copy_sign(Decimal(1.3)).quantize(Decimal('1.00')),
                                    Decimal(3).exp().quantize(Decimal('1.00')))
)
print("The items in the list1 are:,", list1)

>>> 
The items in the list1 are:, [(Decimal('-2.10'), Decimal('1.30'), Decimal('20.09'))]
>>>


print(fractions())
The equal to:
from fractions import Fraction
a=Fraction(5,16)
b=Fraction(9,16)
c=a+b
print(c)

>>> 
7/8
>>>


print(range())
Here in this sample code the variable assigned the numeric ranges and and if statement is tested on these variables.
a=range(1,18)
b=range(18,40)
c=range(40,99)
print("Please enter your age")
d=input()
if d is a:
    print("You're authorized to work")
elif d is b:
    print ("You are authorized to work")
else:
    print("You can request accommodation")

>>>
Please enter your age

28
You can request accommodation
>>>

print(range())
The for loop in range() function.
 list=[1,3,4,5,43]
for i in range(1,5):
    print(i, list[i])

>>> 
1 3
2 4
3 5
4 43
>>> 


print(sum(map()))
The function returns with the sum of three tuple.
import math
x=(math.acos(1),math.asin(1),math.atan(1))
y=(math.sin(-1),math.cos(-1),math.tan(-1))
z=(math.cosh(.1),math.sinh(.1),math.tanh(.1))
print("The sum is", sum(map(lambda a,b,c: a+b+c, x,y,z)))
>>>
The sum is 1.7024569992982896
>>>

print(math function)
The equation value is determined through input().
import math
import operator
a=float(input("Please enter copysign(x) : "))
b=float(input("Please enter copysign(y) : "))

c=math.copysign(a,b).__add__(1.1).__mul__(math.acosh(2)).__truediv__(math.atan2(88,34))
print("The equation value is", c)

>>> 
Please enter copysign(x) : 2
Please enter copysign(y) : 6
The value is 3.3961966891396522
>>> 


print(math functions)
The input() value returns the math.sin(a)*2-1
import math
import operator
a=float(input("Please enter sine(value) : "))
b=math.sin(a).__mul__(2).__sub__(1)
print(b)
>>> 
Please enter sine(value) : 2.2
0.6169928076391802
>>>


print(set.difference)
The method return with the difference in the set items:

print(for statement)
Method run the loop for sets.
import math
set1={math.trunc(1.1),math.sqrt(49),math.pow(4,2),math.e,math.exp(44)}
set2={math.floor(3.12),math.fmod(3,2),math.fabs(22), math.ceil(1)}
for i in map(lambda a,b: a+b, set1, set2):
print(i)

>>> 
17.0
4
24.718281828459045
>>>


print(while loop) 
The loop returns with: 
 while True:
    try:
        print("Please enter password: ")
        x=input()
        password=int(x)
        print("Please enter correct password: ", password, "is not correct")
    except:
        print("password: " ,password, "is not correct")
        break    

>>> 
Please enter password: 
152
Please enter correct password:  152 is not correct
Please enter password: 

print(while loop)
While loop return with the value from 14 to 1.
 x = 15
while x > 0:              
   x = x -1
   if x == 10:
      continue
   print("x value is equal :", x)

>>> 
x value is equal : 14
x value is equal : 13
x value is equal : 12
x value is equal : 11
x value is equal : 9
x value is equal : 8
x value is equal : 7
x value is equal : 6
x value is equal : 5
x value is equal : 4
x value is equal : 3
x value is equal : 2
x value is equal : 1
x value is equal : 0
>>> 


if statement sum(map(lambda).__le__()
The lambda returns with equation computation.
import math
x=[math.log(2,10),math.log10(22), math.log2(2)]
y=[math.trunc(2.1)]
if sum(map(lambda a,b: a+b/2, x,y)).__le__(y):
    print("The return is large or equal to 2.0")
else:
   print ("The value does not meet the criteria")

>>> 
The return is large or equal to 2.0
>>>


The method returns with the value:
import random
x=random.Random()
if x.__ge__(2):
                    print("Random value are not acceptable")
else:
     print(x)
>>> 
Random value are not acceptable
>>>


print(string, variable(random.choice)
The method selected the item from tuple.
import random
tuple=(1,3,5,7,4,6,7)
x=random.choice(tuple)
if x.__lt__(4):
                  print("Random value is more than 4")
else:
      print("Random value is: ",x)

>>> 
Random value is: 6
>>>


print(operator.neg(random))
The return with negative random value.
import operator
import random
random1=random.random()
print(operator.neg(random1))
>>> 
-0.9279674230152819
>>> 


print((random.betavariate())+(random.gammavariate()
Return with round value of random.betavariate()+(random.gammavariate().
import random
x=round((random.betavariate(3,1))+(random.gammavariate(3,21)))
if x in range(1,9):
    print("The random value is single digit: ", x)
    y=input("Do you add to generate number one more time: y/n")
    if y=="y":
        print("Second random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
            elif y=="n":
                next
elif x in (range(10,99)):
    print("Random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
    z=input("Do you add to generate number one more time: y/n: ")
    if z=="y":
        print("Second random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
    elif z=="n":
        next
else:
print("Random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))


print(if statement return, variable)
The return is:
import operator
import random
a=float(random.randrange(1,10))
b=float(random.randint(20,40))
c=operator.pow(a,b)
if c.__le__(10):
    print("Random value: ",c+5)
elif c.__ge__(20):
    print("Random value: ",c-5)


if statement (string is decimal)
if statement test whether string object is decimal or not
 x="122cc"
if x.isdecimal():
    print("yes, you're right")
else:
    print("It is not Decimal")

>>> 
it is not Decimal
>>>


print(random.sample(a,1))
The method return with the sample random from the random methods.
import random
a=[random.weibullvariate(1,4),random.choice([1,3,5,7]),random.getrandbits(3)]
print(random.sample(a,1))

>>> 
[0.8132223906535521]
>>>


print(for loop)
The method returns with the for loop after finding the subtraction of random values.
import operator
import random
a=random.triangular(7,14)
b=random.uniform(2,5)
x=int(round(operator.sub(a,b)))
for i in range(x, 30):
    print(i)
    if i.__ge__(30):
        b=int(round(random.paretovariate(3)))
        print(i)

>>> 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
>>>

print(lambda)
The method used the math values to generate random using operator.truediv()
import operator
import random
import math

a=math.acos(.65)
b=math.asin(.45)
c=math.atan(1)

d=random.betavariate(a,b)
f=random.gauss(b,c)
g=random.gammavariate(c,a)

h=operator.truediv(d,f)
i=operator.truediv(f,g)
j=operator.truediv(g,d)

list=[h,i,j]

l=max(map(lambda x:x, list))

print(l)

>>> 
426.5194858354276
>>>


Return with perimeter of bedroom through input().
print("Python Lake will find Perimeter, please enter following information")
l=int(input("Enter length of bedroom: "))
w=int(input("Enter length of width: "))
p= 2*l+2*w
print("Perimeter of Bedroom is " ,p,)
>>> 
Python Lake will find Perimeter, please enter following information
Enter length of bedroom: 10
Enter length of width: 15
Perimeter of Bedroom is 50
>>>


print(string,decimal)
The method return decimal values in various decimal methods through input() method.
from decimal import Decimal

print("Python Decimal Methods")
a=Decimal(input("Enter Decimal Value: "))

print("Your value in Decimal().adjusted()) method is: ", Decimal(a).adjusted())

print("---------------------------------------------------------------------------------")
print("While other methods return your value as: ")
print("Your value in Decimal().as_tuple(() method is: ", Decimal(a).as_tuple())

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().canonical() method is: ", Decimal(a).canonical())

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().compare(your value-1) method is: ", Decimal(a).compare(a-1))

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().compare_signal(3)) method is: ", Decimal(a).compare_signal(3))

>>> 
Python Decimal Methods
Enter Decimal Value: 55
Your value in Decimal().adjusted()) method is: 1
---------------------------------------------------------------------------------
While other methods return your value as: 
Your value in Decimal().as_tuple(() method is: DecimalTuple(sign=0, digits=(5, 5), exponent=0)
---------------------------------------------------------------------------------
Your value in Decimal().canonical() method is: 55
---------------------------------------------------------------------------------
Your value in Decimal().compare(your value-1) method is: 1
---------------------------------------------------------------------------------
Your value in Decimal().compare_signal(3)) method is: 1
>>>


print(Decimal.__eq__())
The method test the equality tow Decimal equations.
from decimal import Decimal

x=(Decimal(1).logical_and(Decimal(1))).__sub__(Decimal(0).logical_and(Decimal(1)))
y=(Decimal(1).logical_and(Decimal(1))).__mul__(Decimal(0).logical_and(Decimal(1)))
print(x.__eq__(y))

>>> 
False
>>>


print(string, operator.xor(a,b)
The method binary bit value of a, not in b after applying the round() method to Decimal().conjugate() and Decimal().copy_abs()
import operator
from decimal import*

a=round(Decimal(33).conjugate())
b=round(Decimal(-133).copy_abs())

if operator.xor(a,b).__lt__(300):
    print(" Binary the bit set in", a, "not in" ,b, "is", operator.xor(a,b))
else:
    ValueError

>>> 
Binary the bit set in 33 not in 133 is 164
>>> 



print (string,  decimal attribute test)
The method returns with Decimal attribute test as through define function and if statement.
 from decimal import Decimal

def test (a,b,c,d,e,f,g,h,i):

    
    if a==True:
        print("The Decimal(",value1,")is canonical.")
    else:
        print("The Decimal(",value1,")is not canonical.")
        
       
    if b==True:
        print("The Decimal(",value2,")is finite.")
    else:
        print("The Decimal(",value2,")is not finite.")


    if c==True:
        print("The Decimal(",value3,")is infinite.")
    else:
        print("The Decimal(",value3,")is not infinite.")


    if d==True:
        print("The Decimal(",value4,")is nan.")
    else:
        print("The Decimal(",value4,")is not nan.")


    if e==True:
        print("The Decimal(",value5,")is normal.")
    else:
        print("The Decimal(",value5,")is not normal.")
              

    if f==True:
        print("The Decimal(",value6,")is signed.")
    else:
        print("The Decimal(",value6,")is not signed.")


    if g==True:
        print("The Decimal(",value7,")is snan.")
    else:
        print("The Decimal(",value7,")is not snan.")


    if h==True:
        print("The Decimal(",value8,")is subnormal.")
    else:
        print("The Decimal(",value8,")is not subnormal.")


    if i==True:
        print("The Decimal(",value9,")is zero.")
    else:
        print("The Decimal(",value9,")is not zero.")


value1=1.1
value2=-2.1
value3='infinity'
value4=0
value5=1.21
value6=10
value7=.50
value8=.12
value9=.21

test(value1,value2,value3, value4, value5,value6,value7, value8, value9)

>>> 
The Decimal( 1.1 )is canonical.
The Decimal( -2.1 )is finite.
The Decimal( infinity )is infinite.
The Decimal( 0 )is not nan.
The Decimal( 1.21 )is normal.
The Decimal( 10 )is not signed.
The Decimal( 0.5 )is not snan.
The Decimal( 0.12 )is not subnormal.
The Decimal( 0.21 )is not zero.
>>>


print(itertools)
The return is:
 import itertools
set={"Python", "Lake", "learning", "Center"}
y=itertools.chain(set)
for value in y: print(value)

>>> 
Python
Center
Lake
learning
>>>


print(for loop in range(decimal, int))
The method computed the int(value) of the decimal and then run loop through range() function.
from decimal import Decimal


for i in range(a,10):
    print(i)
    print(i/Decimal(1.1).log10())
        
>>>
0
0E+29
1
24.15885792809678504023429545
2
48.31771585619357008046859090
3
72.47657378429035512070288634
4
96.63543171238714016093718179
5
120.7942896404839252011714772
6
144.9531475685807102414057727
7
169.1120054966774952816400681
8
193.2708634247742803218743636
9
217.4297213528710653621086590
>>>


class....: def....: str.find()...str.count....print()
The function allow the user to find word in their text.
 class method_text_finder():
    def __init__(self, a,b):

        self.a=str(a)
        find1=a.find(b)
        print("The word found in your text at position:",find1+1)

        count1=a.count(b)
        print("The total word found in your text:",count1)

text=input("Please enter your text: ")
find_word=input("Please enter your text:")

method_text_finder(text,find_word)

>>> 
Please enter your text: Python Research Centre is located at Woodbridge Va
Please enter your text:Woodbridge
The word found in your text at position: 38
The total word found in your text: 1
>>> 


class.....: def __init__()......:....print(string, string method)
The function tested whether the string value is single word, or contain non-string values through input().
 class str_methods():
    def __init__(self, a,b,c):

        identifier=str.isidentifier(a)

        if str.isidentifier(a).__eq__(True):
            print("Full name should not contain special characters or numbers")
            
        else:
            print("Your full not name accepted")

        
      
        alpha=str.isalpha(b)
        
        if alpha.__ne__(False):
            print("Full name accepted")

            lower=str.lower(c)
            if lower.__eq__(str.lower(c)):
                 str.upper(c)
                 print("System convert your name to uppercase:", str.upper(c))
            else:
                 print("Your name accepted")

        else:
            print("Full name can't be one word")

                    

input_text=input("Please enter  your full name: ")

str_methods(input_text, input_text,input_text)
    
          

>>> 
Please enter your full name: Adil22
Full name should not contain special characters or numbers
Full name can't be one word
>>>        


print(class method)
The method return with the value of box.
 class box:
    def __init__(self, h, w):
        self.x = h
        self.y = w
z = box(3.0, -4.5)
z.x*z.y
print(z.x*z.y)

>>> 
-13.5
>>> 


class...: def...: if ...: print()
The class method return the complex values and tested the equality of the values.
 class complex_value:
    def __init__(self, a,b,c):

        self.a=complex(a).conjugate()
        self.b=complex(b).imag
        self.c=complex(c).real

        print("The complex conjugate value of a is: ",self.a)
        print("The complex imag value of b is: ",self.b)
        print("The complex  real value of c is: ",self.c)
        
        if self.a.__eq__(complex(a).conjugate()):
            print("The value of a is equal to complex(a) conjugate")
        else:
             print("The value of a is NOT equal to complex(a) conjugate")
            

        if self.b.__eq__(complex(b).imag):
            print("The value of b is equal to complex(b) imag")
        else:
            print("The value of b is NOT equal to complex(b) imag")


        if self.c.__eq__(complex(c).real):
            print("The value of c is equal to complex(c) imag")
        else:
            print("The value of c is NOT equal to complex(c) imag")

           
value1=81
value2=222
value3=33
complex_value(value1,value2, value3)

>>> 
The comlex conjugate value of a is: (81-0j)
The complex imag value of b is: 0.0
The complex real value of c is: 33.0
The value of a is equal to complex(a) conjugate
The value of b is equal to complex(b) imag
The value of c is equal to complex(c) imag
>>>


class...: def:.....:str.capitalize()
The class return after capitalizing the strings.
 class string_capitalize:
    def __init__(self,a,b):

        self.a=str.capitalize(a)
        self.b=str.capitalize(b)
        print(a, b)
        

x="python"
y="lake"

string_capitalize(x,y)



>>> 
Python Lake
>>> 

if....:print("string")
webbrowser.open_new()
 import webbrowser

x=input("Please enter your web address: ")
y=str(x)

if y.startswith("y"):
    print("Access denied")
    webbrowser.open_new(y)

>>> 
Please enter your web address: yellow.com
Access denied


tkinter.Tk()
tkinter.Label().pack()
if..:print()
else: print()
The method return with:
 from tkinter import Tk
import tkinter


a=tkinter.Label(master,text="hello").pack()

if a=="hello":
    print("Yes, tkinter.Label(master,text='hello').pack() is equal to 'hello'.")
    print("No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.")
    
master.mainloop()

>>> 
No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.
>>>


Comments