python學習筆記1

來源:互聯網
上載者:User

標籤:hub   doc   hello   筆記   close   cond   tps   anaconda   val   

根據一個知乎高票回答的THU大神學習的
http://nbviewer.jupyter.org/github/lijin-THU/notes-python/tree/master/
只整理了一些我認為不太熟悉的東西
對於acmer或者一些熟悉C++的童鞋來說應該有些參考吧,我覺得
我覺得python是一門未來語言,總有一天取代C++,java
說白了就是更加簡化
就像彙編和C的關係一樣

Chat1 Tools

雖然以前也學過一點的python,但是希望這次能夠更加系統的學習這門語言,為未來打好基礎

dict.get(key, default=None)# dict是字典類型,返回尋找key的值# 如果不存在,返回default
%whos#查看當前變數空間%reset -f#清空變數空間
%%writefile hello_world.pyprint "hello world"# 將這行字寫到hello_world.py當中去
%rmdir demo_test# 刪除檔案集%hist# 查看曆史命令
sum?#使用??查看函數協助和函數原始碼
a = 12a_ + 13#_使用上一個cell的輸出結果

第一次安裝好 Anaconda 以後,可以在命令列輸入以下命令使 Anaconda 保持最新:

conda update condaconda update anaconda

conda 是一種很強大的工具,具體用法可以參照它的文檔。

也可以參考它的 cheat sheet 來快速查看它的用法。

可以使用它來安裝,更新,卸載第三方的 python 工具包:

conda install <some package>conda update <some package>conda remove <some package>
Chat2 part 1 a-tour-of-python.ipynb
import numpydel numpy# 撤銷引入
s = """helloworld"""print s# “”“來表示換行

list的使用

a = [1, 2.0, ‘hello‘, 5 + 1.0]a.append("world")

set的使用

a = {1, 2, 3, 4}b = {2, 3, 4, 5}a & ba | ba ^ b#對稱差,也就是兩個集合所專屬的元素

dictionary的使用

d = {‘dogs‘:5, ‘cats‘:4}d["pigs"]d.keys()d.values()

numpy.array

a = array([1, 2, 3, 4])a + 2# python內建也是有array數組的,這裡使用

列表推導式的用法

42964299

檔案操作

f = open(‘data.txt‘, ‘w‘)f.write(‘1 2 3 4\n‘)f.write(‘2 3 4 5\n‘)f.close() 

函數定義

def poly(x, a, b, c):    y = a * x ** 2 + b * x + c    return yx = 1poly(array([1, 2, 3]), 1, 2, 3)# 這裡注意必須使用numpy的轉化

Class 類的建立

class Person():    def __init__(self, first, last, age):        self.first = first        self.last = last        self.age = age    def full_name(self):        return self.first + ‘ ‘ + self.last        person = Person(‘Mertle‘, ‘Sedgewick‘, 52)person.firstperson.full_name()person.basasuya = dperson.basasuya# 這裡可以發現Person的元素是可以隨機添加的
url = ‘http://ichart.finance.yahoo.com/table.csv?s=GE&d=10&e=5&f=2013&g=d&a=0&b=2&c=1962&ignore=.csv‘import urllib2ge_csv = urllib2.urlopen(url)# web使用

python學習筆記1

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.