empty.When not empty, you can write a module import statement under a package in a file, because the __init__.py file is imported when the module is actually imported.3. Import Module Statement formatImport Module NameFrom Package name Import module name (only one module in the package is imported)From package name. module Name Import function name (when a specific function in the module needs to be imported)4..pycache fileThe module is executed when it is imported, and the
$1000000.‘As you may have guessed, the % operator is used to format the string. Inside the string, the representation is replaced by a string, which %s %d is replaced with an integer, there are several %? placeholders, followed by a number of variables or values, the order to correspond well. If there is only one %? , the parentheses can be omitted.Common placeholders are:%d 整数%f 浮点数%s 字符串%x 十六进制整数where formatted integers and floating-point numbers can also specify whether to complement 0 a
(Self.name)8 9 defstaticprint ():Ten Print('This class\ ' s name was person')The next step is to create a new instance of the class and call it.1 Instance=person ('Tom')2instance.printname () 3 person.staticprint ()The first line invokes the constructor of the person and assigns the instance to the instance variable. It is worth noting that there is no new keyword in python.The second line invokes the instance method of the Printname. Output Tom.The third line invokes the Staticprin
the returned string is more friendly to the end user.If you only want to implement one of these two special methods, __repr__ is a better choice, if an object does not have a __str__ function, and Python needs to call it, the interpreter uses __repr__ insteadA custom Boolean valueBy default, instances of our own defined classes are always considered true unless the class has its own implementation for __bool__ or __LEN__ functions. The result of x.__
Python statementAssignment statements1. Assign the 3 object to the variable a2, 3, 4 is assigned to the variable, a, b1 >>> a = 3 2 >>> A, B = 3,43 >>> a4 35 >>> b6 47 >>> a = 3,48 >>> a9 (3, 4)3, the realization will a,b=3,4 exchange a,b=4,31>>> b =3,4 Generally we declare a temporary variable to resolve2>>> temp =a3>>> A =b4>>> B =Temp5>>>a647>>>b839>>> b,a=This can be done in Python, because the va
: Let the adorner with class parameters
Nineth Step: Adorner with class parameters, and split the public class into other py files, but also demonstrates the application of a function of multiple adorners
#-*-CODING:GBK-*-' mylocker.py: public class for example 9.py ' class Mylocker:def __init__ (self):p rint ("mylocker.__init__ () Called. ") @staticmethoddef acquire ():p rint ("Mylocker.acquire () called.") @staticmethoddef unlock ():p rint ("Mylocker.unlock () called.") Class Lockerex (Myloc
does not error, it returns none.Has_key: Checks whether the dictionary contains the given key. The expression D.has_key (k) is equivalent to K in D. Items and iteritems: Items return a dictionary item as a list, iteritems and items work the same, but it returns an iterator object instead of a list.keys and Iterkeys: The Keys method returns the keys in the dictionary as a list, and the Iterkeys method returns the values in the dictionary as a listpop: Gets the value corresponding to the given ke
is not, then go to the parent class, if the parent class is not, then an error.
Private properties, private methods, which are accessible inside the class, are not accessible to the outside or subclass of the class
PolymorphicPyhon Many grammars support polymorphism, such as Len (), Sorted (), and so on, you give Len a string to return the length of the string, and the list returns the length of the list.About polymorphism, Liaoche Teacher's tutorial is easy to understand, here is atta
In interactive mode:If you want Python to print out the specified text, you can use a print statement, and then enclose the text you want to print in single or double quotes, but you can't mix single and double quotation marks:>>> print ' Hello,world 'Hello,worldIn interactive mode, although convenient, but the execution of the code can not be saved, next we use a text editor to write and can be saved.Open notepad++, choose the code you've edited,
Record the python learning process with caution and record the python Process
1. Everything in python is an object, and the built-in data structure is also an object. To process an object, you can use its methods and attributes to process the object and achieve the desired result step by step.
2. During programming,
First day of learning PYTHON, first day of pythonContent to be mastered
1. Programming Language
2. python, C # JAVA
3. python: pypy cpython jpython
4. Execution Method
Interpreter
File Execution
5. Specify the interpreter
Python xxx. py
./Xxx. py #! /Usr/bin/env
Python Second Module learning summary, python module Summary
Summary:
1. Master the usage of the decorator
2. master generator usage
3. Understand the usage of the iterator
4. Familiar with Python built-in functions
5. Familiar with Python shutil/shelve/configparse/has
Summary of essential knowledge for python learning, and summary of essential knowledge for python
I. Variables1. Variables• Variable amount during Program Execution;• Defining a variable is accompanied by three features: Memory ID, data type, and variable value.• Before running other languages, you must manually release the program's memory space. However, the
[Programmer technical skills] Learning a scripting language python (3) dealing with databases, Scripting Language python
Next, the previous article describes how to use python to perform basic CRUD operations on the database. Here, we will describe sqlite3 as an example. Sqlite3 is a very lightweight database. It is ve
objects and strings are immutable objects, and all python caches them efficiently, which leads us to think that Python should create new objects without the illusion of creating new objects. Python caches only simple integers, and the range of Python-cached integers changes, so don't use this feature. (I don't know ho
small anonymous functions. This function is named after the standard procedure for declaring a function with DEF is omitted.A lambda function can receive any number of arguments but can only return the value of an expression, and can only contain commands or multiple expressions.Anonymous functions cannot call print directly, because lambda requires an expression.The lambda function has its own namespace and cannot access parameters outside its own argument list or in the global namespace.Altho
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.