Vous êtes sur la page 1sur 20

Home » Python Tutorials » Python Tutorial for Beginners – Introduction to Python

Python Tutorial for Beginners – Introduction to


3

Python
15 Dec, 2017  in Python Tutorials by DataFlair Team

Contents

1. Python Tutorial
2. Python Tutorial – What is Python?
3. Python History
4. Architecture
5. Components of Python
a. Functions
b. Classes
c. Modules
d. Packages
6. Features of Python
7. Frameworks available in Python
a. Django
b. Flask
c. Pyramid
d. Tornado
e. Bottle
f. web2py
g. NumPy
h. SciPy
i. Pylons
8. Flavors of Python
a. CPython
b. Jython
c. IronPython
d. Brython
e. RubyPython
f. PyPy
g. MicroPython

9. Python File Extensions
10. Why should I learn Python?
11. How is Python different from Java or C++?
12. Python Constructs
a. List
b. Tuple
c. Dictionary
d. Comments and Docstrings-
13. Conclusion: Python Tutorial

1. Python Tutorial
In this Python tutorial, we will learn about the introduction to Python programming, Python features, an
overview of Python architecture, and Python applications in real industry. We will also learn about
available python frameworks like Django, Flask, Pyramid etc.

The transition from consuming games and web apps to being the one behind them is exciting. Imagine if,
with one technology, you could create all that? The world would be at your fingertips. Well, what if we told
you that it’s possible? 1991 changed a lot of things for the programming industry and many others. We’re
talking about Python programming, a friendly general-purpose programming language. And in a world of
machine learning, Python is here to stay. So let us start with Python tutorial.

Python Tutorial

Read: Python V/s Java

2. Python Tutorial – What is Python?



Let us start this python tutorial with ‘What is Python?’

Python is an object-oriented language, which means that it can model real-world objects. It is also
dynamically-typed because it carries out type-checking at runtime. It does so to make sure that the type
of a construct matches what we expect in that context. The distinctive feature about Python is that it is
an interpreted language. The Python IDLE (Integrated DeveLopment Environment) executes instructions a
line at a time.

Etymology states that Guido van Rossum named it after the comedy group Monty Python. That is why the
metasyntactic variables used here are ‘spam’ and ‘eggs’ instead of ‘foo’ and ‘bar’. Unlike as expected, it
does not refer to the reptile species. A lot of implementations today run version 2.x, but the future
belongs to Python 3.x. It is also called ‘Python 3000’ or ‘Py3K’. CPython, written in C, is the most common
implementation of Python. It compiles a Python program into intermediate bytecode.

Apart from the constructs that Python provides, you can use the PyPI (Python Package Index). It is a
repository of third-party modules, you can install it using a program called pip. Run the following
command in Command Prompt:

pip install library_name

Python or R: To learn the difference between Python and R, please follow Python vs R. For now let is
move ahead with the current python tutorial.

Read: Comments, Indentations and Statements in Python

3. Python History
Python programming language was conceived in the late 1980s and was named for the BBC TV show
Monty Python’s Flying Circus. Guido van Rossum started python implementation at CWI in the
Netherlands in December 1989. This was a successor to the ABC (programming language) which was
capable of exception handling and interfacing with the Amoeba operating system.

On October 16, 2000, python 2.0 release was there and it had many major new features, that includes
cycle-detecting garbage collector for memory management and support for Unicode.

Next version of Python 3.0 was released on December 3, 2008.

Now we know how Python came to the picture. Now let us jump to the Python Architecture in this Python
Tutorial.

Read: Real World Applications of Python

4. Architecture
This is the architecture of a CPython Compiler/Interpreter.

a. Parser

It uses the source code to generate an abstract syntax tree.

b. Compiler 
It turns the abstract syntax tree into Python byte code.

c. Interpreter

It executes the code line by line.

In the below topic of python tutorial, we will cover the components of python programming language.

Read: Pros and Cons of Python

5. Components of Python
a. Functions
A function is a collection of statements named into one. You can use it when you want to execute all
those statements at a time. You can call it wherever you want in a program. A function may return a
value.

b. Classes
As we discussed, Python is an object-oriented language. It supports classes and objects. A class is an
abstract data type. In other words, it is a blueprint for an object of a certain kind. It holds no values.

c. Modules
A Python module is a collection of related classes and functions. We have modules for mathematical
calculations, string manipulations, web programming, and many more.

d. Packages
A package is a collection of related modules. You can either import a package or create your own.

