, and only the result of all true,and operations is True.An OR operation is an operation, as long as one of the true,or operation results is True.The not operation is a non-operation, which is a single-mesh operator that turns true to False,false to true.Five, null valueThe null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.The
When you declare variables within a function definition, they are not related to other variables with the same name outside the function, that is, the variable name is local to the function. This is called the scope of the variable. All variables are scoped to their defined blocks, starting with the point where their names are defined.Using local variablesExampl
#-there is a declared local variableNAME = ["Product Manager","Riopo Wet"]defQupengfei ():GlobalName Name="own" Print('I'm doing', NAME) Qupengfei ()#The error example, all variables are placed under the local variable, is not possible, so if you want any global variables, try to put forward. NAME = ["Product Manager","Riopo Wet"]defQupengfei (): NAME="own"
In Python multithreaded development, global variables are data shared by multiple threads, and local variables are the respective threads, unshared.Here are a few ways to do this:First: Passing a list as a parameter to a thread fromThreadingImportThreadImport TimedefWork1 (nums): Nums.append (44)
Local variables: variables defined in a function, scoped to the current function, only work on the current function.
Global variables: Variables defined at the beginning of the code, scoped to the entire code, work on the entire code.
Let's take a look at the following example, and finally give the conclusion.
name =
Python basics-Class variables and instance variables
Write in front
If not specifically stated, the following are based on Python3
Outline:
1. Class variables and instance variables
This is described in Python tutorial
Global variables, variables that can be called globallyLocal variables, variables that can be called in a subroutine' W ' def text (): ' L ' Print (name) text () print (name)Global var
can see from the example code above, there are obvious advantages to using the Print function: We can now specify additional delimiters (separator) and terminator (end string) compared to using the print statement.The key is flexibility.The true ingenuity and flexibility of turning print into a function is not easily noticed. After
Python-multiple methods of string connection and python-multiple methods
There are many string Connection Methods in python. I am writing code today. By the way, I would like to sum up the following:
The most primitive string connection method: str1 + str2New
Python _ does not need to print 1-1000 cyclically, and python prints 1-1000Question: I can print the 1000 numbers from 1 to on the screen. Do not use cyclic or conditional statements. Do not use them? : Operator. You are not allowed to use the method of listing output statements in the source code. For example, if you
Don't say a word, just cut to the chase.The print statement can output the specified text to the screen. For example, the output of ' Hello, world ', implemented in code as follows:>>> print ' Hello, world 'Attention:1. When we write code in a python interactive environment,,>>> is the prompt for the Python interpreter
a special null value.
In addition, Python provides multiple data types, such as lists and dictionaries, and allows you to create custom data types. We will continue later.Variable
The concept of variables is basically the same as that of the equation variables of junior high school algebra. in computer programs,
# Print Testclass.val1 # Testclass.val1 =2000 Print Inst1.val1 # testclass.val1 # print inst2.val1 # inst3 = TestClass ( ) print Inst3.val1 # 2000you can see that Python's class variables are different from C + + stat
Python basic syntax and variables
Basic syntax
Variable type
Percent% of formatted output
1. Basic syntax the first Python programInteractive programming:Interactive programming does not require the creation of a script file, it is written in the interactive mode of the Python interpreter.On Linux
initial value of sum = 0 # Sets the initial value of a total number to store the calculated result of the total number while count 3. All the even numbers in the output 1-100For I in Range (1,101): If I% 2 = = 0: print (i)4. All the odd numbers in the output 1-100For I in Range (1,101): If I% 2! = 0: print (i)5, to seek the 1-2+3-4+5-6...99 of all the number andMethod One:Count = 1sum
variable name is not local,Global. We useglobalStatement to complete this function. NoglobalIt is impossible to assign values to variables defined outside the function.
You can use the value defined outside the function (assuming there is no variable with the same name in the function ). However, I do not encourage you to do this, and you should avoid it as much as possible, because this makes the reader of the program unclear where the variable is d
In Python, a local variable is defined as a local variable, and the scope of the local variable is local. If the local variable is defined inside the function body, if you want to invoke the local variable outside the body of the function, the function needs to be executed first, the global variable can be defined inside the function body, but the keyword global must be prepended to the definition. The following examples can help to understand.def fun
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.