Python Basic Tutorials

Python is a high level general purpose programming language which has a clear/easy learning curve. Python programming language is massively used in various domains like Artificial Intelligence, Data Science, Web Development, Utilities Tools and Scripts and many more

Python is a Programming language, and the default Python we use is written in C programming language which is also referred to as CPython (Python implementation in C). There are various implementation of Python Programming language i.e Jython(in JAVA), Skulpt(in JS) e.t.c

To make everything easy: We refer CPython as Python

Python Datatype Conversion

Datatypes conversion means the conversion of the datatype from one type to another type. For example, if you are converting string datatype to integer datatype that's a datatype conversion.

Python has two types of type conversion:

  1. Implicit Type Conversion

    In this type of data conversion in python, python directly converts one data type to another data type. Data conversion is done automatically with the help of Implicit Type Conversion. Python converts the data from lower types to higher data types in order to prevent data loss. Data conversion is done automatically by the python interpreter.

    >>>c=a+b #data is converted implicitly from integer to float.
    >>>#Another example
       <class 'complex'>
  2. Explicit Type Conversion/Casting

    Explicit Type Conversion means conversion of datatypes with the involvement of the user. We can convert data to the required type with the help of some functions like int(), float(), str(), complex(), etc.
    Conversion syntax: cast-type(data).

       <class 'str'>
    >>>b=int(a) #cast to int
       <class 'int'>
    >>>c=float(a) #cast to float
       <class 'float'>
    >>>d=complex(a) #cast to complex
       <class 'complex'>

    Explicit type conversion is also called as type-casting in python.

    Type Casting functions and conversions
    SN Functions Conversions
    1 int() string, float to int.
    2 float() string, int to float.
    3 str() int,float,list,tuple,di-ctionary to string.
    4 complex() int,float to complex.
    5 set() string, list, tuple to set.
    6 list() string,tuple,set,dictionary to list.
    7 tuple() string,list,set to tuple.