Python Basics (local, global variables, functions, file operations)Local variables can be used with return valuesGlobal variablesIf a function has a return value, it has no meaning if it is saved with this variable before calling the function.GlobalIf you add global declarations to a global variable in a local variableWendu = 0def test1 ():Global WenduWendu = 33D
Describes python's numeric type variables and methods.
Preface
The python data type cannot be changed, which means that if the value of the Number data type is changed, the memory space will be re-allocated. I will not talk about it below. Let's take a look at the detailed introduction.
The Number object will be created when the following instances assign values to vari
I. Knowledge of PythonPython language advantages and disadvantages, self-Baidu, here does not outline, simply say, Python is an object-oriented, interpreted computer language. So the question is, what is the difference between an explanatory and a compiled language?1. Explanatory and compiled language differencesinterpreted language: when the program runs, it compiles, and the code executes one line of compilation. Compile the source code into a. PYC
This section describes how Python functions return multiple values at the same time.
When learning Python, I was surprised to find that Python functions can return multiple values at the same time, which is very interesting.
#define function sumdef sum(x, y): z = x + y x
, it is automatically recycled by the Python garbage collection mechanismPython's built-in feature ID (), each variable value has its memory address, and ID is used to reflect the value of the variable in memory location, memory address different ID is differentdefines the three characteristics of a variable x=10;id (determines whether the ID is equal with IS), type (view type with print (type (x)), value (
. However, in some cases, Python global variables can solve problems that are hard to solve by local variables. Things must be divided into two parts. Global variables in python have two flexible usage methods:
Gl. py:
gl_1 = 'hello'gl_2 = 'world'
Used in other modules
A.
follow when using variables in Python. Violating these rules throws an error, and the guide is designed to make the code you write easier to read and understand. Be sure to keep the following rules about variables in mind.
Variable names can contain only letters, numbers, and underscores. Variable names can begin with a letter or underscore, but cannot
Python scope
Python no block-level scope to see the C language code:
#include int main () { if(20) { int0; } printf ("i =%d", i); return 0 ;}In this code, if clause introduces a local scope, the variable i exists in this local scope, but is not visible externally, so the next reference to the variable i in the printf function throws a compilation error, but not in Python
does Python support multiple inheritance? Python Multiple inheritance usageinheritance is an important way of object-oriented programming, and through inheritance, subclasses can extend the functionality of the parent class. Python also has this feature, and in addition,
, underline + plain lowercase letters are recommended)# age_of_oldboy=84#四: constants: Unchanging quantities#强调: There is no mandatory definition of constants in Python from a syntactic point#如果在python中需要定义常量, you should change the variable name all to uppercaseage_of_oldboy=84# age_of_oldboy=85# Print (Age_of_oldboy)Python
In Python, the variable type is fixed and cannot be modified once it is declared (in Python it should not be declared, but should be used)That's right:1 var = 12print(Var)3 var = 24print(VAR)Output variable var values, 1 and 2 in turn.Error:1 var = 12print(Var)3" I am a variable "4 Print(VAR)Compile errors, error on the third line.Data types in
easily understood as a range within a single file.B (built-in) built-in scopes, variables defined within the system's fixed modules, such as predefined variables within the Builtin module, the highest level scope, the widest range, can be understood as the scope of the current operating system.To illustrate:#!/usr/bin/env Python3#-*-Coding:utf-8-*-__author__ = "Ask to Program"__date__ = "2018-06-13 15:40"P
python multiple inheritance Usage Python weekend studyinheritance is an important way of object-oriented programming, and through inheritance, subclasses can extend the functionality of the parent class. Python also has this feature, and in addition, Python can use
Variable definition: variable is an area of computer memory, storing the value within the specified range, the value can be changed, the popular saying variable is to give the data a name.Second, the variable naming rules:1. Variable names consist of letters, numbers, underscores2. Numbers cannot begin3. Keywords cannot be used, example: a,a1,a_1Three, the assignment of variables:1. Variables in
Scope of variables in Python (variable scope) This article aimsThis article mainly discusses and summarizes the scope of variables in Python (variable scope).The aim is to make a more thorough understanding of the scope of variables in P
/python #-*-coding: UTF-8-*-counter = 100 # assign a value to the integer variable miles = 1000.0 # Floating Point name = "John" # string print counterprint milesprint name
In the above example, 100,100 0.0 and "John" are assigned to the counter, miles, and name variables respectively.The following results are output when the above program is executed:
1001000.
variable a_list points to the unchanged
No type of variable, object has type
Third, function value transfer
Let's look at an example:
Def func_int (a): A + = 4 def func_list (a_list): a_list[0] = 4 T = 0func_int (t) print t# output:0 t_list = [1, 2, 3] Func_list (t_list) print t_list# output: [4, 2, 3]
For the above output, a lot of Python beginners are co
of letters , underscores , and numbers
Cannot start with a number
cannot be duplicate with keyword
The keyword is the identifier that has been used inside Python
keywords have special features and meanings
Developers are not allowed to define identifiers with the same name as keywords
5.2 Key WordsUse the following command to view the keywords in PythonIn [1]: Import Keywordin [2]: print
------------------------process id:619[]
Turn on the 6th line comment and you'll see the following result:
Process id:32074process id:32073process id:32072process id:32078process id:32076process id:32071process Id:32077pro Cess id:32079process id:32075process id:32080------------------------process id:32066[3, 2, 1, 7, 5, 0, 6, 8, 4, 9]
2. Python multi-process shared variables in several ways:(1) Shared
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.