GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Prove that two string variables of same value point same memory location - w3resource

Python: Prove that two string variables of same value point same memory location

Last update on May 17 2025 05:43:14 (UTC/GMT +8 hours)


String Memory Location Test

Write a Python program to prove that two string variables of the same value point to the same memory location.

Sample Solution:

Python Code:

# Define two string variables, str1 and str2, both containing the string "Python".
str1 = "Python"
str2 = "Python"
 
# Print the memory location (in hexadecimal) of str1 and str2 using the id() function.
print("\nMemory location of str1 =", hex(id(str1)))
print("Memory location of str2 =", hex(id(str2)))

# Print a blank line for separation.
print()

Sample Output:

Memory location of str1 = 0x7f8af3e89f10                                                                      
Memory location of str2 = 0x7f8af3e89f10

Flowchart:

Flowchart: Prove that two string variables of same value point same memory location.


For more Practice: Solve these Related Problems:

  • Write a Python program to check if two variables point to the same memory location.
  • Write a Python program to compare the memory addresses of different string variables.
  • Write a Python program to find the memory location of an object before and after modification.
  • Write a Python program to prove that small integers in Python share the same memory location.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to print Unicode characters.
Next: Write a Python program to create a bytearray from a list.

Python Code Editor:

 

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.