日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

study notes for python

發(fā)布時(shí)間:2023/12/18 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 study notes for python 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

some useful materials

Python完全新手教程

http://www.cnblogs.com/taowen/articles/11239.aspx (from taowen, BITer)

Note:

Part 1 Basic Data Structure

List, Dict(dictionary) and Turple are three main data structures in python, which are respond to set,mapping and ? in math.

List

my_list=[] my_list=[1,2] print my_list my_list.append(3) print my_list

list can be indexed: print my_list[1], which outputs 2

Dict

contact={} contact["name"]="taowen" contact["phone"]=68942443

Turple

my_turple = (1,2,3) my_list = [] for i in my_turple:my_list.append(i) print my_list

?Part 2 Basic Grammer

i = 5 n = 0 while i>0:n = n + ii = i - 1 print n

while 1:
  inputed_num = input("input a number between 1 and 10\n")
  if inputed_num >= 10:
    pass
  elif inputed_num < 1:
    pass
  else:
    break
print "hehe, don't follow, won't out"

Part 3 IO

raw_input: return your inputs as a string.

input:convert your inputs to a digital number and return it.

COFFE BREAK

# import the module to create a GUI
fromt Tkinter import *
# create a main window root = Tk()
# create a label which is located in the main window w = Label(root, text="Hello, world!")
# put the label in main window in default way w.pack()
# start a loop waiting for your input root.mainloop()

?Part 4 Exception Handling

try:print input() except:print "there is an error in your input"

Part 5 Function

def square(x):return x**2 print square(5)

def swap(a,b):
# return a turple
  return (b,a)
print swap(1,2)

Whether the paramater in function can be modifed or not depends on the type of paramater. Data types such as number or string cannot be modified in funciton, while list could be modified when used as param. So it's better to think twice before sending the complex params to function(you may need to copy it in advance).

Part 6 File Operation in Python

#input xxx = file('c:\\a.txt', 'r') xxx_content = infile.read() xxx_content = infile.readlines() for xxx_line in xxx.readlines():print "Line:", xxx_line xxx.close()#output xxx=file('c:\\test.txt','w') xxx.write("billrice") xxx.write("testtest") xxx.write("enter\n") xxx.writelines(['billrice','ricerice']) xxx.close

Note that before running the xxx.close() sentence, there is just an empy test.txt file in C disk, xxx.close() completes the save operation.

?COFFE BREAK : useful functions

eval(raw_input()) # input 1+2, output 3

Part 7 Class

class person:
   school = 'bit'def _init_(self):self.name = 'taowen'self.id = 20022479def say_id(self):print "%s's id is %d" % (self.name, self.id)me = person() me.say_id()

?

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/jorig/p/3200934.html

總結(jié)

以上是生活随笔為你收集整理的study notes for python的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。