‘’'python
Tab健可以在cmd中打文件夹名字
变量的命名规则
1.名字要一眼看出意思,有描述性
2.变量名只能_ 数字 大小写字母组成,不能特殊字符,不能空格
3不能用中文做变量名
4不能以数字,不能以空格开头 不能以大写开头
5保留字符不能被使用(函数名 符号等等)
python里面所有的量 都是变量,没有常量
在python里面,所有的常量都用全部大写字母来表示
例如 PIE CO
用“” 包起来的 是字符串string
“Alex Daniel” 是字符串
其他自定义的,不加符号的, 都是变量名或者其他,或者值等等
变量(内存)回收机制,
直接del 变量名
直接旧的变量名给新的值
x=4
x=6
就可以。4这个值会自动在内存被回收掉
注释
用#
单行注释用#
多行注释例子
“”“print(msg)
print(msg)
print(msg)
print(msg)
print(msg)
print(msg)”“”
也可以用单引号,但是一定要3个 对称
‘‘‘
aaa
aaa
‘‘‘
用户交互简单实例
name1=input(“哼哼哈哈打字吧你:”)
name2=input(“打两遍:”)
‘’'这个时候,用户输入的input就定义为了变量name1和name2
保存在了内存里
然后打印出来’’’
print(name1,name2)
death_age = 80 #变量=80
name = input(“your name:”)
age = input(“your age:”) #input 接受的所有数据都是字符串,即便你输入的是数字,但依然会被当成字符串来处理
print( type(age) )
#int integer =整数 把字符串转成int,用int(被转的数据)
#str string =字符串 把数据转成字符串用str(被转的数据)
print(“Your name:”,name)
#print(“You can still live for “, death_age - int(age),” years …”)
print(“You can still live for " + str(death_age - int(age)) +” years …")
在py里面,一个等号,是赋值。两个等号表示相等
例子
my_age=28
这个是定义变量是28
type是整数int
age_of_princal = 56
guess_age = int( input(">>:") )
‘’’
if guess_age == age_of_princal then #伪代码,表示思路用
#伪代码,表示思路用
print(“yes”) #伪代码,表示思路用
else #伪代码,表示思路用
print("no ") #伪代码,表示思路用
‘’’
if guess_age == age_of_princal:
print(“Yes,you got it…”)
elif guess_age > age_of_princal:
print(“shoud try samller…”)
else:
print(“try bigger …”)
记住,if else的后面都要加冒号
elif可以判断很多很多条件
score = int(input(“score:”))
if score > 90:
print(“A”)
elif score > 80:
print(“B”)
elif score > 70:
print(“C”)
elif score > 50:
print(“D”)
else:
print(“滚”)
从上到下依次执行,成功了,只判断一次
‘’’