1、输入输出的使用
(1)、输出print print("%d 是%d" %(num,number))
(2)、输入input();
例如;
guess=input() //也可以是guess=input("请您输入一个数字:")
print(guess)
2、字符的连接+,转义字符r,长字符串的输出”””char”””
print("I "+"love"+" you")
输出的是I love you
如果是str='c:\now'
print(str)
输出的是:
c
ow
str=r'c:\now'
print(str)
输出的是:
c:\now
str="""this is my first project
this is my second project
this is my third project
"""
print(str)
输出的是:
this is my first project
this is my second project
this is my third project
3、变量名的赋值:
(1)、my_name='诺铖'
print(my_name)
(2)、在给变量输入的时候其实默认的都是输入的是字符
要想将其转变成整形的需要:int()的潜质转换
例如:
guess=input("请您输入一个数字:");
en_guess=int (guess)
或者:guess=int(input("请您输入一个数字:"))
这样才能将其转换成整形的
4、判断语句,以及循环使用:
(1)、if 条件:
执行的命令
else:
执行的命令
(2)、if 条件 and 条件 and 条件……:
执行条件
else:
执行条件
(3)、if 条件:
执行条件
elif 条件:
执行条件
elif 条件:
执行条件
(3)、while 条件:
循环执行的命令
(4)、for循环
for 目标 in 表达式:
循环体
例如:
arr="asdfasdf"
for i in arr:
print(i,end=' ')
输出的是 a s d f a s d f
例如:
arr=['诺铖','小颖','傻狗','傻猫']
for i in arr:
print(i,len(i)) //len()表示的判断该字符串的长度
(5)、range()的使用:
range(start ,[stop],[step])
例如:for i in range(1,5,2): //表示的是从1开始,到5结束 每循环一次增加2
print(i)
5、模块的引入:
(1)引用 import 模块名 //例如 import random //随机数的产生
(2)使用 secret=random.randint(1,10) //从1到10随机抽出一个数子
6、断点
assert 3>4
当这个关键字后面的条件为假的时候,程序自动崩溃并抛出assertionerror的异常,如果正确,就自动自动跳过去了