Python中字符的重复
print("字符" * n) #n为字符重复次数
Python的字符连接
print("字符1" + "字符2")
输出带有’\’的字符串:
1.使用’\’;
2.使用原始字符串;
#例如:输出C:\now
print("C:\\now")
print(r"c:\now")
猜数字:
temp = input("a number:") #赋值给temp
guess = int(temp) #转换为整型
if guess == 8:
print("yes")
else:
print("no")
print("game over")
改进版:
import random
key = random.randint(1, 100)
while 1:
temp = input("input a number:")
guess = int(temp)
if guess == key:
print("yes")
break
else:
if guess > key:
print("big")
else :
print("small")
print("game over")
idle打开新窗口:ctrl+n;
在idle中查看有哪些库函数:dir(-builtins-);
查看库函数具体功能:help(函数名);
PS:
运行Python文件时遇到提示:please select a valid interpreter解决方法
更改Pycharm的设置
打开settings(CTRL + ALT + S)
查找框输入 interpreter
双击 project Interpreter
在 Project Interpreter选择编译器,点击apply,重新启动pycharm即可