python learning note 1

According to a THU God who knows how to answer with high vote
http://nbviewer.jupyter.org/github/lijin-THU/notes-python/tree/master/
Just sort out something I don't think I'm familiar with
For acmer or some children's shoes familiar with C + +, I think there should be some references
I think python is a future language. One day, it will replace C + +, java
To put it bluntly, it's more simplified
Just like the relationship between assembly and C

Chat1 Tools

Although I have learned a little bit of python before, I hope to learn the language more systematically this time, and lay a good foundation for the future

dict.get(key, default=None)
# dict is a dictionary type, which returns the value of the key to be found
# If not, return default
%whos
#View the current variable space
%reset -f
#Empty variable space
%%writefile hello_world.py
print "hello world"
# Write this line in hello_world.py
%rmdir demo_test
# Delete file set
%hist
# View history command
sum?
#Use? To view function help and function source code
a = 12
a
_ + 13
#_Use the output of the previous cell

Installed for the first time Anaconda Later, you can enter the following command at the command line to make Anaconda Keep up to date:

conda update conda
conda update anaconda

conda is a very powerful tool. Its specific usage can refer to its File.

You can also refer to its cheat sheet To quickly see its usage.

You can use it to install, update, and uninstall third-party python toolkits:

conda install <some package>
conda update <some package>
conda remove <some package>

Chat2 part 1 a-tour-of-python.ipynb

import numpy
del numpy
# Revocation
s = """hello
world"""
print s
# "" "for line breaks

Use of list

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

The use of set

a = {1, 2, 3, 4}
b = {2, 3, 4, 5}
a & b
a | b
a ^ b
#Symmetry difference is the unique element of two sets

Use of dictionary

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

numpy.array

a = array([1, 2, 3, 4])
a + 2
# python also has array array, which is used here

Use of list derivation

https://blog.csdn.net/yzhou86/article/details/42964299

File operation

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

Function definition

def poly(x, a, b, c):
    y = a * x ** 2 + b * x + c
    return y
x = 1
poly(array([1, 2, 3]), 1, 2, 3)
# Note here that you must use numpy's transformation

The establishment of 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.first
person.full_name()
person.basasuya = d
person.basasuya
# Here you can find that the element of Person can be added randomly
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 urllib2
ge_csv = urllib2.urlopen(url)
# web use

Tags: Python Anaconda jupyter github

Posted on Mon, 06 Apr 2020 00:47:48 -0700 by wyrd33