Home [python] Introduction to Python
Post
Cancel

[python] Introduction to Python

Intro

What is Python?

Python is a high-level programming language known for its simplicity and readability. It is widely used in various fields such as web development, data science, artificial intelligence, and more. Python is interpreted, which means that the code is executed line by line by the Python interpreter.

Syntax

Python uses indentation to define code blocks, unlike other languages that use curly braces or keywords. This makes Python code more readable and forces developers to write clean and organized code. For example, in Python, a for loop is defined by the keyword “for” followed by a colon and then an indented block of code.

Example Codes

  1. Hello World:
    1
    
    print("Hello World")
    

    This simple code snippet prints “Hello World” to the console. The print() function is used to display the text within the parentheses.

  2. Sum of two numbers:
    1
    2
    3
    4
    
    num1 = 5
    num2 = 10
    sum = num1 + num2
    print("The sum is:", sum)
    

    In this code, we declare two variables num1 and num2 with values 5 and 10 respectively. We then add them together and print the result.

  3. Finding the maximum number in a list:
    1
    2
    3
    
    numbers = [3, 7, 2, 9, 5]
    max_num = max(numbers)
    print("The maximum number in the list is:", max_num)
    

    Here, we have a list of numbers and we use the max() function to find the largest number in the list. The result is then printed to the console.

Applicable Versions

Python has two major versions currently in use: Python 2 and Python 3. Python 2 will no longer be supported after January 1, 2020, so it is recommended to use Python 3 for new projects. Python 3 has many improvements and new features compared to Python 2.

In conclusion, Python is a versatile and powerful programming language that is suitable for beginners and experienced developers alike. Its simple syntax and vast library of modules make it a popular choice for a wide range of applications. By mastering the basics of Python, you can unlock the full potential of this language and use it to create amazing projects.

This post is licensed under CC BY 4.0 by the author.
Contents