Introduction

Setup

Operators

variable

String

Number

Dtype & Comment

Lists

Tuples

Sets

Dictionaries

if else statement

For Loop

While Loop

iterator & iterable

Pre-Built functions

Function

Decorators

generators

Types of errors

Exceptions Handling

OOP

Regular expression

Create module

OS module

Date module

Random module

Math

Statistics module

Exercise 1

Exercise 2

Exercise 3

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Python data type and comment

What is Data type in python?

In short, data type is mentioned as data type. Data type means what kind of data we are working with. It defines the form of the data. If we write a word then its data type is a string or if we write a number then its data type can be integer or float or complex. In Python, the data type is always set but you can change it. Look data type is a very important thing in coding. You must have a clear knowledge about the data type. Because if you are not using required data type for your code then it can give you error or wrong output. So while coding careful about data type.

Suppose you want to do addition of two numbers. To do that you are taking two numbers as input from user in the form of string. Now if you want to do addition then you must change the data type of the given inputs from string or text to number like integer or float. If you don't do this then you will not be able to do addition. Because without changing the data types those inputs will be treated as string or text and we know that we can't to subtraction, summation, multiplication, division or we can say any type of mathematical calculation on text.

So you must use correct data type in coding otherwise it will not work or will give you an error.

Classification of Data types

There are total 6 types of data type present in python.
So the data types are:

  • Text Type: str
  • Numeric Types: int, float, complex
  • Sequence Types: list, tuple, range
  • Binary Types: bytes, bytearray, memoryview
  • Boolean Type: bool,True ,False
  • Set Types: set, frozenset
  • Mapping Type: dict
  • Example:1
    Input
    x="SelfTaught"
    print(type(x))
    Output
    <class "Str">

    In the example 1 we have a text in x variable. Now if we check the data type then we will see it is str means string.

    Example:2
    Input
    x=4
    print(type(x))
    Output
    <class "int">

    In the example 2 we have a number in x variable. Now if we check the data type then we will see it is int means integer.

    Example:3
    Input
    x=2.50
    print(type(x))
    Output
    <class "float">

    In the example 3 we have a number in x variable. Now if we check the data type then we will see it is float.

    Example:4
    Input
    x = ["apple", "banana", "cherry"]
    print(type(x))
    Output
    <class 'list'>

    In the example 4 we have a list in x variable. We will learn about list in upcoming lectures. Now just think that it is data structure where you can store multiple values at a time. Now if we check the data type then we will see it is list.

    Example:5
    Input
    x = ("apple", "banana", "cherry")
    print(type(x))
    Output
    <class 'tuple'>

    In the example 4 we have a tuple in x variable. We will learn about tuple in upcoming lectures. Now just think that it is data structure where you can store multiple values at a time. Now if we check the data type then we will see it is tuple.

    Example:6
    Input
    x =True
    print(type(x))
    Output
    <class 'bool'>
    Example:7
    Input
    x = 1j
    print(type(x))
    Output
    <class 'complex'>
    Example:8
    Input
    x = {"name" : "Rafsun", "age" : 21}
    print(type(x))
    Output
    <class 'dict'>

    In the example 8 we have a dictionary in x variable. We will learn about dictionary in upcoming lectures. Now just think that it is data structure where you can store multiple values at a time in form of key and value pair. Now if we check the data type then we will see it is tuple.

    How to comment in python?

    When we write a lot of lines of code, sometimes we forget that why we wrote this line of code. To solve this problem we write a short note or comment beside or under the code and it's called a comment. It doesn't effect the code. It's just a short note.

    In python we write comment by giving hash(#) or three double or single quotation(""",''').
    When to use #?
    If you want write a comment which is a single-line or for single line comment use hash(#).
    When to use (""",''')? If you want write a comment which is contain multiple lines or for multiple-line comments, double or single quotations are used.

    Let's see some coding example for better understanding.

    Example 1:
    Input
    x="SelfTaught"
    print(x)
    #I write this code to print this website name

    Here we use comment that why I wrote this code and this is a single line comment so I use hash. This comment will not effect the code.

    Example 2:
    Input
    x="SelfTaught again"
    print(x)
    """
    I write this code
    to print this website
    name
    """

    Here we use comment that why I wrote this code and this is a multiple line comment so I use double quotation. You can also use single quotation. This comment will not effect the code.

    CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

    © Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.