Giter Site home page Giter Site logo

yanny-tututu's Introduction

yanny-tututu

yanny-tututu's People

Contributors

tushao avatar

Watchers

James Cloos avatar  avatar

yanny-tututu's Issues

Python Studying(4)

Implicit Inheritance:
class Parent(object):

def implicit(self):
    print "PARENT implicit()"

class Child(Parent):
pass

dad = Parent()
son = Child()

dad.implicit()
son.implicit()
The use of pass under the class Child: is how you tell Python that you want an empty block. This creates a class named Child but says that there's nothing new to define in it.

Override Explicitly
Alter Before or After:hen you use a Python built-in function named super to get the Parent version to call

When to Use Inheritance or Composition:
Avoid multiple inheritance at all costs, as it's too complex to be reliable. If you're stuck with it, then be prepared to know the class hierarchy and spend time finding where everything is coming from.
Use composition to package code into modules that are used in many different unrelated places and situations.
Use inheritance only when there are clearly related reusable pieces of code that fit under a single common concept or if you have to because of something you're using.

chapter46,47

google python classes

type CTRL-d to exit (CTRL-z in Windows/DOS terminal)

pytho声明变量时必须赋值
“hello"+str"6"出来的效果是"hello6"

Sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,所以参数从1开始

string“HELLO”的顺序是:01234;倒过来是-5,-4,-3,-2,-1

Python Studying(1)

Python 是一门解释性语言:无需编译源码为成可执行文件,直接使用源码,运行时候逐行编译。

python2把x四舍五入为远离0的最近倍数,如round(0.5)=1, round(-0.5)=-1;
python3则会把x四舍五入为最近的偶数倍数,如round(0.5)=0, round(1.5)=2.0, round(2.5)=2.0

%d will format a number for display.
%s will insert the presentation string representation of the object (i.e. str(o))
%r will insert the canonical string representation of the object (i.e. repr(o))

print "." * 10 的输出是10个.

Python recognizes True and False as keywords representing the concept of true and false. For example,
formatter = "%r %r %r %r"
print formatter % (True, False, False, True)
的输出是:True False False True

Python中"""的用法:
print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
"""
For raw_input you can also put in a prompt to show to a person so he knows what to type. Put a string that you want for the prompt inside the () so that it looks like this:
y = raw_input("Name? ")

What's the difference between argv and raw_input()?
The different has to do with where the user is required to give input. If they give your script inputs on the command line, then you use argv. If you want them to input using the keyboard while the script is running, then use raw_input().

Python Studying(3)

Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值。
dict.get(key, default=None)

result = sentence[:]
You're using the list slice syntax [:] to effectively make a slice from the very first element to the very last one.

python super class?

Python Studying(2)

txt = open(filename)
txt.read()

truncate -- Empties the file. Watch out if you care about the file. Example:
target = open(filename, 'w')
target.truncate()

The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating the file if it already exists), and 'a' for appending

Modes 'r+', 'w+' and 'a+' open the file for updating (reading and writing); note that 'w+' truncates the file.

建立新文件或增加文件内容 格式:ECHO 文件内容>文件名
cat主要有三大功能:
1.一次显示整个文件。
$ cat filename
2.从键盘创建一个文件。
$ cat > filename
只能创建新文件,不能编辑已有文件.
3.将几个文件合并为一个文件。
$cat file1 file2 > file

def print_two(*args):
arg1, arg2 = args
print "arg1: %r, arg2: %r" % (arg1, arg2)

从raw_input()传入的变量都string类型,在%d时候需要int()来转换

file.seek(off,whence=0) 在文件中移动文件指针,冲whence(0代表文件开始,1代表当前位置,2代表文件末尾)遍历off字节

chapter20

'\t'是tab

The range() function only does numbers from the first to the last, not including the last.

设计规则:
Every if-statement must have an else.
If this else should never run because it doesn't make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors.
Never nest if-statements more than two deep and always try to do them one deep.
Treat if-statements like paragraphs, where each if-elif-else grouping is like a set of sentences. Put blank lines before and after.
Your boolean tests should be simple. If they are complex, move their calculations to variables earlier in your function and use a good name for the variable.

tips for debugging:

Do not use a "debugger." A debugger is like doing a full-body scan on a sick person. You do not get any specific useful information, and you find a whole lot of information that doesn't help and is just confusing.
The best way to debug a program is to use print to print out the values of variables at points in the program to see where they go wrong.
Make sure parts of your programs work as you work on them. Do not write massive files of code before you try to run them. Code a little, run a little, fix a little.

熟悉chapter37

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.