PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 12, 2022

[FIXED] Why [a,b] and a+b have different values with APPEND command in My Paython Code?

 May 12, 2022     append, arrays, python     No comments   

Issue

I am new in Python.. But i realy confused with this problem...

The Print Results of the last 3 lines :

['John', 'Philiph', 'Derek', 'Melanie', 'Romy', 'Andy', 44]

[1, 2, 3, 4, 5, 6, 'John', 'Philiph', 'Derek', 'Melanie', 'Romy', 'Andy']

[[1, 2, 3, 4, 5, 6], ['John', 'Philiph', 'Derek', 'Melanie', 'Romy', 'Andy', 44]]

**QUESTION : ** 44 is in the t BUT---> WHY 44 isn't in the x

CODE :

z=[1,2,3,4,5,6]
h=['John', 'Philiph', 'Derek', 'Melanie', 'Romy', 'Andy']
x=z+h
t=[z,h]
#print(x)
#print(t)
h.append(44)
print(h)
print(x)
print(t)

Solution

z+h will create a single list containing h and z values meanwhile the [z,h] create a list of the two lists h and z



Answered By - Khalil Rebhi
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing