在D:\python\目录下新建文件hello.txt,编写代码如下
1 print("hello world!")
修改后缀名为.py,执行hello.py,即
python D:\python\hello.py
#单行注释 ‘‘‘多行注释‘‘‘ 举例: ‘‘‘ -------菜单------- 1、列表 2、列表 3、列表 ------------------- ‘‘‘
快速注释:选中要注释的内容,ctrl+?
再次ctrl+?取消注释
声明变量
name = "双鱼的yanlei"
变量定义的规则:
1、变量名只能以 字母、数字或下划线组成
2、变量名不能以数字开头,且具有描述性
3、不能使用保留字符
name = input("请输入你的名字:") print(name)
if 判断语句
例子一、用户登陆验证
1 usr_name = "双鱼的yanlei" 2 usr_psw = "123456" 3 usr_input_name = input("请输入你的账号:") 4 usr_input_psw = input("请输入你的密码:") 5 if usr_input_name == usr_name and usr_input_psw == usr_psw : 6 print("登陆成功") 7 else: 8 print("密码输入错误!!!")
while 循环语句
1 count=1 2 while count <= 100: 3 if count%2 != 0: 4 print(count) 5 count+=1
1 usr_name = "双鱼的yanlei" 2 usr_psw = "123456" 3 for i in range(3) : 4 usr_input_name = input("请输入你的账号:") 5 usr_input_psw = input("请输入你的密码:") 6 if usr_input_name == usr_name and usr_input_psw == usr_psw : 7 print("登陆成功") 8 exit() 9 else: 10 print("密码输入错误!!!") 11 else: 12 print("输入超过规定次数!") 13 exit()
缩进:python中默认缩进4个空格
break用于退出所有循环
continue用于退出当前循环,继续下一次循环
exit 退出当前程序
原文:https://www.cnblogs.com/yjzhangchn/p/11158929.html