Introduction to the getattr function hasattr function and getattrhasattr function in python
Hasattr (object, name)
Purpose:Determine whether the object contains the feature named name (hasattr is implemented by calling getattr (ojbect, name) to check whether an exception is thrown ).
Example:
>>> hasattr(list, 'append'
Python beginners and advanced notes: Python built-in function summary, python advanced
Built-in functionsCommon functions
1. Mathematical Correlation• Abs (x)Abs () returns the absolute value of a number. If a plural number is given, the return value is the modulo of the plural number.
Copy codeThe Code is as follows:>
of the values in the sequence is converted to a bool value and the value is false, it will be excluded from the sequence102 #Example One:103A = Filter (LambdaX:x% 2, (1,2,3,4,5,6,7,8))104 Print("Higher order function filter", List (a)) the #Example Two:106b = Filter (LambdaX:x% 2 = = 0, (1,2,3,4,5,6,7,8))107 Print("Higher order function filter", list (b))108 109 #High- order
(Reprinted) python date function, reprinted python date function
Reprinted on http://www.cnblogs.com/emanlee/p/4399147.html
All Date and Time APIs are in the datetime module.
1. format the date output datetime => string
Import datetime
Now = datetime. datetime. now ()
Now. strftime ('% Y-% m-% d % H: % M: % s ')
Output
position of the variable, forming a dictionaryDef func1 (): a = 2 b = 3 print (Globals ()) print (Locals ()) def inner (): c = 5 d = 6 Print (Globals ()) print (Locals ()) inner () func1 ()def func (): a = 3 b = 4 print (Locals ()) print (Globals ()) func () A = 1b = 2print (Globals ()) print (Locals ())5. Iterative objects and iterators (all objects in Python)The judgment of an iterative obje
the map function is in the form: Map(function, iterable, ...) Function: Functions, containing two parametersIterable: One or more sequencesfunction functions can be created by themselves, previously using the contents of the CSV file to replace, for example, ' is ' replaced by ' yes ', some Chinese replaced by a digital representation.Iterable: Generally a
anonymous functions /Anonymous functionAn anonymous function is a function that does not require a binding function name (i.e. functions, which is not bound to a name). Anonymous functions are built with lambda expressions. Often used to quickly establish a (one-time) function.Note: Lambda is an expression/keyword for Python
Original address: http://blog.csdn.net/caroline_wendy/article/details/23383995static functions (Staticmethod), class functions (Classmethod), differences in member functions (fully parsed)Defined:static function (@staticmethod): A static method that deals primarily with the logical association of this class, such as validating data;class function (@classmethod): A class method that focuses more on invoking
()print [i-I in a if aFilter (lambda x:x*x,a)Serialization:Only strings or binaries can be stored on the hard disk, so dictionaries, lists, etc. cannot be saved.Pickle is just the type of serialization used in Python.Pickle.dump (object, file handle) Pickle.load () pickle.dump (dic1,f)Json.dump () Json.load ()Regular Expressions:m = Re.match ("\d", matching object) match is matched from the beginning.View match to Character: M.group ()Re.search () Global lookup matchRe.findall () finds all matc
From C # To Python -- 3 function and function programming,
In C #, there is no independent function. Only the class (dynamic or static) method is used. It refers to the member used to execute computing or other behaviors in the class. In Python, you can use a method similar
built-in functions /built-in function or Method There are many built-in functions in Python (see the 3.6.1 section), where the built-in functions are described built-in functions ord/built-in function ord Python's built-in function, Ord, is to convert a single character in an ASCII code table to the corresponding deci
parameter of the formal parameter.Default parameter does not pass the value is the default value, the pass value overrides the default value.def func2 (y, X, z=): print (x, y, z) func2 (1, 2, 3000)def input_information (name, sex= ' man '): With open (' Information ', encoding= ' utf-8 ', mode= ' a ') as F1: f1.write (' { }\t{}\n '. Format (name,sex)) while True: msg = input (' Please enter the user's name, gender \q or Q exit '). Strip () if msg.upper () = = ' Q ': Br
Introduction to the _ init _ method function in the Python class, the Python class constructor, And the python _ init _
If there is no _ init _ method function in a class, the instance object created using the class name is empty and is not initialized. If this method
Strip function prototype
Declaration: S is a string, RM is the sequence of characters to be deleted. You can only delete characters or strings that start or end. The middle character or string cannot be deleted.
S.strip (RM) deletes the character at the beginning and end of the s string that is in the RM delete sequence
S.lstrip (RM) deletes the character at the beginning of the S string at the RM delete sequence
S.rstrip (RM) deletes the character at
This section describes how to design and pass Multiple Parameter subfunctions.
In Section 2.3, we discussed how to design a sub-function with parameters. Now we will study how to transmit the design methods of two or more parameters.
Why do functions require parameters? In fact, the reason is very simple, that is, to give more data to the sub-function for processing. It seems too stretched to pass only one
A function is a piece of code that is organized, reusable, and used to implement a single, or associated, function.Functions can improve the modularity of applications and the reuse of code. You already know that Python provides a number of built-in functions, such as print (). But you can also make your own creative functions, which are called user-defined functions.One, define a functionYou can define a
This article mainly introduces common problems such as creating, calling, and function parameters, and variable scope of Python user-defined functions. For more information, see the organized and reusable functions, code segment used to implement a single, or associated function.
Functions can improve the app's vigilance and reuse of code. You already know that
Functions are organized and reusable, and used to implement a single, or associated function code segment.Functions can improve the app's vigilance and reuse of code. You already know that Python provides many built-in functions, such as print (). But you can also create functions by yourself, which are called user-defined functions.1. Define a functionYou can define a
As an abstract way of computer code, functions play a very important role in Python. Today we introduce the definition of Python functions, the introduction of parameters, and how to invoke them. Where the function parameters are passed in in this section is the key content. The parameters of the Python
This article mainly introduces the Python function Programming Guide (2): Starting from the function, this article explains how to define a function, use function assignment, closure, as a parameter, and so on, for more information, see
2. Start with the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.