×

Html & Html5

The World's best Software Development Study Portal

Python Casting


Casting specify a types of variable.Python is the Object-Oriented languages and such as user classes to defined data types,including primitive types.
Casting in Python therefor done by Constructor functions:-



Constructing integer through string , integer and float literal


Constructs an integer number from integer literal, a float literal (by rounding down the previous whole number), or a string literal (providing the string represent a whole number)
Example:-...



x=int(5)                 # x will be 5 


y=int(3.7)               # y will be 3 





Constructing float through string or integer literal


Constructs a float number from integer literal,or a float literal or a string literal (provide the string represent a float and an integer).
Example:-...



x=float(1)                  # x will be 1 


y=float(2.2)                # y will be 2.2 


z=float(“3”)                # z wii be 3.0 


a=float(“4.5”)              # a will be 4.5 





Constructing string through string , integer and float literal


Constructs a string from a wide variety of data types,including String,Integer literals and Float literals.
Example:-...



x=str(“s1”)                #x will be “s1” 


y=str(2)                   #y will be 2 


z=str(3.0)                 #z will be 3.0 







python training insitute| Best IT Training classes in Gurgaon | python training