New to Busy?

LINUXOPOLIS ~ PYTHON # 2019-10-21

1 comment

wglenz
52
23 days ago6 min read

PYTHON

Published with SteemPeak
home ~ previous

ScreenshotScreenshot by Willi Glenz

SUMMARY

01 PYTHON ............................................................. v6 19-07

03 tutorials .......................................................... v6 19-09

13 hello world ........................................................ v1 19-08
08 console ............................................................ v1 19-07
04 ide ...................[ pycharm thonny atom eclipse ].............. v4 19-09
06 keywords ........................................................... v1 19-07
11 strings ............................................................ v1 19-07
09 pep ................................................................ v1 19-07
12 module os .......................................................... v2 19-07 
10 module random ...................................................... v1 19-07

02 installation ....................................................... v4 19-10 update
14 configuration ...................................................... v2 19-10 update
07 documentation ...................................................... v3 19-07

#14

14 CONFIGURATION
[01] $ python<tab><tab>
[02] $ ls /usr/bin/python*
[03] $ ls /usr/local/bin/python*

[04] $ python --version

[05] # update-alternatives --list python
[06] # update-alternatives --install /usr/bin/python3 python /usr/local/bin/python3 1
[07] # update-alternatives --config python
[08] # update-alternatives --list python
[09] $ python --version

[10] # update-alternatives --remove python /usr/bin/python2.7
source  : linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux


13 HELLO WORLD
$ python3
>>> print('Hello world')
>>> quit()                  # <ctrl-d>

$ mkdir ~/python_projects
$ cd ~/python_projects
$ vim hello_world.py
    print('Hello world')
    :wq
$ python3 hello_world.py
sources             : python.org
interpreter         : docs.python.org/3/tutorial/interpreter.html
first-steps         : docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming


12 MODULE OS
import os


print(dir(os))
os.uname()
os.getcwd()
os.system('lsd -l')
os.system('rm Session.vim')
os.system('touch {}'.format('abc.txt'))
os.system(f'touch {"abc.txt"}')


file1 = 'abc.txt'
file2 = 'xyz.txt'
if os.path.isfile(file1):
    os.rename(file1, file2)
else:
    print('The file', file1,'does not exist')


file = input('File name: ')
if os.path.isfile(file):
    print('The file exists.')
else:
    os.system(f'touch {file}')
    print('The file was created')


file_info = os.stat('~/.bashrc')
print(type(file_info))
print(file_info)
The Python Tutorial                         : docs.python.org/3/tutorial/index.html
Miscellaneous operating system interfaces   : docs.python.org/3.7/library/os.html


11 STRINGS
msg = 'Hello, World!'
print(msg)
print(dir(msg))
print(help(str.upper))

msg = '{}, {}!'.format('Hello', 'World')
print(msg)

var_1 = 'Hello'
var_2 = 'World'
msg = f'{var_1}, {var_2}!'
print(msg)

for i in msg:
    print(i, end='')

print(msg[0])
print(msg[0:5])
print(msg[0:5:2])
print(msg[7:])
print(msg[:5])
print(msg[-1])

print(len(msg))
print(msg.lower())
print(msg.upper())
print(msg.count('l'))
print(msg.replace('l', 'x'))
Tutorial        : docs.python.org/2/tutorial/introduction.html#strings
Strings         : docs.python.org/2/library/strings.html
String-Methods  : docs.python.org/2/library/stdtypes.html#string-methods
Format Strings  : docs.python.org/2/library/string.html#formatstrings
f-Strings       : docs.python.org/3/reference/lexical_analysis.html#f-strings


10 MODULE RANDOM
import random 

counter = random.randint(1,100)
number = 1
for i in range(counter):
    print(number)
    number += 1
Source      : youtu.be/GW6DlAjZdks


09 PEP
PEP-008 Style Guide for Python Code .............. python.org/dev/peps/pep-0008/
PEP-257 Docstring Conventions .................... python.org/dev/peps/pep-0257/
Source  : python.org/dev/peps/


08 CONSOLE
$ python3
>>> help()
>>> <ctrl-d>
Documentation           : docs.python.org/3.7/contents.html
Help                    : help()


07 DOCUMENTATION
Jetbrains               : jetbrains.com
Python.org              : python.org
University of Waterloo  : uwaterloo.ca
Wingware                : wingware.com
Documentation           : docs.python.org/3.7/

#COMMENTS
    #
    """ ... """
    ''' ... '''

#PRINT
    print('Hello, World!')
    print('Hello, World! ', end='')
    print('Hello, World! ', end='\n')
    docs.python.org/3.7/library/functions.html#print

#OPERATORS
    + - * / // % **
    = += -= *= /= //= **=

#CONSTANTS
    True False None
    docs.python.org/3.7/library/constants.html

#VARIABLES
    x = 64
    print('x =', x)
    print('x = ' + str(x))
    x = 0b1000000
    print('x =', x)

#INPUT
    inp = input('Input: ')

#IF
    if x = 1:
        ...
    elif x > 1:
        ...
    else:
        ...

