python官方Programming FAQ
阿新 • • 發佈:2018-11-02
https://docs.python.org/3.3/faq/programming.html#programming-faq
Contents
- Programming FAQ
- General Questions
- Core Language
- Why am I getting an UnboundLocalError when the variable has a value?
- What are the rules for local and global variables in Python?
- Why do lambdas defined in a loop with different values all return the same result?
- How do I share global variables across modules?
- What are the “best practices” for using import in a module?
- How can I pass optional or keyword parameters from one function to another?
- What is the difference between arguments and parameters?
- How do I write a function with output parameters (call by reference)?
- How do you make a higher order function in Python?
- How do I copy an object in Python?
- How can I find the methods or attributes of an object?
- How can my code discover the name of an object?
- What’s up with the comma operator’s precedence?
- Is there an equivalent of C’s ”?:” ternary operator?
- Is it possible to write obfuscated one-liners in Python?
- Numbers and strings
- How do I specify hexadecimal and octal integers?
- Why does -22 // 10 return -3?
- How do I convert a string to a number?
- How do I convert a number to a string?
- How do I modify a string in place?
- How do I use strings to call functions/methods?
- Is there an equivalent to Perl’s chomp() for removing trailing newlines from strings?
- Is there a scanf() or sscanf() equivalent?
- What does ‘UnicodeDecodeError’ or ‘UnicodeEncodeError’ error mean?
- Performance
- Sequences (Tuples/Lists)
- How do I convert between tuples and lists?
- What’s a negative index?
- How do I iterate over a sequence in reverse order?
- How do you remove duplicates from a list?
- How do you make an array in Python?
- How do I create a multidimensional list?
- How do I apply a method to a sequence of objects?
- Why does a_tuple[i] += [‘item’] raise an exception when the addition works?
- Dictionaries
- Objects
- What is a class?
- What is a method?
- What is self?
- How do I check if an object is an instance of a given class or of a subclass of it?
- What is delegation?
- How do I call a method defined in a base class from a derived class that overrides it?
- How can I organize my code to make it easier to change the base class?
- How do I create static class data and static class methods?
- How can I overload constructors (or methods) in Python?
- I try to use __spam and I get an error about _SomeClassName__spam.
- My class defines __del__ but it is not called when I delete the object.
- How do I get a list of all instances of a given class?
- Why does the result of id() appear to be not unique?
- Modules