运行命令给我以下错误:
C:\Python34\Scripts> pip install pygame
错误堆栈:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
Run Code Online (Sandbox Code Playgroud) 我对 C 很陌生,我试图在一行中使用一个变量两次:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int myAge = 10;
char PL = "C";
printf("I am Rydex (not my real name) and i am %d years old. This was made using %s", myAge, PL);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,我得到:
我是 Rydex(化名),今年 10 岁。这是使用 (null) 制作的
我得到的是“(null)”,而不是变量“PL”中的值。有人可以帮帮我吗?
所以基本上,当我转到文件时builtins.py,我发现很多这样的函数:
def foo(o: object, arg: int | None = ...) -> int: ...
Run Code Online (Sandbox Code Playgroud)
当我自己尝试时,它实际上没有给出任何错误,并且仍然像正常功能一样工作。我想知道为什么人们使用它以及它的目的是什么。当我创建一个像该函数这样的函数时foo(这是之前给出的第一个示例):
def bar(arg: int, arg1: int | None = ...) -> int:
try:
return arg + arg1
except:
print('You cannot add a string and int together')
Run Code Online (Sandbox Code Playgroud)
我没有发现def bar(arg: int, arg1: int): ...和之间有什么区别def bar(arg: int, arg1: int | None = ...) -> int: ...
我试图在 python 中使用 tkinter 创建一个库:
import tkinter as tk
class Screen():
def make_window(self, width: int=None, height: int=None, title: str=None) -> int:
self.width = width
self.height = height
self.title = title
new_window = tk.Tk()
if width or height is not None:
new_window.geometry(width + "x" + height)
win = Screen()
win.make_window()
Run Code Online (Sandbox Code Playgroud)
但如果我这样做:
import tkinter as tk
class Screen():
def make_window(self, width: int=None, height: int=None, title: str=None) -> int:
self.width = width
self.height = height
self.title = title
global new_window
new_window = …Run Code Online (Sandbox Code Playgroud)