Python Notes for Professionals programming,
Monday, January 13, 2020
Comment
Python Notes for Professionals programming.
About
Python is an interpreted high-level programming language for general-purpose programming.
Learn this powerful language and reap the rewards. With over 700 pages of knowledge, this can be your go-to guide for everything Python related. This resource will help you get started and learn more advanced components.
Contents
Chapter 1: Getting started with Python Language .
Section: 1.
Python 3.x
Version Release Date
3.7 2018-06-27
3.6 2016-12-23
3.5 2015-09-13
3.4 2014-03-17
3.3 2012-09-29
3.2 2011-02-20
3.1 2009-06-26
3.0 2008-12-03
Python 2.x
Version Release Date
2.7 2010-07-03
2.6 2008-10-02
2.5 2006-09-19
2.4 2004-11-30
2.3 2003-07-29
2.2 2001-12-21
2.1 2001-04-15
2.0 2000-10-16
Section 1.1: Getting Started
Python is a widely used high-level programming language for general-purpose programming, created by Guido van
Rossum and first released in 1991. Python features a dynamic type system and automatic memory management
and supports multiple programming paradigms, including object-oriented, imperative, functional programming,
and procedural styles. It has a large and comprehensive standard library.
Two major versions of Python are currently in active use:
Python 3.x is the current version and is under active development.
Python 2.x is the legacy version and will receive only security updates until 2020. No new features will be
implemented. Note that many projects still use Python 2, although migrating to Python 3 is getting easier.
You can download and install either version of Python here. See Python 3 vs. Python 2 for a comparison between
them. In addition, some third-parties offer re-packaged versions of Python that add commonly used libraries and
other features to ease setup for common use cases, such as math, data analysis or scientific use.
Verify if Python is installed
Verify if Python is installed
To confirm that Python was installed correctly, you can verify that by running the following command in your
favorite terminal (If you are using Windows OS, you need to add path of python to the environment variable before
using it in command prompt):
$ python --version
2.
Python 3.x Version ≥ 3.0
If you have Python 3 installed, and it is your default version (see Troubleshooting for more details) you should see
something like this:
$ python --version
Python 3.6.0
Python 2.x Version ≤ 2.7
If you have Python 2 installed, and it is your default version (see Troubleshooting for more details) you should see
something like this:
$ python --version
Python 2.7.13
If you have installed Python 3, but $ python --version outputs a Python 2 version, you also have Python 2
installed. This is often the case on MacOS, and many Linux distributions. Use $ python3 instead to explicitly use the
Python 3 interpreter
Hello, World in Python using IDLE
IDLE is a simple editor for Python, that comes bundled with Python.
How to create Hello, World program in IDLE
Open IDLE on your system of choice.
In older versions of Windows, it can be found at All Programs under the Windows menu.
In Windows 8+, search for IDLE or find it in the apps that are present in your system.
On Unix-based (including Mac) systems you can open it from the shell by typing $ idle
python_file.py.
It will open a shell with options along the top.
In the shell, there is a prompt of three right angle brackets:
>>>
Now write the following code in the prompt:
>>> print("Hello, World")
Hit Enter .
>>> print("Hello, World")
Hello, World
Hello World Python file
Create a new file hello.py that contains the following line:
Python 3.x Version ≥ 3.0
print('Hello, World')
Python 2.x Version ≥ 2.6
You can use the Python 3 print function in Python 2 with the following import statement:
from __future__ import print_function
Python 2 has a number of functionalities that can be optionally imported from Python 3 using the __future__
module, as discussed here.
Python 2.x Version ≤ 2.7
If using Python 2, you may also type the line below. Note that this is not valid in Python 3 and thus not
recommended because it reduces cross-version code compatibility.
print 'Hello, World'
In your terminal, navigate to the directory containing the file hello.py.
Type python hello.py, then hit the Enter key.
$ python hello.py
Hello, World
You should see Hello, World printed to the console.
You can also substitute hello.py with the path to your file. For example, if you have the file in your home directory
and your user is "user" on Linux, you can type python /home/user/hello.py.
Launch an interactive Python shell
By executing (running) the python command in your terminal, you are presented with an interactive Python shell.
This is also known as the Python Interpreter or a REPL (for 'Read Evaluate Print Loop').
$ python
Python 2.7.12 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'Hello, World'
Hello, World
>>>
Alternatively, start the interactive prompt and load file with python -i <file.py>.
In command line, run:
$ python -i hello.py
"Hello World"
>>>
There are multiple ways to close the Python shell:
>>> exit( )
or
>>> quit()
Alternatively, CTRL + D will close the shell and put you back on your terminal's command line.
Run commands as a string
Python can be passed arbitrary code as a string in the shell:
$ python -c 'print("Hello, World")'
Hello, world
This can be useful when concatenating the results of scripts together in the shell.
Shells and Beyond
Package Management - The PyPA recommended tool for installing Python packages is PIP. To install, on your
command line execute pip install . For instance, pip install numpy. (Note: On windows
you must add pip to your PATH environment variables. To avoid this, use python -m pip install )
Getting started with Python Language video
(Thanks for washing this video.)



0 Response to "Python Notes for Professionals programming,"
Post a Comment