#FOR
    for i in [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]:
        print(i, end=' ')
    for i in range(10):
        print(i, end=', ')

#WHILE
     n = 10
     while n > 0:
        print(n)
        n -= 1

#FUNTIONS
    def fib(n):
        """ Calculate Fibonacci Numbers """
        a, b = 0, 1
        while a < n:
            print(a, end=' ')
            a, b = b, a+b
        print()
    def fib2(n):
        """ Calculate Fibonacci Numbers """
        a, b = 0, 1
        result = []
        while a < n:
            result.append(a)
            a, b = b, a+b
        return result
    docs.python.org/3.7/tutorial/controlflow.html

#STRINGS
    msg = 'Hello, World!'
    print(msg)
    print(msg[5])
    print(msg[0:5])
    print(msg[0:5:2])
    print(msg.lower())

#LISTS
    dummy_list = []
    dummy_list = ['a', 'b', 'c']
    dummy_list = [1, 'xyz', 2.0]
    print(dummy_list)
    print(dummy_list[-1])

#TUPLES
    dummy_tuple = ('abc', 'xyz', 123)
    print(dummy_tuple)
    print(dummy_tuple[-1])

#SETS
    dummy_set_0 = {1, 2, 'abc'}
    dummy_set_1 = {1, 2, 3, 4, 5}
    dummy_set_2 = {1, 7, 9, 11, 5}
    print(dummy_set_0)
    print(dummy_set_1 | dummy_set_2)
    print(dummy_set_1 & dummy_set_2)
    print(dummy_set_1 - dummy_set_2)
    print(dummy_set_1 ^ dummy_set_2)

#DICTIONARIES
    dummy_dict = {}
    dummy_dict = {1:7, 2:23, 3:18, 4:9, 99:0}
    dummy_dict[1] = 8
    del dummy_dict[99]
    dummy_dict[5] = 12
    print(dummy_dict)

Tutorial                : docs.python.org/3.7/tutorial/index.html
Documentation           : docs.python.org/3.7/contents.html
Language Reference      : docs.python.org/3.7/reference/index.html
Setup and Usage         : docs.python.org/3.7/using/index.html


06 KEYWORDS
import keyword
print(keyword.kwlist)

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Source          : docs.python.org/3.7/library/keyword.html


04 IDE
PYCHARM

 homepage               : jetbrains.com
 download               : jetbrains.com/pycharm/
 documentation          : jetbrains.com/pycharm/documentation
 quick Start            : jetbrains.com/help/pycharm/quick-start-guide.html
 snap                   # snap install pycharm-community --classic
 reference card         : resources.jetbrains.com/storage/products/pycharm/docs/PyCharm_ReferenceCard.pdf

THONNY

 homepage               : thonny.org
 installation           # apt install thonny

ATOM

 homepage               : atom.io
 documentation          : atom.io/docs
 manual                 : flight-manual.atom.io
 installation           # snap install atom

ECLIPSE

 homepage               : eclipse.org
 plugin (PyDev)         : pydev.org 
 installation Eclipse   # snap install eclipse
 installation PyDev     : Eclipse > Help > Eclipse Marketplace
wiki.python.org/moin/IntegratedDevelopmentEnvironments


03 TUTORIALS
Python 3 Tutorial (en)  : python-course.eu
Python 3 Tutorial (de)  : python-kurs.eu/python3_kurs.php

Socratica               : youtube.com/playlist?list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-
Python.org              : docs.python.org/3/tutorial/index.html
Python from Scratch     : open.cs.uwaterloo.ca/python-from-scratch/

Chuck Severance
   Videos               : youtube.com/playlist?list=PLlRFEj9H3Oj7Bp8-DfGpfAfDBiblRfl5p
   Book                 : py4e.com/book
   Free Online Course   : py4e.com

Dive Into Python 3      : file:///usr/share/doc/diveintopython3/html/index.html


02 INSTALLATION
TARBALL v3.8.0
 $ mkdir ~/tmp; cd ~/tmp;
 $ wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
 $ xz --uncompress Python-3.8.0.tar.xz
 $ tar -xf Python-3.8.0.tar
 $ rm Python-3.8.0.tar
 $ cd Python-3.8.0/
 $ view README.rst
 $ ./configure
 $ make
 $ make test
 # make install
 $ rm -r ~/tmp; ls -lisa ~

DEBIAN
 # apt install python3 idle3 spyder3 python-pip diveintopython3
 $ which python; python -V
 $ which python3; python3 -V
 $ python3
 $ python -m SimpleHTTPServer
Homepage                : python.org
Download                : python.org/downloads/release/python-384/


01 PYTHON
Homepage                : python.org
Download                : python.org/downloads/
Documentation           : docs.python.org/3.7/

CheatSheet              $ cheat.sh/python/:learn
IDE                     : PyCharm Spyder3 Wing
Version                 $ python -V && python3 -V

DIVE-INTO-PYTHON-3

# apt install diveintopython3
$ dpkg -L diveintopython3 | grep -i index
> /usr/share/doc/diveintopython3/html/index.html
> file:///usr/share/doc/diveintopython3/html/index.html

Comments

Sort byBest