Python基础介绍

1.1 入门

1.1.1 第一个hello word程序

print("Hello World!")

图片[1]|Python基础介绍|leon的博客

1.1.2 注释方法

# 单行注释
'''块注释'''
"""块注释"""

1.1.3 变量赋值

Python中只有变量,没有常量,即所有的变量都是可变的,程序中经常把“常量”定义为全部大写字符

# 变量赋值运算
x = 3
y = 4
z = x * y
print("x*y =",z)

# 常量定义
COUNTNUM = 50

图片[2]|Python基础介绍|leon的博客

1.1.4 用户输入

 注意:用户所有的输入都是字符串类型

name = input("Please input your name:")
age = input("Please input your age:")
print("Your name is:"+name+" and your age is:"+age)

图片[3]|Python基础介绍|leon的博客

1.1.5 字符串拼接

 

maxNum = 80
inputNum = input("Please input your number:")
print("There is "+str(maxNum-int(inputNum))+" in different")

图片[4]|Python基础介绍|leon的博客

1.2 条件语句

1.2.1 if条件语句

maxNum = 80
inputNum = input("Please input your number:")
if maxNum-int(inputNum)>0:
    print("Please input bigger...")
elif maxNum-int(inputNum)<0:
    print("Please input smaller...")
else:
    print("You have guess the number!")

图片[5]|Python基础介绍|leon的博客

图片[6]|Python基础介绍|leon的博客

图片[7]|Python基础介绍|leon的博客

温馨提示:本文最后更新于2022-12-20 20:57:48,已超过486天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/1167.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享