The following assumes variable A is 10 and variable B is:"=" is to assign the right value to the left variable .Example 1 : Programming Implementation 145893 Seconds is a few days a few hours a few minutes a few seconds? Total = 145893Day = Total // ( - * - * -)hour = ( Total % ( - * - * -)) // ( -* -)minute = ( Total % ( - * -)) // -second = Total % -Print("%dseconds to%ddays,%dhours,%dminutes,%dseconds" % ( Total, Day , Hour, minute, second))Example 2 : the user input Chinese, math
1, >>> myteacher = ' big '
>> Yourteacher = Myteacher>> myteacher = ' small '>> Print (Yourteacher)→bigWrong answer: Myteacher
2, >>> first = 100
>> second = ' 100 '>> first = Second>> Print (first)→100Wrong answer: ' 100 '
3, in addition to the escape, there is no way
>>STR = "Let ' s go!">>print (str)→let ' s go!Double quotes and three quotation marks ("" "..." "" ") can contain single quotes, and three quotation marks (" ... ") can contain double quotes without escaping
Analysis of the role of a comma after a value assignment statement in Python
This example describes the role of a comma after a value assignment statement in Python. Share it with you for your reference. The specific analysis is as follows:
IDLE 2.6.2
?
1 2 3 4 5 6 7 8 9 10 11 12
>>> A = 1 >>> B = 2
This is a creation in
Article, where the information may have evolved or changed.
Usually write much is python, recently saw a little go, today encountered a problem, and share with you
package mainimport "fmt"type student struct { Name string Age int}func pase_student() { m := make(map[string]*student) stus := []student{ {Name: "zhou", Age: 24}, {Name: "li", Age: 23}, {Name: "wang", Age: 22}, } for _, stu := ra
Python assignmentThere are several types. Let's talk about them separately;
1 sequence assignment:X, Y, Z = 1, 2, 3
We can think of it as: x = 1, y = 2, Z = 3
2 link assignment:
X = y = 1Print ID (X)Print ID (y)
As you can see, the results of the two executions are the same. Both the X and Y variables store the reference address of integer object 1.
3. Incremental
Simply put, if object A is stored in a mutable object such as a list or dictionary, a shallow copy of B to A is just a copy of the first layer of the object, and modifying the second layer of B still affects two objects.A deep copy does not affect the original object.ImportCopy.copy () Shallow copyCopy.deepcopy () deep copyThe assignment operation is more like a reference, the new assignment creates a new m
The following table lists the assignment operators supported by all Python languages. Assuming that variable a holds 10 and variable B holds 20, then:
For example:
Try the following example to understand all the assignment operators available in the Python programming language:
#!/usr/bin/pythona = 21b = 10c
This example describes the role of a comma after a python assignment statement. Share to everyone for your reference. The specific analysis is as follows:
IDLE 2.6.2
>>> a = 1>>> b = 2,>>> print type (a)
>>> print type (b)
>>> c = []>>> d = [],>>> print type (c)
>>> print type (d)
After a comma is added to the
elements of elements .In this line of code, note that set is a recursive pass-through subset:# Set[j] + = (Elements[i]) #Why Elements? SET[J] = set[j] + According to the question 2,+= Set[j] is still the original set[j], it may be the element of elements. SoSET[J] + = Elements[i]may be equivalent toElements[*] + = Elements[i]Once the elements of the elements are changed, the result is naturally wrong.How to solve this problem? According to question 3, as long as the set and elements are "no
This example describes the role of commas after Python assignment statements. Share to everyone for your reference. The specific analysis is as follows:
IDLE 2.6.2
?
1 2 3 4 5 6 7 8 9 10 11-12
>>> A = 1 >>> b = 2, >>> print type (a)
After a comma is appended to an assignment expression, an tuple object is automatically obtained, and
parameter value changes the default parameter value of the function object, so the default parameter value of the next call is changed. The reason for this is because the default parameter value is a mutable object, causing each call to change the default parameter value .As a result, you can avoid the hassle of designing objects as immutable objects as possible when programming.Assignment manipulation Techniques---sequence unpacking (recursive unpacking)
The sequence that contains mul
) lock_user_file.close () #定义事先设定的username和password常亮_username = "Galen "_password=" Galen "inpu_user={} #创建一个空的字典, used to determine a user name entered several times count=0# The number of times to record input Whilecount Program two: #! usr/bin/evnpython#-*-codingutf-8-*-__author__= ' Galen ' Importgetpass asgp# introduces the Getpass module importpickleimportos# verifies that there is a file that holds the locked user, if not, creates an empty file and writes an empty list if Notos.path.ex
Assignment
In python, a value assignment is to create an object reference, instead of storing the object as another copy. For example:
>>> a=[1,2,3]>>> b=a>>> c=a
The object is [1, 2, 3], which is referenced by three variables a, B, and c respectively. The three variables do not exclusively occupy the object [1, 2, 3], or you can use any variable to modify the o
First, meaning:The local variable XXX reference was not defined before.ii. Causes of ErrorsIs that Python does not have a variable declaration, so it finds the scope of the variable by a simple rule: if there is a variable assignment inside a function, the variable is considered local, so if the value of the modified variable becomes a local variable.Iii. The scene that produced this errorPython code:val=9d
a sequence, nested sequences in a dictionary are sub-objects of complex objects. For sub-objects, Python stores it as a public image, and all copies of it are treated as a reference, so that when one of the references changes the mirror and the other reference uses the mirror, the image is changed.So look at the origin[2 here], that is [3, 4] this list. According to the definition of shallow copy, the cop1[2] points to the same list [3, 4]. Well, if
= =Len (relation): $ relation.append (flag)Panax Notoginseng Else: - relation.append (flag) the + #parameter, the value of the remaining variable is equal to the value of the first variable argument Aindex = 1 the whileIndex Len (ARG): +Globals () [arg[index]] =globals () [arg[0]] -Index + = 1 $ $ - #assigning values to variables - defassign (Var, value): the Globalrelation - ifLen (relation):Wuyii =0 the whileI Len (relation): - ifVarinchRelation[i]
Multiple assignment operations are performed simultaneously:>>> x, y , z = #元组赋值 >>> print (x, y, z) 1 2 3 >>> values = [] #列表赋值 >>> x, Y,z = values>>> print (x, y, z) 1 2 3Swap two variables at once>>> x, y, z = 1,2,3>>> print (x, y, z) 1 2 3>>> x, y = y,x>>> print (x, y) 2 1When a function returns a tuple, multiple attributes that are assigned at the same time are particularly useful>>> people = {"Name": "Alice", "age": "+", "Genda": "ma
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.