Now let us learn about the features of Python in this python tutorial. Based on these features you will be
able to choose a programming language for your new project.

Read: Python Career Opportunities

6. Features of Python
Python is one of the richest language, in this python tutorial we will discuss several features of python:


Python Tutorial – Features of Python

a. Easy

Python is very easy to learn and understand, using this python tutorial any beginner can understand
basics of python.

b. Interpreted

It is interpreted(executed) line by line. This makes it easy to test and debug.

c. Object-Oriented

It supports classes and objects.



d. Free and Open Source
The language and its source code are available to the public for free, no need to buy a costly license.

e. Portable

You can run Python on Windows, Mac, Linux or any other platform.

f. GUI Programming

You can use it to develop a Graphical User Interface.

g. Large Library

Python provides you with a large standard library. You can use it to implement a variety of functions.

Read more about the features of Python in Detail in another of out Python tutorial on features of Python.

Now in This Python Tutorial let us see the Frameworks available in Python.

Read: Python Oprators

7. Frameworks available in Python


Python Tutorial – Python Frameworks

a. Django
This is a free and open-source framework that was written in Python and is the most common framework
for Python. It allows you to create database-driven websites. It follows the DRY Principle (Don’t Repeat
Yourself). Popular websites like Instagram, Mozilla, and Disqus make use of it.

b. Flask
Like Django, Flask is a web framework written in Python. It is a micro framework because it does not
need certain libraries and tools. It also does not have form validation or a database abstraction layer.
However, you can make use of extensions to add extra features.

c. Pyramid
Pyramid is another web framework. It is neither a mega-framework that would make decisions for you
nor a micro-framework that wouldn’t force decisions. It gives you optimal liberty on your project.

d. Tornado
Another open-source web framework, it was written in Python. It is noted for its excellent performance
and scalability.

e. Bottle
Like Flask, it is a micro-framework for Python. It is used for web development. Bottle is known for its
speed, simplicity, and light-weight. A single file can run both Python 2.5+ and 3.x

f. web2py
Written in Python, web2py is another open source web framework. It emphasizes on rapid development,
and follows an MVC architecture. MVC stands for Model View Controller.

g. NumPy
NumPy is an open-source framework for Python. It is used for scientific computing. It supports large
multidimensional arrays and matrices, and functions to operate on them.

h. SciPy
SciPy is a Python library that you can use for scientific computing. It has modules for linear algebra,
interpolation, fast Fourier transform, image processing, and many more. It uses a multidimensional array
from the NumPy module.

i. Pylons
This is a deprecated framework, which means it is no longer recommended. It is a web framework, and is
open source as well. It makes extensive use of third-party tools.

Next chapter in the Python tutorial is the different Flavors of Python.

Read: Python Variables and Data Types

8. Flavors of Python


Python Tutorial – Python Flavors types

a. CPython
This is the most widely accepted implementation of Python. It is written in the language C, and is an
interpreter.

b. Jython
Jython is a Python implementation written in Java. A Jython program can import any Java class. It
compiles to Java bytecode.

c. IronPython
IronPython is implemented in C#. It can function as an extensibility layer to application frameworks

written in a .NET language.
d. Brython
Brython stands for Browser Python. It is an implementation of Python that runs in the browser.

e. RubyPython
It acts as a bridge between the Python and Ruby interpreters. It marshals data between Python and Ruby
virtual machines.

f. PyPy
It is interesting to know that PyPy is Python implemented in Python. This makes it faster and easier to
experiment with. However, the standard implementation is CPython.

g. MicroPython
This is an implementation of Python meant to run on a microcontroller. It uses a MicroPython board that
runs MicroPython on bare metal.

Lets also see some Python File Extensions in this Python Tutorial

Read: Best Python Books

9. Python File Extensions


py -The normal extension for a Python source file
pyc- The compiled bytecode
pyd- A Windows DLL file
pyo- A file created with optimizations
pyw- Python script for Windows
pyz- Python script archive

In this python tutorial we will also try to answer some of your questions regarding python, one of which is:
Why should I learn Python.

10. Why should I learn Python?


Python is easy to pick-up, even if you come from a non-programming background. You can look at the
code and tell what’s going on. With it, you can:

Build a website
Develop a game
Perform Computer Vision (Facilities like face-detection and color-detection)
Do Machine Learning (Giving a computer the ability to learn)
Enable Robotics
Perform Web Scraping (Harvesting data from websites)
Perform Data Analysis
Automate a web browser
Perform Scripting
Perform Scientific Computing 
Build Artificial Intelligence
Install Python Now to start playing with the python programming language

