编译型:只须编译一次就可以把源代码编译成机器语言,后面的执行无须重新编译,直接使用之前的编译结果就可以;因此其执行的效率比较高。
解释型:源代码不能直接翻译成机器语言,而是先翻译成中间代码,再由解释器对中间代码进行解释运行
编译型语言有:C、C++、Pascal/Object Pascal(Delphi)
解释型语言有:Python、JavaScript、Shell、Ruby、MATLAB
第一种:交互式,在cmd中运行
第二种:命令行式,通过cmd输入python3文本
单行用#
多行用‘’‘或“”“框起来
true 和 false
变量名必须是大小写英文字母、数字或下划线的组合。
变量名不能用数字开头。
变量名对大小写敏感。
变量名不能是关键字,例如and、as、class等等。
变量名不能使用特殊符号,例如:!、@、#、$、% 等
变量在使用前必须对其赋值。
变量没有明显的变量声明,而且类型不是固定的。
在python中可以用id()函数获取对象的内存地址。
object=1+2
print(id(object))
usnm = "seven"
pswd=123
username = input("please enter your nickname!")
password = int(input("please enter your password!"))
if username==usnm and password==pswd:
print("ID comfirmed welcome!")
else:
print("login fault")
i=0
usnm = "seven"
pswd=123
i=0
while i<=2:
username = input("please enter your nickname!")
password = input("please enter your password!")
if username==usnm and password==pswd:
print("ID comfirmed welcome!")
i=2
break
else:
print("login fault")
i+=1
print("you can try",3-i,"times")
usnm1 = "seven"
usnm2 = "alex"
pswd = 123
i = 0
count=2
while i <=count :
username = input("please enter your nickname!")
password = int(input("please enter your password!"))
if username == usnm1 and password == pswd:
print("ID comfirmed welcome!", usnm1)
i =4
break
elif username == usnm2 and password == pswd:
print("ID comfirmed welcome!", usnm2)
i = 4
break
else:
print("login fault")
i+=1
print("you can try",count+1-i,"times")
num=2
total=0
while num<=100:
print(num)
if num%2==0:
total+=num
if num%2==1:
total-=num
num+=1
print("sum=",total)
i=1
while i<=12:
print(i)
i+=1
i=1
while i<=100:
if i%2==0:
print(i)
i+=1
else :
i+=1
i=1
while i<=100:
if i%2==1:
print(i)
i+=1
else:
i+=1
n1=123456
n2=n1
答:n2的值是由n1赋予的,当前两个变量的值皆为123456
需求:等待用户输入名字、地点、爱好,根据用户的名字和爱好进行任意显示
如:敬爱可爱的xxx,最喜欢在xxx地方干xxx
name=input("")
place=input("")
hobby=input("")
print("敬爱可爱的",name,"最喜欢在",place,"干",hobby)
注:反符合下面两个条件之一的年份是闰年。(1)能被四整除但不能被一百整除。(2)能被四百整除。
year=int(input("please enter a year"))
if year%4==0 and year%100!=0 or year%400==0:
print("该年是闰年")
else:
print("该年不是闰年")
principal=10000
year=0
while principal<=20000:
principal*=1.0325
year+=1
print(year)
原文:https://www.cnblogs.com/jimGraymane/p/11390654.html