Python‎ > ‎Built-in‎ > ‎

int()

http://www.adilwaseem.com/

Introduction
The numeric function int(x) will convert the string into the integer. Python can't compute the string and integer and only way available to convert them into the integer before computing these.

Syntax
int(x)

Parameters
x=number

Examples
converting string into integer.
 >>> int("134433")
134433
>>> x="1234"
>>> int(x)
1234

sum(int())
The method sum() the int() value.
 >>> x="2232"
>>> y=33232
>>>sum( int(x), y)
35464

The digital number are obtained through string.digits and converted to integer through int().
>>>import string
 >>> x=string.digits
>>> int(x)
123456789
>>>

int(round(operator.sub(a,b)))
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
>>>

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
>>>


int(Decimal)
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
>>>

int(max(set(Decimal())))
The returns are following:
from decimal import Decimal
import itertools

set1={Decimal(0.1).to_integral_value(),Decimal(1.9).to_integral_exact(),
                        Decimal(1.5000001).to_integral()Decimal(10).shift(2)}
set2={Decimal(1).scaleb(0),Decimal(1).remainder_near(2),Decimal(1.0000).normalize()}

print("The decimal values of set1 are:", set1)
print("The decimal values of set2 are: ", set2)

max_set1=int(max({Decimal(0.1).to_integral_value(),Decimal(1.9).to_integral_exact(),
Decimal(1.5000001).to_integral(), Decimal(10).shift(2)}))
print("The maximum integer value in set1 is: ",max_set1)

min_set2=int(min({Decimal(1).scaleb(0),Decimal(1).remainder_near(2),Decimal(1.0000).normalize()}))
print("The minimum integer value in set2 is:",min_set2)

set3=max_set1.__add__(min_set2)
print("The set1 added by set2 is: ", set3) 

set4=max_set1.__lt__(min_set2)
print("The max_set1 is lessor than min_set2:", set4)

x=set1.difference(set2)
rint("The set1 difference to set2 is :", x)

>>> 
The decimal values of set1 are: {Decimal('1000'), Decimal('0'), Decimal('2')}
The decimal values of set2 are: {Decimal('1')}
The maximum integer value in set1 is: 1000
The minimum integer value in set2 is: 1
The set1 added by set2 is: 1001
The max_set1 is lessor than min_set2: False
The set1 difference to set2 is : {Decimal('1000'), Decimal('0'), Decimal('2')}
>>>


int(str())
The arc is created through tkinter.Canvas().Create_arc() through user input().
from tkinter import*
import tkinter
    
master=tkinter.Tk()

def create_arc1():
    canvas=tkinter.Canvas(master, width=250, height=300)
    canvas.pack()

    x1_value=input("Please enter x1 arc value :" )
    x1=int(x1_value)

    y1_value=input("Please enter y1 arc value :" )
    y1=int(y1_value)
    
    x2_value=input("Please enter x1 arc value :" )
    x2=int(x2_value)
    
    y2_value=input("Please enter x1 arc value :" )
    y2=int(y2_value)

    canvas.create_arc(x1, y1, x2, y2)
        
button=tkinter.Button(master, text="Create Arc",command=create_arc1).pack()






>>> 
Please enter x1 arc value :50
Please enter y1 arc value :110
Please enter x1 arc value :150
Please enter x1 arc value :250
>>> 



Comments