Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 891613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:55:05+00:00 2026-05-15T13:55:05+00:00

import ctypes a = ‘abc’ b = ctypes.string_at(id(a), 3) c = ctypes.string_at(id(a) + 20,

  • 0
import ctypes

a = 'abc'
b = ctypes.string_at(id(a), 3)
c = ctypes.string_at(id(a) + 20, 3)

I expect the result of b to be ‘abc’, but it is not; and the result of c is ‘abc’.
I don’t know why. Anyone can explain me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:55:05+00:00Added an answer on May 15, 2026 at 1:55 pm

    In Python, a str is an object, so there is no guarantee about what it looks like in memory. Probably, it contains some more information, like the length of the string. In your case, the size of this “metadata” is apparently 20 bytes.

    Possibly, the object itself does not even contain the actual string, but rather a pointer to it. If that is the case, in your situation the actual string happens to be located 20 bytes after the object.

    Either way, this is an implementation detail. None of this behaviour should be relied upon in any serious code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use python's (2.6.5) ctypes with cygwin, but I don't know how
Using the ctypes module I can easily import a POINTER(c_char) or a c_char_p type
I can't import ctypes on the production GAE server, which is causing our code
given the following code: import ctypes ip=192.168.1.1 thisdll = ctypes.cdll['aDLL'] thisdll.functionThatExpectsAnIP(ip) how can I
Let's say I have a 10 element array: from ctypes import * arr =
In Windows, the ctypes.cdll.msvcrt object automatically exists when I import the ctypes module, and
Tested this both on Ubuntu and ArchLinux, I get from ctypes import * libc
I'm trying to redo the Misaka module in ctypes, but when I try to
from ctypes import * and In [27]: sizeof(c_char_p) Out[27]: 8 In [28]: sizeof(c_uint64) Out[28]:
This is inconsistent: from ctypes import * class S(Structure): _fields_ = [(x, POINTER(c_int)), (y,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.