How Python implements a PHP-like reference assignment

Source: Internet
Author: User

Tag: ATI%s OBA output variable BSP exists index div color

Directly put the code, there are comments, will not parse the

1 # ############################2 #change the value of a variable, and the value of the variable that is related to it also changes equally3 #php-like reference assignment, macro view4 # ############################5 6Relation = []#relation is a list of the collections that are loaded in the relationship7 8 9 #bind a variable that has a relationshipTen defBind (*Arg): One     ifLen (ARG) < 2: A         " " - determine the number of bound variables -         " " the         Print("error: Bind at least two variables") - exit () -     Globalrelation -      forIinchARG: +         " " - checks if the bound variable exists +         " " A         ifI not inchglobals (). Keys (): at             Print("Error: Variable%s does not exist"%(i)) - exit () -  -     #for loading -Flag =Set (ARG) -     ifLen (relation): ini =0 -          whileI <Len (relation): to             ifLen (relation[i) &flag): +Relation[i] = Relation[i] |Flag -                  Break thei + = 1 *         ifi = =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]: Wu                  forIteminchRelation[i]: -Globals () [Item] =value About                  Break $i + = 1 -         ifi = =Len (relation): -             Print('Error: The assigned variable is not yet bound') - exit () A     Else: +         Print("Error: No related collection currently exists") the exit () -  $  theA ='Sky' theb =' Land' theBind'a','b')#binding has a relational variable the Print(relation)#print a list of currently-related collections [{' A ', ' B '}] - Print(A, B)#values for output variables A and B sky Sky inAssign'a','Sea')#change the value of a variable the Print(A, B)#values for output variables A and B sea sea

How Python implements a PHP-like reference assignment

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.