Python isn’t limited to these applications. If you’ve ever used services from brands like YouTube, Dropbox,
and Netflix, then you’ve used Python. The search-engine Google also made great use of the language in
its initial stages.

When writing code in Python, you need fewer lines of code. This high-level language is also open-source
and free. It is among the major programming languages with the fastest growth. So if you plan to make a
career out of it, you’re lucky to be born in the 21st century.

To make you more clear about the python programming language we have covered how Python is
different from other programming languages like Java or C++. Lets see how python is different from Java
and C in this Python Tutorial.

11. How is Python different from Java or C++?


Python uses whitespace indentation to delimit code, so you don’t need to use curly braces for that. Also,
semicolons are optional. Both following syntax are correct:

a=7

print(a)

a = 7;

print(a)

While Java and C++ are statically-typed, Python is dynamically-typed. You also don’t need to declare the
type of a variable; you assign it:

life=42

Java is faster by a few seconds, but the difference does not invalidate Python’s advantages over it. Since
you can interpret Python, code is easier to test and debug. Next topic in this Python Tutorial is Python
Constructs.

12. Python Constructs


a. List
You can think of a list as a collection of values. Declare in the CSV (Comma-Separated Values) format.
and delimit by square brackets:

life = [‘love’, ‘wisdom’, ‘anxiety’];

arity = [1,2,3];

Notice that we do not declare the type for the list either. A list may also contain elements of different
types, and the indexing begins at 0:

person = [‘firstname’, 21];



print(person[1])
This prints 21 to the screen.

You can also slice lists; slicing is a way of retrieving values from it. We will learn more about it in further
lessons.

b. Tuple
A tuple is like a list, but it is immutable (you cannot change its values).

pizza = (‘base’, ‘sauce’, ‘cheese’, ‘mushroom’);

pizza[3] = ‘jalapeno’

This raises a TypeError.

c. Dictionary
A dictionary is a collection of key-value pairs. Declare it using curly braces, and commas to separate key-
value pairs. Also, separate values from keys using a colon (:).

student = {‘Name’: ‘Abc’, ‘Age’: 21}

print(student[‘Age’])

This prints 21 to the screen.

d. Comments and Docstrings-


