Data Types of Python Programming Language

Data Types of Python Programming Language
Data Types of Python Programming Language

Data Types of Python Programming Language

    Data Types: Variables can hold values of different data types. Python is a dynamically typed language hence we need not define the type of the variable while declaring it. The interpreter implicitly binds the value with its kind.

    Python lets us check the type of variable used in the program. python provides us the type() function which returns the type of the variable passed.

    Consider the following example to define the values of different data types and check their type. data types can be used in every programming language like C Plus Plus.


    Datatype Definition in python

    A Python Data type is used in a python program. There is no need for data types to declare a variable in data types. Python pre-defined data types in python language.

    like int, float, char, etc, no need to declare in variable python automatic declared data types defined in the python program.


    Python Support 4 Types of Numeric data

    1. int (signed integer like 1,2,3,4 etc)

    2. long(long integer used for a higher range of values like 85674477L, -64754736734L, etc).

    3. float(float is used to store a floating-point number like 1.4, 1.5, 5.7, etc).

    4. Complex( complex numbers like 2.2j, 3.5+2j, etc).

    Python allows us to use a lower-case L to used with long integers. However, we must always use an upper-case l to avoid confusion.

    A complex number contains an ordered pair l.e, x+iy where x and y denote the real and imaginary parts respectively).


    Python Types of Data_Types

    1. Integer Data Types

    2. Float Data Types

    3. Complex Data Types

    4. Strings Data Type

     

    Python Integer Data Types

    Integer Data Types: A integer data type can be used without decimal numbers.

    integer data type python program runs automatically no declared Data types. it is called the integer data type in the python language.


    int a=100 /it is valid data types

    a=100/it is valid data types


    Integer Data Types in Python

    int a=100 /it is valid data types

    a=100/it is valid data types

    How To Use Integer Data Types in Python?

    int a=100

    int b=200

    print("value of a:",a)

    print("value of b:",b)

    print("Data type:",type(a))

    print("Data type:",type(b))

     

    *****OUTPUT*****

    value of a: 100

    value of b: 200

    Data types: <class 'int'>

    Data types: <class 'int'>


    Python Float Data Types

    Float Data Types: Floating point numbers are float data types in python language. it can be used floating numbers stored in the python program.

    float data combination of integer float data is called the float data type.


    Python Float Data Types

    a=30.5

    b=23.23

    c=47.43

     

    How To Use Float Data Types in Python?

    a=25.65

    b=28.45

    print("value of a:",a)

    print("value of b:",b)

    print("Data type:",type(a))

    print("Data type:",type(b))

     

    *****OUTPUT*****

    value of a: 25.65

    value of b: 28.45

    Data types: <class 'float'>

    Data types: <class 'float'>

     

    Python Complex Data Types

    Complex Data Types: A Complex data type combination of the first real part and the second imaginary part in complex data types.


    Python Complex Data Types

    5+3j

    2+5j

     

    How To Use Complex Data Types in Python?

    a=5+2j

    b=3+4j

    print("complex value of a:",a)

    print("complex value of b:",b)

    print("Data type:",type(a))

    print("Data type:",type(b))

     

    *****OUTPUT*****

    complex value of a: 5+2j

    complex value of b: 3+4j

    Data types: <class 'complex'>

    Data types: <class 'complex'>


    Python String Data Types 

    Strings Data Type: A String is a sequence of characters. The string is using single and double quotes.

    it is called string short data in the python program str.

    The string can be defined as the sequence of the characters represented in quotation marks. In python, we can use single, double, or triple quotes to define a string.

    String handling in python is a straightforward task since there are various in-built functions and operators provides.

    In the case of string handling the operator + is used to concatenate two strings as the operation "hello"+"python" returns hello python.

    The operator * is known as the repetition operator as the operations "python" *2 returns "python python".


    Python Strings Data Types

    a="Welcome to codeswithbaby"

    b="Welcome Python Language"


    How to use string Data Types

    a="Welcome to icoderweb"

    b="Welcome Python Language"

    print("String value of a:",a)

    print("String value of b:",b)

    print("Data type:",type(a))

    print("Data type:",type(b))

     

    *****OUTPUT*****

    The string value of a: Welcome to codeswithbaby

    The string value of b: Welcome Python Language

    Data types: <class 'str'>

    Data types: <class 'str'>


    Python Standard Data Types

    Data Types: A variable can hold different types of values. For Example, a person's name must be stored as a string whereas its id must be stored as an integer.

    Python provides various standard data types that define the storage method for each of them. the data types defined in python are given below.

    1. Numbers

    2. String

    3. List

    4. Tuple

    5. Dictionary

     

    Numbers: Number stores numeric values. Python creates number objects when a number is assigned to a variable.


    How To Use number Data Types in Python?

    a=100

    b=200

    print(a)

    print(b)

     

    *****OUTPUT*****

    100

    200

    Here a and b are number objects


    What is a list in python with an example?

    List: The list is similar to arrays in C. However the list can contain data of different types. The items stored in the list are separated with a comma(,) and enclosed within square brackets[].

    We can use slice[:] operators to access the data of the list the concatenation operator(+) and repetition operator(*) work with the list in the same ways as they were working with the strings.


    How to use list data type in python?

    int_list=[11,12,13,14,15 16,17,18,19]

    float_list=[4.6,2.6,3.7,8.4,6.3]

    Str_list=["java","Python","codeswithbaby","Google"]

    Mix_list=[1234,23.54,"list program"]

    print(int_list)

    print(float_list)

    print(Str_list)

    print(Mix_list)

     

    *****OUTPUT*****

    [11,12,13,14,15,16,17,18,19]

    [4.6, 2.6, 3.7, 8.4, 6.3]

    ['java', 'Python', 'codeswithbaby', 'Google']

    [1234, 23.54, 'list program']


    What are tuples and examples?

    Tuple: A tuple is similar to the list in many ways. like lists, tuples also contain the collection of items of different data types. The items of the tuple are separated with a comma(,) and enclosed in parentheses().

    A tuple is a read-only data structure as we can not modify the size and value of the items of a tuple.


    How to use tuple data type in python?

    str_tup=("Python","Java","Programming")

    int_tup=(80,77,14,78,96)

    float_tup=(4.3,8.6,7.4,5.6)

    mix_tup=("codeswithbaby",8077,35.3)

    print("String  Tuple:",str_tup)

    print("Integer Tuple:",int_tup)

    print("Floating Tuple:",float_tup)

    print("Mixed  Tuple:",mix_tup)

    print("Type:",type(str_tup))

     

    *****OUTPUT*****

    String  Tuple: ('Python', 'Java', 'Programming')

    Integer Tuple: (80, 77, 14, 78, 96)

    Floating Tuple: (4.3, 8.6, 7.4, 5.6)

    Mixed Tuple: ('codeswithbaby', 8077, 35.3)

    Type: <class 'tuple'>


    What is a dictionary data type in Python?

    Dictionary: Dictionary is an ordered set of key-value pairs of items.

    It is like an associative array hash table where each key stores a specific value. the key can hold any primitive data type whereas the value is an arbitrary python object.

    The items in the dictionary are separated with the comma and enclosed in the curly braces{}.


    How to use dictionary data type in python?

    student={

     

     "name":"codeswitthbaby",

     "rollno":807714,

     "email":"codeswithbaby@gmail.com",

     "address":"Delhi"

    }

     

    print("Student Name:",student["name"])

    print("Student Roll No:",student["rollno"])

    print("Student Email:",student["email"])

    print("Student address:",student["address"])

     

    *****OUTPUT*****

    Student Name: codeswithbaby

    Student Roll No: 807714

    Student Email: codeswithbaby@gmail.com

    Student address: Delhi


    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.