0% found this document useful (0 votes)
22 views

Python Notes - Data - Types

Uploaded by

shwsun.1206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Python Notes - Data - Types

Uploaded by

shwsun.1206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Data Types

• In programming, data type is an important concept.


• Variables can store data of different types, and different types can do
different things.
• Python has the following data types built-in by default, in these
categories
Categories Data Types
Text Type str

Numeric Types int, float, complex

Sequence Types list, tuple, range

Mapping Type dict

Set Types set, frozenset

Boolean Type bool

Binary Types bytes, bytearray, memoryview

None Type None Type


Setting the Data Type
Data Type Example

str x = "Hello World” or x = ‘Hello World'

int x = 20

float x = 20.5

complex x = 1j or x = 3 + 4j

list x = [ "apple", "banana", "cherry” ]

tuple x = ( "apple", "banana", "cherry” )

range x = range(6)

dict x = { "name" : "John", "age" : 36 }


Data Type Example

set x = { "apple", "banana", "cherry” }

frozenset x = frozenset ( { "apple", "banana", "cherry” } )

bool x = True or x = False

bytes x = b"Hello"

bytearray x = bytearray(5)

memoryview x = memoryview(bytes(5))

NoneType x = None
Setting the specific Data Type
Data Type Example

str x = str("Hello World”) or x = str(‘Hello World’)

int x = int(20)

float x = float(20.5)

complex x = complex(1j) or x = complex(3 + 4j)

list x = list (( "apple", "banana", "cherry” ))

tuple x = tuple (("apple", "banana", "cherry”))

range x = range(6)

dict x = dict{"name" : "John", "age" : 36}


Data Type Example

set x = set(( "apple", "banana", "cherry”))

frozenset x = frozenset(( "apple", "banana", "cherry”))

bool x = bool(5)

bytes x = bytes(5)

bytearray x = bytearray(5)

memoryview x = memoryview(bytes(5))

You might also like