programming in python 3 - programming in python 3.x catalin boja @ie.ase.ro bogdan iancu @ie.ase.ro

Download PROGRAMMING IN PYTHON 3 - programming in python 3.x catalin boja @ie.ase.ro bogdan iancu  @ie.ase.ro

If you can't read please download the document

Post on 21-May-2020

2 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • PROGRAMMING IN PYTHON 3.X CATALIN BOJA

    CATALIN.BOJA@IE.ASE.RO

    BOGDAN IANCU

    BOGDAN.IANCU@IE.ASE.RO

    mailto:Catalin.boja@ie.ase.ro mailto:bogdan.iancu@ie.ase.ro

  • SCOPE

    • Understand the language fundamental concepts

    • Understand how to use and what’s the development cycle

    • Being able to read and understand Python source code

    • Prerequisite for starting to modify and write Python source code

    2018 © CATALIN BOJA

  • OTHER RESOURCES

     https://docs.python.org/3/library/

     https://docs.python.org/3/tutorial/

     https://www.learnpython.org/en

     https://www.tutorialspoint.com/python/

     https://automatetheboringstuff.com/

    • Paul Barry David Griffiths, Head First Programming Python, O’Reilly

    2018 © CATALIN BOJA

    https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/ https://www.learnpython.org/en https://www.tutorialspoint.com/python/ https://automatetheboringstuff.com/

  • UNDERSTANDING PYTHON

    Section I – Python fundamentals

    • basic concepts: interpreter, scripts

    • Prerequisites, using an IDE – IDLE

    • Basic Python Concepts: syntax and coding styles, data types, variables, operators, control structures, strings, some collections, functions, lambda

    expressions, exceptions, files

    2018 © CATALIN BOJA

  • UNDERSTANDING PYTHON

    Section II – Python advanced topics

    • Modules

    • Classes and objects

    • Regular expressions

    • Iterators and Generators

    • Database

    • Networking

    • UI

    • Standard Library

    • Multithreading

    2018 © CATALIN BOJA

  • PREREQUISITES

    • Almost none

    • Some knowledge about some programming languages (any)

    • To know what is a variable or a function

    • Ability to abstract problems

    • Ability to follow logic flows

    2018 © CATALIN BOJA

  • WHAT IS PYTHON?

    • an interpreted programming language

    • easy to learn, powerful high-level programming language

    • object-oriented

    • ranked 5th in TIOBE index (August 2017) - http://www.tiobe.com/tiobe-index/

    • used for rapid application development

    • created by Guido van Rossum during 1985-1990 at the National Research Institute for Mathematics and Computer Science in the Netherlands

    2018 © CATALIN BOJA

    http://www.tiobe.com/tiobe-index/

  • WHY USING PYTHON ?

    • easy to learn, to read and maintain

    • is portable and extendable

    • supports functional, structured programming methods and OOP

    • provides very high-level dynamic data types

    • supports dynamic type checking

    • supports automatic garbage collection

    • it can be integrated with C, C++ and Java

    2018 © CATALIN BOJA

  • THE TOOLS

    • Windows and Linux/Unix distributions on https://www.python.org/downloads

    • The Python interpreter, python, is in the installed folder

    • /usr/local/bin/python for Linux

    • C:\Python - the path of the Python directory (or any other path)

    • A free IDE for Linux and Unix is IDLE - https://www.python.org/downloads/

    • A editor: Notepad++, Sublime, JEdit

    2018 © CATALIN BOJA

    https://www.python.org/downloads/

  • PYTHON BASICS

    • Python Application Structure

    • Python Development Steps

    • Hello World application

    • Command line development with Python 3

    • Using an IDE - IDLE

    • \Python\Section1\Hello.py

    2018 © CATALIN BOJA

  • PYTHON FUNDAMENTALS

    Python source code - module

    .py file

    = > Interpret and execute – python.exe source.py

    Executed by CPython interpreter

    2018 © CATALIN BOJA

    CPython compiles your python code into bytecode (transparently) and

    interprets that bytecode in a evaluation loop. It is implemented in C.

    http://stackoverflow.com/questions/17130975/python-vs-cpython

    http://stackoverflow.com/questions/17130975/python-vs-cpython

  • PYTHON FUNDAMENTALS

    • Start the python interpreter with optional arguments

    • -d – provides debug output

    • -O – generates optimized bytecode (resulting in .pyo files)

    • -v - verbose output

    • C cmd - run Python script sent in as cmd string

    • file - run Python script from given file

    More available with python.exe -h

    2018 © CATALIN BOJA

  • PYTHON FUNDAMENTALS

    1. Needed software and tools

    • a simple ASCII editor (Notepad++, Sublime, JEdit, or other) for writing source files;

    • Python interpreter, python.exe for Windows to compile and run source code scripts, .py;

    • Python libraries

    2018 © CATALIN BOJA

  • INSTALLING PYTHON ON WINDOWS

    • python.exe (for Windows) is obtained by installing the Python SDK (Software Development Kit), obtained from the https://www.python.org/downloads/

    site;

    • the executable is available in your installation folder (eg. D:\PythonInstall);

    • If you use Sublime (https://www.sublimetext.com/) you can set it up with the following add-ons: https://realpython.com/blog/python/setting-up-sublime-

    text-3-for-full-stack-python-development/

    2018 © CATALIN BOJA

    https://www.python.org/downloads/ https://www.sublimetext.com/ https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/

  • INSTALLING PYTHON ON LINUX/UBUNTU

    • Python can be build by downloading the source code form https://www.python.org/downloads/release/python-352/ site;

    • For Ubuntu: $sudo apt-get install python3-minimal

    • If you use Sublime (https://www.sublimetext.com/) you can set it up with the following add-ons: https://realpython.com/blog/python/setting-up-sublime-

    text-3-for-full-stack-python-development/

    2018 © CATALIN BOJA

    https://www.python.org/downloads/release/python-352/ https://www.sublimetext.com/ https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/

  • PYTHON FUNDAMENTALS

    1. Edit the source code with your chosen editor;

    2. Open the command prompt; select Windows Start, type cmd.exe and press Enter;

    3. Check if the system knows where to find the two executables, python.exe

    4. Set environment variables (if needed)

    set PYTHONPATH=D:\PythonInstall

    set PATH=%PYTHONPATH%\bin

    set PYTHONHOME=%PYTHONPATH%\Lib;

    2018 © CATALIN BOJA

  • PYTHON FUNDAMENTALS

    5. Compile, interpret and run the source code

    d:\PythonExamples> python.exe HelloWorld.py

    6. Run the Python application

    An alternative is to use an IDE:

    • IDLE (https://www.python.org/downloads/)

    • https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

    • PyCharm from JertBrains

    2018 © CATALIN BOJA

    https://www.python.org/downloads/ https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

  • DEVELOPMENT CYCLE

    •Use the interpreter in an interactive mode

    •Write Python scripts (files with .py extension) and run them with the interpreter

    2018 © CATALIN BOJA

  • DEVELOPMENT CYCLE

    Python interactive interpreter

    Python IDLE editor

    2018 © CATALIN BOJA

  • PYTHON 3.X VS 2.X

    • 3.x introduces some significant changes

    • New features can be imported via the in-built __future__ module in Python 2

    from __future__ import division

    • https://wiki.python.org/moin/Python2orPython3

    • https://www.tutorialspoint.com/python3/python3_whatisnew.htm

    2018 © CATALIN BOJA

    https://www.tutorialspoint.com/python3/python3_whatisnew.htm https://www.tutorialspoint.com/python3/python3_whatisnew.htm

  • PYTHON FUNDAMENTALS

    • The language is developed continuously and the official documents are called Python Enhancement Proposals (PEPs) available on

    https://www.python.org/dev/peps/

    • The official documentation is available on https://www.python.org/doc/ and there are 2 major versions 2.x (2.7 being the latest) and 3.x (3.6 at this

    moment)

    2018 © CATALIN BOJA

    https://www.python.org/dev/peps/ https://www.python.org/doc/

  • PYTHON FUNDAMENTALS

    • one line comments defined by #

    • multiple lines comments – each line must be commented individually

    • the end delimiter for a instruction is Enter (CRLF);

    • commented instructions are ignored;

    • instructions can be associated in blocks of code that are defined by the same level of indentation; there is no { } like in Java or C/C++

    • Python language is case sensitive, vb as variable is different than Vb or VB

    • Imports should usually be on separate lines

    2018 © CATALIN BOJA

  • PYTHON CODING STYLE

    • “code is read much more often than it is written” (Guido van Rossum)

    • Readability is the source code quality that measures the easiness/difficulty of reading it

    • If a source is easy to read then it is easy to understand, test and

Recommended

View more >