Python Data Types

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

 HTML CSS JAVASCRIPT SQL PYTHON PHP BOOTSTRAP MORE  REFERENCES  EXERCISES   

w3schools.com
y
Python For Loops
p
THE WORLD'S LARGEST WEB DEVELOPER SITE

Python Functions
Python Lambda
Python Arrays
Python Classes/Objects
Python Inheritance
Python Data Types
Python Iterators
❮ Previous Next ❯
Python Scope
Python Modules
Python Dates
Python JSON Built-in Data Types
Python RegEx
Python PIP In programming, data type is an important concept.
Python Try...Except
Variables can store data of different types, and different types can do different things.
Python Command Input
Python String Formatting Python has the following data types built-in by default, in these categories:

Text Type: str


File Handling
Python File Handling Numeric Types: int , float , complex
Python Read Files
Sequence Types: list , tuple , range
Python Write/Create Files

Mapping Type: dict

Set Types: set , frozenset

Boolean Type: bool

Binary Types: bytes , bytearray , memoryview

COLOR PICKER
Getting the Data Type
You can get the data type of any object by using the type() function:

Example HOW TO
Print the data type of the variable x:
Tabs
x = 5 Dropdowns
print(type(x)) Accordions
Side
Navigation
Run example » Top Navigation
Modal Boxes
Progress Bars
Parallax

Setting the Data Type Login Form


HTML Includes
Google Maps
In Python, the data type is set when you assign a value to a variable:
Range Sliders
Tooltips
Example Data Type Try it Slideshow
Filter List
x = "Hello World" str Try it »
Sort List
x = 20 int Try it »

x = 20.5 float Try it » SHARE


x = 1j complex Try it »
 
x = ["apple", "banana", "cherry"] list Try it »

x = ("apple", "banana", "cherry") tuple Try it »

x = range(6) range Try it » CERTIFICATES

x = {"name" : "John", "age" : 36} dict Try it » HTML


CSS
x = {"apple", "banana", "cherry"} set Try it » JavaScript
SQL
x = frozenset({"apple", "banana", "cherry"}) frozenset Try it » Python
PHP
x = True bool Try it » jQuery
Bootstrap
x = b"Hello" bytes Try it »
XML

x = bytearray(5) bytearray Try it »


Read More »
x = memoryview(bytes(5)) memoryview Try it »

Setting the Specific Data Type


If you want to specify the data type, you can use the following constructor functions:

Example Data Type Try it

x = str("Hello World") str Try it »

x = int(20) int Try it »

x = float(20.5) float Try it »

x = complex(1j) complex Try it »

x = list(("apple", "banana", "cherry")) list Try it »

x = tuple(("apple", "banana", "cherry")) tuple Try it »

x = range(6) range Try it »

x = dict(name="John", age=36) dict Try it »

x = set(("apple", "banana", "cherry")) set Try it »

x = frozenset(("apple", "banana", "cherry")) frozenset Try it »

x = bool(5) bool Try it »

x = bytes(5) bytes Try it »

x = bytearray(5) bytearray Try it »

x = memoryview(bytes(5)) memoryview Try it »

❮ Previous Next ❯

REPORT ERROR PRINT PAGE FORUM ABOUT

Top Tutorials Top References Top Examples Web Certificates


HTML Tutorial HTML Reference HTML Examples HTML Certificate
CSS Tutorial CSS Reference CSS Examples CSS Certificate
JavaScript Tutorial JavaScript Reference JavaScript Examples JavaScript Certificate
How To Tutorial SQL Reference How To Examples SQL Certificate
SQL Tutorial Python Reference SQL Examples Python Certificate
Python Tutorial W3.CSS Reference Python Examples jQuery Certificate
W3.CSS Tutorial Bootstrap Reference W3.CSS Examples PHP Certificate
Bootstrap Tutorial PHP Reference Bootstrap Examples Bootstrap Certificate
PHP Tutorial HTML Colors PHP Examples XML Certificate
jQuery Tutorial jQuery Reference jQuery Examples
Java Tutorial Angular Reference Java Examples Get Certified »
Java Reference XML Examples

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references,
and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read
and accepted our terms of use, cookie and privacy policy. Copyright 1999-2019 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

You might also like