pycharm中python运行结果哪里查看

Python011

pycharm中python运行结果哪里查看,第1张

查看python运行结果的方法:

在pycharm中,点击页面最下方的“Run”选项,该选项可以打开一个程序运行窗口,程序执行完之后,运行结果会在上面显示出来

示例如下:

程序执行结果显示:

更多Python知识,请关注:Python自学网!!

python中一般并不需要查看内存内容,但作为从C/C++过来的人,有的时候还是想看看内存,有时是为了验证内容是否与预期一致,有时是为了探究下内存布局。

from sys import getsizeof

from ctypes import string_at

'''

getsizeof(...)

getsizeof(object, default) ->int

Return the size of object in bytes.

string_at(ptr, size=-1)

string_at(addr[, size]) ->string

Return the string at addr.

'''

getsizeof用于获取对象占用的内存大小,string_at用于获取指定地址、指定字节长度的内容,因为返回的对象类型是bytes,可以调用hex()函数转换成16进制查看。

对int对象的内存内容如下,首先通过函数id获取对象的内存地址。

i = 100

type(i)

# int

s = string_at(id(i), getsizeof(i))

type(s)

# bytes

s

# b'>\x00\x00\x00\x00\x00\x00\x00\xa0\x99\xfd\x1d\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00'

s.hex()

# '3e00000000000000a099fd1d000000000100000