Basics of Python

Basics of Python

Day 13 of 90daysofdevops

What is Python?

  • Python is a widely-used programming language known for its readability, versatility, and simplicity. Developed in 1991 by Guido van Rossum, it has grown to become one of the most popular programming languages worldwide.

  • Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. It is an interpreted language, which means that code is executed line-by-line at runtime instead of being compiled into machine code beforehand.

  • Python has gained popularity in recent years, particularly in the fields of data science and machine learning, DevOps due to its powerful libraries such as NumPy, Pandas, Matplotlib, and Scikit-learn.

Installation of Python

Windows

  • Follow the below blog to install Python on Windows:

Python on Windows

Linux

  • To install Python on Linux, we have to execute the below commands

      sudo apt-get update
      sudo apt-get install python3
    
  • To see which version of Python 3 you have installed

       python3 --version
    

Variable

  • In Python, a variable is a name that represents a value stored in the computer's memory. It acts as a container for holding data that can be manipulated and accessed within a program. Variables allow you to store different types of data such as numbers, strings, lists, or even more complex objects.

  • To create a variable in Python, you simply choose a name and assign a value to it using the assignment operator (=)

      message = "Hello Readers"
      # Here message is the variable name and "Hello Readers" is the value assigned to variable which is type String in python
    
  • To print output in the console we use print() function to display.

      print(message)
    

Data Types in Python

In Python, data types can be categorized as either mutable or immutable.

Mutable Data Type

  • A mutable data type is one that can be modified after it has been created. Whenever an operation is performed on a mutable object, the object itself is modified.

    Examples: Lists, Sets, Dictionaries.

  1. List: A list is an ordered sequence of some data written using square brackets([]) and commas(,) which can simultaneously hold different types of data

    Example :

     A = ["Abhi", "Ashu", 1, 2, 3]
    
  2. Set: A set is an unordered collection of unique elements that is duplicate values are not allowed.

    Example:

     set_1 = {1, 2, 3, 4}
    
  3. Dictionary: A dictionary is an unordered sequence of data of key-value pair form. It is very useful to retrieve data in an optimized way among a large amount of data.

    Example:

     dict = {1:"Abhisek",2:"Moharana", "age":24}
    

Immutable Data Type

  • An immutable data type is one whose value cannot be changed after it has been created. Whenever an operation is performed on an immutable object, a new object is created.

    Examples: integers, floats, booleans, and strings, tuples, frozen set, bytes.

  1. Numbers:

    Number stores numeric values. The integer, float, and complex values belong to a Python Numbers data type.

    Example:

     # Integer: This data type is used to represent whole numbers, both positive and negative. 
     x = 7
    
     # Float: This data type is used to represent floating-point numbers, which are numbers with a decimal point.
     y = 9.8 
    
     # Complex: This data type is used to hold the value both integer and character with a "j" as the imaginary part.
     z = 1 + 3j
    
  2. String:

    The string can be defined as the sequence of characters represented in single or double quotation marks.

    Example:

     x = "Hello Viewers"
    
  3. Tuples:

    Tuples are used to store multiple items in a single variable used to store collections of data.

    A tuple is a collection that is ordered and unchangeable.

    Example:

     company = ("TCS", "Accenture", "IBM", "Google", "Microsoft")
    
  4. Boolean:

    Booleans represent one of two values: True or False.

    Example:

     a = 10
     b = 3
     print(a > b)  # True
    

Thank You,

Abhisek Moharana