AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

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
x = int(22)   # x will be 22
y = int(24.8) # y will be 24
z = int("9") # z will be 9
Output:
22
24
9


Example: Floats
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:
12.0
24.8
23.0
14.2


Example: Strings
m = str("a1") # m will be a1
n = str(12)    # n will be 12
o = str(9.0)  # o will be 9.0
Output:
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
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.