跳到主要內容


Python-介紹

Python

介紹

      Python是一種直譯語言(也稱解譯器),也是一種腳本語言,他有以下幾個特點:
  1. 容易寫
  2. 功能想當多
  3. 跨平台
  4. 容易擴充
      也是因為以上特點,所以可以在各個平台上看到(Windows, Linux, Mac),也可以看到在許多領域上使用,網路、商業軟體、嵌入是系統,這也說明他有龐大的模組支援。

      而在看直譯器本身會發現會有CPython,、PyPy、Jython等,但是只要在使用上大多還是使用CPython,而CPython就是使用C語言寫成的Python直譯器,想必只以知道PyPy就是用Python寫的,Jython就是用Java寫的,當然詳細要知道如何寫成的,需要去了解編譯器,而這個東西的理解,也需要演算法跟資料結構的學習。

版本

      目前學習過程中,建議使用3.7版本,除非使用的模組只有在Python2中能夠使用。
      Python的官方網站
  • Python 1.0 - 1994 
    • Python 1.2 - 1995 
    • Python 1.3 - 1995 
    • Python 1.4 - 1996 
    • Python 1.5 - 1997 
    • Python 1.6 - 2000 
  • Python 2.0 - 2000 
    • Python 2.1 - 2001 
    • Python 2.2 - 2001 
    • Python 2.3 - 2003 
    • Python 2.4 - 2004 
    • Python 2.5 - 2006 
    • Python 2.6 - 2008 
    • Python 2.7 - 2010 
  • Python 3.0 - 2008 
    • Python 3.1 - 2009 
    • Python 3.2 - 2011 
    • Python 3.3 - 2012 
    • Python 3.4 - 2014 
    • Python 3.5 - 2015 
    • Python 3.6 - 2016
    • Python3.7  - 2018 

Python的Zen


      在終端機下進入到Python之後,輸入 import this ,你可以看到Python的Zen,也就是中心思想。

圖片上的內容如下:

Python 2.7.15 (default, Jun  7 2018, 19:31:23) 

[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import this

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


第一個程式Hello World

      所有的程式語言的第一個程式,Python相當簡單,print是印出,而單引號中間是字串,也就是用print這個函數,把“Hello World”這串字串傳入,這樣就可以在螢幕上顯示Hello World了,這個範例代表輸出的概念。

print('Hello World')


第二個程式Hello, you

    注意在這個範例目的是要將鍵盤輸入存入變數中,使用了input函數,函數代入的字串會顯示在螢幕當中,讓使用者看到,讓使用者輸入自己的名字,注意這只有在Python3能夠執行,因為在Python2-input函數要在Name前後增加單引號才能夠輸入,這個例子代表輸入到輸出。


var = input('What is your Name?')
print('Hello, ' + var)

開發環境

      個人開發環境習慣是終端機,編輯器用Sublime,這部分只是因為習慣而已,還可以看建議的開發環境給大家參考開發環境要如何建置。


PyPI
www.python.org
PEP



 投影片-slideshare:Python_介紹
 影片-youtube:Python_介紹
 程式碼-Github:Python_介紹  
下一單元:Python-安裝

留言

這個網誌中的熱門文章

Python-程式優化設計-module

class Objects, values and types CPython implementation detail:  For CPython,  The standard type hierarchy User-defined functions __doc__ The function’s documentation string, or  None  if unavailable; not inherited by subclasses Writable __name__ The function’s name Writable __qualname__ The function’s  qualified name New in version 3.3. Writable __module__ The name of the module the function was defined in, or  None  if unavailable. Writable __defaults__ A tuple containing default argument values for those arguments that have defaults, or  None  if no arguments have a default value Writable __code__ The code object representing the compiled function body. Writable __globals__ A reference to the dictionary that holds the function’s global variables — the global namespace of the module in which the function was defined. Read-only __dict__ The namespace supporting arbitrary function attributes. Writable __closure__ None ...

Python-資料庫-mysql-sqlalchemy

Python 資料庫 mysql-sqlalchemy 安裝 Linux、mac : pip3 install SQLAlchemy windows     :之後補充 第一部分 from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///:memory', echo=False) Base = declarative_base() Session = sessionmaker(bind=engine) 第二部分 from test_sqlalchemy import * from sqlalchemy import Column, Integer, String class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) def __repr(self): return "<User(name={})>".format(self.name) 第三部分 from test_sqlalchemy import * from build_model import * Base.metadata.create_all(engine) user1 = User(name='user1', fullname='user1', password='user1') user2 = User(name='user2', fullname='user2...

Python-條件敘述

Python 條件敘述概念說明 參考 程式語言概念-條件敘述 條件敘述可用於對於程式某些變數的狀態進行判斷,並在該狀態執行特定工作,此種做有法助於程式結構化。 基本語法: Python的範例條件敘述如下: n = 3 if n < 0:    print('n<0') elif n == 0:    print('n==0') elif n == 2:    print('n==2') else:    print('Other') 在條件敘述加上變數單元中的比較運算,如果有兩個以上的條件可以加上邏輯運算。 if a > 0 and b > 0:    print('a>b而且b>0') 程式碼說明 n 定義變數 if    如果,後面加條件 elif  其他條件,後面加條件 else 其他,後面不加條件 在條件式結尾必續加上:,下一行必須縮排,再加上要在該條件下,要執行的動作  投影片-slideshare:Python_條件敘述  影片-youtube:Python_條件敘述  程式碼-Github:條件敘述 下一單元: Python- 迴圈