; otherwise, it returns None (a null value in Python ).
3-3.Identifier. Why should we avoid double underscores (_) at the beginning and end of the variable name?[Answer]Because the variable name _ xxx _ has a special meaning for Python, this naming style should be avoided for common variables.
sequence query like a if-elif-else statement or a for loop.As you can see, the solution in Python is more powerful and concise for implementing the same functionality.
4. Conditional expressions (ternary operators)
syntax : X if C else Y
Use the following:>>> x, y =4, 3>>> smaller = x if x
5.while statements
Grammar
While Expression:suite_to_repeat
Counting
knew * what she was doing. */PyErr_SetString (PyExc_SystemError, "NULL object passed to Py_BuildValue"); return v ;}
Example:
The left side is the function call form, and the right side is the returned Python value:
Py_BuildValue("") NonePy_BuildValue("i", 123) 123Py_BuildValue("iii", 123, 456, 789) (123, 456, 789)Py_BuildValue("s", "hello") 'hello'Py_BuildValue("ss", "hello", "world") ('h
of the sequence.
For example:
#! /Usr/bin/python
Output:
$ Python seq. PY
The Slice operator is a sequence name followed by a square bracket, which contains an optional number and is separated by a colon. Note that this is very similar to the index operator you are using. Remember that numbers are optional, while colons are required.
shoplist[1:3]Returns a
files, you can import test first, then call it through Test.add (A, B), and of course, by using the From test import Add.Three, the characteristics of module import:(1), loading the execution module, that is, the import module's top-level code will be executed, usually enclosing the module in the global variables, classes and functions of the Declaration.(2), A module can be imported (import) multiple times, but only load (load) once.Why use a module?1, code reuse.2, the System name space div
defined.Application of arguments: How to use it, but follow the corresponding rules. variable length parameter : variable length worth is the number of arguments is not fixed * number equal to the position parameterVariable length arguments defined by location: *Variable length arguments defined by keyword: * *def func (X,y,*args): #x =1 y=2, args= (3,4,5,6) Tuple formPrint (x, y)Print (args)Func (1,2,3,4,5,6) #实参为位置参数使用 *argsFunc (1,2,* (3,4,5,6)) #等同于 func (1,2,3,4,5,6)D:\
Python function Programming Guide (3): iterator details, python programming guide
3. iterator
3.1. Iterator Overview
An iterator is a way to access elements in a set. The iterator object is accessed from the first element of the set until all elements are accessed.
The iterator cannot be rolled back and can only be ite
Add by ZHJ: For a multi-line string connection, the 6th connection method is convenient and no additional space is added when connecting.Original: http://www.cnblogs.com/bigtreei/p/7892113.html1. PlusFirst, people with programming experience know that many languages use a plus sign to connect two strings, and Python also uses "+" directly to connect two strings;print ' Python ' + ' Tab 'Results:PythontabBac
be used in the function4, sum (A, B) at the time of execution, the "a" and "C" is passed to the SUM function5, return is the result when we call the function, the call function returns two number of the C=a+bb, various parameter types of the functionYou will often see how func (*args,**kwargs) functions are definedExample 1:1. Set a default value for variable bIf a value of B is specified when the argument is passed in, then there is a default value when B has no valuedef Funca (a,b=0): prin
(dictionary parameters)
M.N.
M is the minimum total width displayed, and n is the number of digits after the decimal point (if available)
Python2.6 begins with the addition of a function str.format () that formats the string, which enhances the functionality of string formatting.Python three-quote (triple quotes)Three quotation marks in Python can be used to copy complex strings:Python three quotes allow a string to spa
comes with a pip3,python2.7 that comes with a PIP, provided the PIP3 (scripts directory) is added to the environment variable.PIP3 Install a module for installation xxxPIP List view installed modulesPip Uninstall XXX module uninstalledSecond installation method, manual installation:First download the installation package, direct Baidu search for example, Python requests moduleUnpacking the installation packageExecute
;>> if x == 1: File "The above error is obvious, syntax error, colon is problematic. As a beginner, you may need to be wary of some of the following symbols as they are entered
English comma
English Colon
English parentheses
Brackets in English
The symbol is not accurate, the general Python interpreter will prompt SyntaxError , encounter this error do not fear, find a way to solve the good.Error
The two most commonly used modules:Os#可以允许python调用执行系统命令, such as the shellSYS#处理与python程序本身的事情Python comes with more than 200 common modulesThe Python website collects more than 2000 modules and can basically find any features you want, including graphics and interfaces .SYS module>>>Import SYS Import Module>>>Sys.pa
previous article, we introduced the use of the Power operator (* *) to calculate the N-squared of a number. In fact, you can use a function to replace this operator, this function is the POW, the function can pass two parameters, if you want to calculate X's Y, then the POW function's 1th parameter should be x, the 2nd parameter should be Y. The POW function returns the result of the calculation. For example, the following code calculates 2 of the 6-
not annotated in the compiled binaries.In the Python language, comments are divided into single-line comments and multiline comments. A single-line comment begins with a pound sign (#), and a multiline comment is enclosed in 3 quotation marks (single or double quotes). If you use a single-line comment, everything behind the pound sign is ignored when compiling the program, and if you use multiline comments
[Python journey] Article 6 (v): producer and consumer models implement multi-thread asynchronous InteractionAlthough the title is "producer-consumer model achieves multi-thread asynchronous interaction", this should also include the Python message queue, because the multi-thread asynchronous interaction is implemented through the
called, releasing the allocated memory unit immediately at the end of the call. Therefore, the formal parameter is only valid inside the function. Function call ends when you return to the keynote function, you can no longer use the shape parametricarguments can be constants, variables, expressions, functions, and so on, regardless of the type of argument, and when a function call is made, they must have a definite value in order to pass these values to the parameter. It is therefore necessary
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.