python基礎

  • 編程語言
  • Python特點
  • 應用領域
  • 數據類型與運算
  • 簡單使用

  • 編程語言

    • 編程語言的分類:根據運行方式(強類型與弱類型)
       編譯運行:源代碼 --> 編譯器 (編譯)--> 程序文件;
       解釋運行:源代碼 --> 運行時啓動解釋器,由解釋器邊解釋邊運行;
    • 編程模型:過程式編程語言,面向對象的編程語言
       程序=指令+數據
       過程式:以指令爲中心來組織代碼,數據是服務於代碼;

      順序執行
      選擇執行
      循環執行
      代表:C,bash

       對象式:以數據爲中心來組織代碼,圍繞數據來組織指令;

      類(class):實例化對象,method;
      代表:Java, C++, Python

    • python即是編譯器又是解釋器,嚴格區分字符大小寫、格式
  • Python特點
    簡單易學-->開發效率高-->典型工具語言-->強大豐富的模塊庫-->優秀跨平臺

  • 應用領域

    • 數據採集與處理
    • 數據計算與分析
    • 人工智能與機器學習
    • 自動化測試
    • 系統集成運維(ssh/ansible/fabric)
    • web互聯網
  • 數據類型與運算

    • java常用數據類型
      整型:int、byte、shot、long
      非整型:double、float
      boolean:true、false
      字符型:char,
    • Python數據類型

      number:數字類型 int,float,bool,fractions,complex
      string:字符串,無單獨字符,引號必須
      list:列表
      Tuple:元組
      set:集合
      dictionary:字典
      什麼樣的類型決定能夠參與的運算!

    • 運算

      +-* / % = += -= %=

    python基礎

  • 簡單使用
    '''abc''' 、 """abc""" 三引號支持換行操作(enter)
    >>> str1='''abc
    ... ef 
    ... gdg'''
    >>> str1
    'abc\nef\ngdg'
    字符也支持運算,+ 連接 *出現次數
    >>> a='abc'
    >>> b='sfw'
    >>> a+b
    'abcsfw'
    >>> a*3
    'abcabcabc'
    多行編寫內容,規範美觀或單行比較長:+\表示
    eg:total='item_one'+\
              'item_two'+\
              'item_three'
              輸出內容爲:item_oneitem_twoitem_three
#judging var type
a = 'hello world'
b = 12345
c = 1.2345
aa = type(a);bb=type(b);cc=type(c)
print('%s is %s\n%s is %s\n%s is %s' %(a,aa,b,bb,c,cc))
# print('hello world is',type('hello world'))
#input from stin 
 print('please introduce youself,what\'s u name?')
 name=input('please introduce youself,what\'s u name?')
 # print('please input your password')
 passwd=input('please input your password:')
 # print('your age:')
 age=int(input('your age:'))
 print('successful ! your name is %s,password is %s,age=%d' %(name,passwd,age))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章