Python基础(一):变量,注释,if-else,关键字

安装Python

官网:https://www.python.org/
Windows下的安装:在官网下载对应的程序包,安装是勾选配置环境变量

第一个Python程序

允许cmd,输入Python命令:

这里写图片描述

输出helloworld:

这里写图片描述

注释

单行注释

#单行注释

多行注释

'''
这是多行注释
这是多行注释
这是多行注释
'''

变量和类型

speed = 100              
time = 3                 
distance = speed * time  
print(type(speed))  #result:int
_speed=str(speed) 
print(type(_speed)  #result:str

if-else

if 条件:    
    条件成立,执行.
else:     
    执行内容。 

示例:

flag=1                

if flag==1:           
    print("aaa")      
    print("bbb")      
else:                 
    print("ccc")      
    print("ddd")      

ifparam = input("请输入语种
if ifparam == "zh-cn":
    print("您选择的是简体中文")
elif ifparam == "en-us
    print("You chose A
else:                 
    print("请选择一种语言")  

说明:代码块不使用{},而使用 Tab

关键字

以下下为Python的关键字,不允许作为变量名。

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

如下,可查询当前Python版本的关键字

关键字

猜你喜欢

转载自blog.csdn.net/zhaobw831/article/details/78278892
今日推荐