python learning note 1

According to a THU God who knows how to answer with high vote
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
#View the current variable space
%reset -f
#Empty variable space
print "hello world"
# Write this line in
%rmdir demo_test
# Delete file set
# View history command
#Use? To view function help and function source code
a = 12
_ + 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
print s
# "" "for line breaks

Use of list

a = [1, 2.0, 'hello', 5 + 1.0]

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}


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

Use of list derivation

File operation

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

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.basasuya = d
# Here you can find that the element of Person can be added randomly
url = ''
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