Sunday, June 14, 2020

Python Data Types

Python Data Types

Built-in 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:

For Example: str,intfloatcomplex,listtuplerange,dict,set.

Getting the Data Type

You can get the data type of any object by using the type() function:

Example

Print the data type of the variable x:

x = 5
print(type(x))

Setting the Data Type

In Python, the data type is set when you assign a value to a variable:

ExampleData TypeTry it
x = "Hello World"strTry it »
x = 20intTry it »
x = 20.5floatTry it »
x = 1jcomplexTry it »
x = ["apple", "banana", "cherry"]listTry it »
x = ("apple", "banana", "cherry")tupleTry it »
x = range(6)rangeTry it »
x = {"name" : "John", "age" : 36}dictTry it »
x = {"apple", "banana", "cherry"}setTry it »
x = frozenset({"apple", "banana", "cherry"})frozensetTry it »
x = TrueboolTry it »
x = b"Hello"bytesTry it »
x = bytearray(5)bytearrayTry it »
x = memoryview(bytes(5))memoryview

Setting the Specific Data Type

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

ExampleData TypeTry it
x = str("Hello World")strTry it »
x = int(20)intTry it »
x = float(20.5)floatTry it »
x = complex(1j)complexTry it »
x = list(("apple", "banana", "cherry"))listTry it »
x = tuple(("apple", "banana", "cherry"))tupleTry it »
x = range(6)rangeTry it »
x = dict(name="John", age=36)dictTry it »
x = set(("apple", "banana", "cherry"))setTry it »
x = frozenset(("apple", "banana", "cherry"))frozensetTry it »
x = bool(5)boolTry it »
x = bytes(5)bytesTry it »
x = bytearray(5)bytearrayTry it »
x = memoryview(bytes(5))memoryview

Don't Forget To Comment and Like and Share it with who needs help.
 
😍😍😎😎😊😊
 
Thank You For Your Support And Love.πŸ’˜πŸ’—πŸ’πŸ’•










No comments:

Post a Comment