Declare comments using an octothorpe (#). However, Python does not support multiline comments. Also,
docstrings are documentation strings that help explain code.

#This is a comment

“””

This is a docstring

“””

A lot of other constructs are also available. These include control structures, functions, exceptions, etc.
which will be discussed in further tutorials

This is all about the python tutorial. Lets come to the conclusion.

Read: Python Syntax and Semantics for Beginners

13. Conclusion: Python Tutorial


Finally, we saw introduction to python tutorial, what we can do with Python, and how python is different
from C++ or Java. We also looked at a few constructs in Python. Python also facilitates files, classes and
objects, and regular expressions. We will discuss those in further lessons. Hope you enjoyed the briefing.
Indeed, Python is a beautiful language, and we wish to see you create.

Do share your valuable feedback for this python tutorial.



If you like this python tutorial or found any issues, please let us know by leaving a comment below.
Reference:

https://www.python.org/

Related Posts

Python Applications – 9 Python Flask: A Web Advantages and Big Data Job Updates
Real World Applications Framework for Python Disadvantages of Python Part-21
of Python Programming Programming Language

 Leave a comment
Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Post Comment

 3 thoughts on “Python Tutorial for Beginners –
Introduction to Python”
L. Auslender Reply ↓
December 24, 2017 at 10:44 pm
thanks.

Chandresh Bhatt Reply ↓


January 12, 2018 at 11:21 am
d. Free and Open Source
The language and its source code are available to the public for free, need to buy a costly license.

It should be,
d. Free and Open Source
The language and its source code are available to the public for free, no need to buy a costly license.

thyogigeek Reply ↓
January 13, 2018 at 6:23 pm
great tutorial ,awwesome ,deep,complete knowledge

Post navigation
← Data Science Quiz Questions-Answers – Part 4 Classification in R Programming →
Python Tutorials

› Python – Introduction

› Python – Features

› Python – Pros and Cons

› Python – Applications

› Python – Career Opportunities

› Python – For Data Science

› Python 3.6 Features

› Python – Install on Windows

› Python – Syntax 
› Python – Comments, Indentations and Statements
› Python – Number Types

› Python – Variables and Data Types

› Python – Variable Scope

› Python – Strings

› Python – Operators

› Python – Bitwise Operators

› Python – Comparison Operators

› Python – Operator Overloading

› Python – Namespaces

› Python – Decision Making

› Python – Loops in Python

› Python – Functions

› Python – Function Arguments

› Python – Built-in Functions

› Python – Methods

› Python – Methods vs Functions

› Python – Range() method

› Python – Data Structures

› Python – Lists

› Python – Tuples

› Python – Tuples vs Lists

› Python – Collections Module

› Python – Counters

› Python – Namedtuples

› Python – DefaultDict

› Python – OrderedDict

› Python – Dictionaries

› Python – DateTime

› Python – Modules

› Python – Serialization

› Python – Packages 
› Python – Python OS Modules

› Python – Virtual Environment

› Python – Modules vs Packages

› Python – Sets & Booleans

› Python – List Comprehension

› Python – Date and Time

› Python – Recursion

› Python – Lambda Expression

› Python – Decorators

› Python – Generators

› Python – Iterators

› Python – Iterables

› Python – Generators vs Iterators

› Python – Closures

› Python – Classes

› Python – Object

› Python – Inheritance

› Python – Multiple Inheritance

› Python – File I/O

› Python – File Handling

› Python – Errors and Exceptions

› Python – Exception Handling

› Python – Directories

› Python – Itertool

› Python – Property

› Python – Sequences and Collections

› Python – Multithreading

› Python – Regular Expressions

› Python – Debugger

› Python – CGI Programming

› Python – Library 
› Python – Frameworks
› Python – Forensics

› Python – Network Programming

› Python – Flask

› Python – Sending Email

› Python – GUI Programming

› Python – Best Python Books

› Python – Reasons why Learn Python

› Python – Terminologies Part 1

› Python – Terminologies Part 2

› Python vs Scala

› Python vs Java

› Python vs R

Python Interview Questions

› Python – Interview Questions Part 1

› Python – Interview Questions Part 2

› Python – Interview Questions Part 3

R Tutorials

› R – Data Analytics Tutorial

› R – Data Analytics Tools

› R – Data Analytics Softwares

› R – Introduction

› R – Importance

› R – Future Scope

› R – Applications

› R – Installation

› R – Hadoop Integration

› R – Data Types

› R – RStudio

› R – Data Structures

› R – Vectors

› R – Lists
› R – Matrix

› R – Arrays

› R – Data Frame 

› R – Factor

› R – Control Statements

› R – Functions

› R – Vector Functions

› R – Numeric & Character Functions

› R – Matrix Function

› R – Recursive Functions

› R – Arguments

› R – Packages

› R – Data Reshaping

› R – Object Oriented Programming

› R – Debugging

› R – Input / Output Features

› R – String Manipulation

› R – Data Manipulation

› R – Descriptive Statistics

› R – Contingency Tables

› R – Graphical Models

› R – Generalized Linear Models(GLM)

› R – Graphical Models Applications

› R – Graphical Analysis

› R – Data Visualization

› R – Bar Chart

› R – Lattice Package

› R – Save graphs To Files

› R – Performance Tuning

› R – Hypothesis Testing

› R – Linear Regression 
› R – Nonlinear Regression
› R – Logistic Regression

› R – Decision Trees

› R – Random Forest

› R – Clustering

› R – Classification

› R – SVM Training & Testing Models

› R – Bayesian Network

› R – Bayesian Methods

› R – Bayesian Inference

› R – Bayesian Network Applications

› R – Normal Distribution

› R – Binomial & Poisson Distribution

› R – Importing Data

› R – Exporting Data

› R – Predictive & Descriptive Analytics

› R – Survival Analysis

› R – T-tests

› R – Chi-Square test

› R – List of Best Books

› R vs Python

› R vs SAS vs SPSS

data-science-quiz-widgets
R Quiz

› Data Science Quiz – Part 1

› Data Science Quiz – Part 2

› R Quiz – Part 1

› R Quiz – Part 2

Search

Search

Training in Cities: Bangalore | Chennai | Hyderabad | Delhi | NCR | Mumbai | Pune | Kolkata | Chicago | San
Francisco | Los Angeles | New York | Boston | London

   
· © 2018 DataFlair · Designed by Press Customizr · Powered by  ·

Vous aimerez peut-être aussi