Friday 23 March 2018

Python Tutorial For Beginners


Python Introduction:
  • Python is a powerful high-level, object-oriented programming language created by Guido van Rossum.
  • It has simple easy-to-use syntax, making it the perfect language for someone trying to learn computer programming for the first time.
  • This is a comprehensive guide on how to get started in Python, why you should learn it and how you can learn it.
Python Programming Basics : 

Before Enter into the Python Basics lets get familiarized with the language first
Python is a general-purpose language. It has wide range of applications from Web development (like: Django and Bottle), scientific and mathematical computing (Orange, SymPy, NumPy) to desktop graphical user Interfaces (Pygame, Panda3D). The syntax of the language is clean and length of the code is relatively short. It's fun to work in Python because it allows you to think about the problem rather than focusing on the syntax. Python is a fairly old language created by Guido Van Rossum. The design began in the late 1980s and was first released in February 1991.

History of Python:

In late 1980s, Guido Van Rossum was working on the Amoeba distributed operating system group. He wanted to use an interpreted language like ABC (ABC has simple easy-to-understand syntax) that could access the Amoeba system calls. So, he decided to create a language that was extensible. This led to design of a new language which was later named Python.

Why the name Python?
Rossum was fan of a comedy series from late seventies. The name "Python" was adopted from the same series "Monty Python's Flying Circus".

Features Of Python:

  1. A simple language which is easier to learn
    Python has a very simple and elegant syntax. It's much easier to read and write Python programs compared to other languages like: C++, Java, C#. Python makes programming fun and allows you to focus on the solution rather than syntax.If you are a newbie, it's a great choice to start your journey with Python.
  2. Free and open-source
    You can freely use and distribute Python, even for commercial use. Not only can you use and distribute softwares written in it, you can even make changes to the Python's source code.
    Python has a large community constantly improving it in each iteration.
  3. Portability
    You can move Python programs from one platform to another, and run it without any changes.
    It runs seamlessly on almost all platforms including Windows, Mac OS X and Linux.
  4. Extensible and Embeddable
    Suppose an application requires high performance. You can easily combine pieces of C/C++ or other languages with Python code.
    This will give your application high performance as well as scripting capabilities which other languages may not provide out of the box.
  5. A high-level, interpreted language
    Unlike C/C++, you don't have to worry about daunting tasks like memory management, garbage collection and so on.
    Likewise, when you run Python code, it automatically converts your code to the language your computer understands. You don't need to worry about any lower-level operations.
  6. Large standard libraries to solve common tasks
    Python has a number of standard libraries which makes life of a programmer much easier since you don't have to write all the code yourself. For example: Need to connect MySQL database on a Web server? You can use MySQLdb library using import MySQLdb.
    Standard libraries in Python are well tested and used by hundreds of people. So you can be sure that it won't break your application.
  7. Object-oriented
    Everything in Python is an object. Object oriented programming (OOP) helps you solve a complex problem intuitively.
    With OOP, you are able to divide these complex problems into smaller sets by creating objects.
Installed and Run Python in Windows:
Go to Download Python page on the official site and click Download Python 3.6.0 (You may see different version name).
  • When the download is completed, double-click the file and follow the instructions to install it.
    When Python is installed, a program called IDLE is also installed along with it. It provides graphical user interface to work with Python.
  • Open IDE, copy the following code below and press enter.
    print("Hello, Vijaykumar")


  • To create a file in IDLE, go to File > New Window (Shortcut: Ctrl+N).
  • Write Python code (you can copy the code below for now) and save (Shortcut: Ctrl+S) with .py file extension like: hello.py or your-first-program.py
  • print("Hello, Vijaykumar")
  • style="list-style: none; margin: 0px 0px 20px 20px; padding: 0px 10px; position: relative;">Go to Run > Run module (Shortcut: F5) and you can see the output. Congratulations, you've successfully run your first Python program.

  • Example Programs Using Python:

    Reverse string in Python Python string library does’nt support the in-built “reverse()” as done by other python containers like list, hence knowing other methods to reverse string can prove to be useful. This article discusses several ways to achieve it. Using loop
    # Written By V.Vijaykumar
    # Python code to reverse a string
    # using loop def reverse(s):
    str = i + str
    str = "" for i in s: return str
    print ("The original string is : ",end="")
    s = "Vijaykumar" print (s)
    print (reverse(s))
    print ("The reversed string(using loops) is : ",end="")
    Output:

    The original string  is : Vijaykumar

    The reversed string(using loops) is : ramukyajiV
    Explanation : In above code, we call a function to reverse a string, which iterates to every element and intelligently join each character in the beginning so as to obtain the reversed string.

    No comments:

    Post a Comment