python入门-2020.12.21

1.行与缩进

if True:
  print ("True")
else:
   print ("False")

2.注释

#第一个注释

3.数据类型

数字:int (整数),float (浮点数),bool (布尔),complex (复数)

字符串:string

4.基础语法-接收键盘输入内容

age =input("请输入年龄:")
print("输入的年龄是" + age)
print(type(age)) #默认输入的内容类型是str

5.基础语法-导入模块用法

import random
huahua_age = random.randint(10, 20)
print("华华的年龄是",huahua_age)

6.if判断

import random

age =input("请输入年龄:")
print("输入的年龄是" + age)

huahua_age = random.randint(10, 20)
print("华华的年龄是"+str(huahua_age))
if int(age) > huahua_age:
    print("输入的年龄比华华的年龄大")
elif int(age) == huahua_age:
    print("猜对了")
else:
    print("输入的年龄比华华的年龄小")

7.for循环

for i in range(5):
    print(i)

8.while循环

count = 1
while (count > 0):
    print(count)
    count = count + 1
    if count == 5:
        break



 

加油
原文地址:https://www.cnblogs.com/huahuacheng/p/14170665.html