Python Casting
Python Tutorial » Python Casting
Specify a Variable Type
When you want to specify a type on a variable can be done with casting.
Casting in python is therefore done using constructor functions:
1. int()
2. float()
3. str()
Example: Integers
22
24
9
x = int(22) # x will be 22
y = int(24.8) # y will be 24
z = int("9") # z will be 9
Output: y = int(24.8) # y will be 24
z = int("9") # z will be 9
22
24
9
Example: Floats
12.0
24.8
23.0
14.2
a = float(12) # a will be 12.0
b = float(24.8) # b will be 24.8
c = float("23") # c will be 23.0
d = float("14.2") # d will be 14.2
Output: b = float(24.8) # b will be 24.8
c = float("23") # c will be 23.0
d = float("14.2") # d will be 14.2
12.0
24.8
23.0
14.2
Example: Strings
a1
12
9.0
m = str("a1") # m will be a1
n = str(12) # n will be 12
o = str(9.0) # o will be 9.0
Output: n = str(12) # n will be 12
o = str(9.0) # o will be 9.0
a1
12
9.0
casting to int, float to int, string to int, to string, class, to float, to double, exception. object, to integer
Python Casting - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.