Python 官方文档:入门教程 => 点击学习
常量为了和变量做区分,全部采用大写字母,之间用下划线连接。 静态方法:可以直接用类名来调用的方法,不需要创建对象,不会隐式的传送self。 根据面向对象的设计原则,应该将对象的职责封装到类的代码内部,尽量简化调用一方的代码调用。 1.
实例方法
定义:第一个参数必须是实例对象,该参数名一般约定为“self”,通过它来传递实例的属性和方法(也可以传类的属性和方法);
调用:只能由实例对象调用。
类方法
定义:使用装饰器@claSSMethod。第一个参数必须是当前类对象,该参数名一般约定为“cls”,通过它来传递类的属性和方法(不能传实例的属性和方法);
调用:实例对象和类对象都可以调用。
静态方法
定义:使用装饰器@staticmethod。参数随意,没有“self”和“cls”参数,但是方法体中不能使用类或实例的任何属性和方法;
调用:实例对象和类对象都可以调用。
备注:Mac 安装pygame报错
liangkai@ttys000 $ pip install pygame
Collecting pygame
Using cached https://files.pythonhosted.org/packages/b2/6b/c510f0853765eb2219ca5aa3D416d65bb0dea7cd9bb2984aea0a0e04c24d/pygame-1.9.4.tar.gz
Building wheels for collected packages: pygame
Running setup.py bdist_wheel for pygame ... error
Complete output from command /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-wheel-7s7vp6w0 --python-tag cp35:
...............
building 'pygame.sdlmain_osx' extension
/usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Ddarwin -D_THREAD_SAFE -DENABLE_NEWBUF=1 -I/usr/X11R6/include -I/usr/local/include/SDL -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c src/sdlmain_osx.m -o build/temp.macosx-10.6-intel-3.5/src/sdlmain_osx.o
In file included from src/sdlmain_osx.m:24:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:34:10: fatal error: 'CarbonSound/CarbonSound.h' file not found
#include <CarbonSound/CarbonSound.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
---
For help with compilation see:
Https://www.pygame.org/wiki/MacCompile
To contribute to pygame development see:
https://www.pygame.org/contribute.html
---
error: command '/usr/bin/clang' failed with exit status 1
----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-record-f5kt4tGo/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/
解决方法:
pip install pygame==1.9.2
--结束END--
本文标题: Python - 笔记1
本文链接: https://lsjlt.com/news/186260.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0