python doc_2019-2020年Python3中文教程完整版.doc
Python已經是3.1版本了,與時俱進更新教程.本文適合有Java編程經驗的程序員快速熟悉Python本文程序在windows xp+python3.1a1 測試通過.本文提到的idle指python shell,即安裝python后你在菜單看到的IDLE(python gui)在idle里ctrl+n可以打開一個新窗口,輸入源碼后ctrl+s可以保存,f5運行程序.凡打開新窗口即指ctrl+n的操作.
1 你好#打開新窗口,輸入:#! /usr/bin/python# -*- coding: utf8 -*- s1=input("Input your name:")print("你好,%s" % s1)'''知識點: * input("某字符串")函數:顯示"某字符串",并等待用戶輸入. * print()函數:如何打印. * 如何應用中文 * 如何用多行注釋''' 2 字符串和數字但有趣的是,在javascript里我們會理想當然的將字符串和數字連接,因為是動態語言嘛.但在Python里有點詭異,如下:#! /usr/bin/pythona=2b="test"c=a+b運行這行程序會出錯,提示你字符串和數字不能連接,于是只好用內置函數進行轉換#! /usr/bin/python#運行這行程序會出錯,提示你字符串和數字不能連接,于是只好用內置函數進行轉換a=2b="test"c=str(a)+bd="1111"e=a+int(d)#How to print multiply valuesprint ("c is %s,e is %i" % (c,e))'''知識點: * 用int和str函數將字符串和數字進行轉換 * 打印以#開頭,而不是習慣的// * 打印多個參數的方式 '''
3 列表#! /usr/bin/python# -*- coding: utf8 -*-#列表類似Javascript的數組,方便易用#定義元組word=['a','b','c','d','e','f','g']#如何通過索引訪問元組里的元素a=word[2]print ("a is: "+a)b=word[1:3]print ("b is: ")print (b) # index 1 and 2 elements of word.c=word[:2]print ("c is: ")print (c) # index 0 and 1 elements of word.d=word[0:]print ("d is: ")print (d) # All elements of word.#元組可以合并e=word[:2]+word[2:]print ("e is: ")print (e) # All elements of word.f=word[-1]print ("f is: ")print (f) # The last elements of word.g=word[-4:-2]print ("g is: ")print (g) # index 3 and 4 elements of word.h=word[-2:]print ("h is: ")print (h) # The last two elements.i=word[:-2]print ("i is: ")print (i) # Everything except the last two charactersl=len(word)print ("Length of word is: "+ str(l))print ("Adds new element")word.append('h')print (word)#刪除元素del word[0]print (word)del word[1:3]print (word)'''知識點: * 列表長度是動態的,可任意添加刪除元素. * 用索引可以很方便訪問元素,甚至返回一個子列表 * 更多方法請參考Python的文檔'''
4 字典#! /usr/bin/pythonx={'a':'aaa','b':'bbb','c':12}print (x['a'])print (x['b'])print (x['c'])for key in x: print ("Key is %s and value is %s" % (key,x[key])) '''知識點: * 將他當Java的Map來用即可.'''
5 字符串比起C/C++,Python處理字符串的方式實在太讓
總結
以上是生活随笔為你收集整理的python doc_2019-2020年Python3中文教程完整版.doc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DS系列服务器硬盘扇区,硬盘基本知识(磁
- 下一篇: python视窗编程_[PYTHON]