云亦然
天下皆白,唯我独黑。非攻墨门,兼爱平生。

Python之Python基础

2019-07-26 15:31:38 python学习笔记
Word count: 747 | Reading time: 3min

python学习笔记之Python基础

[Python基础之hello]
1
2
print("hello world")
print("hello hello")
[Python基础之第2个Python程序]
1
print("hello hello")
[Python基础之注释]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 这是第一个注释
print("hello world") # 输出欢迎信息

"""
这是多行注释
。。
。。
。。
注释完了
"""
# 这是第二个注释
print("hello hello")


[Python基础之qq号码]
1
2
3
4
5
6
7
8
# 1.定义一个变量记录 QQ 号码
qq_number = "2135434"
# 2.定义一个变量记录 QQ 密码
qq_passsword = "123"

# 如果希望通过解释器的方式,输出变量的内容,需要使用print函数
print(qq_number)
print(qq_passsword)
[Python基础之超市买苹果]
1
2
3
4
5
6
7
8
9
10
11
12
13
# 1.定义苹果的单价
price = 8.5

# 2.挑选苹果
weight = 7.5

# 3.计算付款金额
money = price * weight

# 4.只要买苹果就返 5
money = money - 5 #money -= 5

print(money)
[Python基础之个人信息]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
姓名:小明
年龄:18岁
性别:是男生
身高:1.75米
体重:75.0公斤
"""

# 在Python中,定义变量时不需要指定变量的类型的
# 在运行的时候,Python解释器,会根据赋值语句等号右侧的数据
# 自动推导出变量中保存数据的准确类型
# str 表示是一个字符串类型
name = "小明"
# int 表示是一个整数类型
age = 18
# bool 表示是一个布尔类型,真True 或者假 False
gender = True # 是
# float 表示是一个小数类型,浮点数
height = 1.75

weight = 75.0

print(2 ** 1000)
print(name)
[Python基础之买苹果增强版]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 1.输入苹果的单价
price_str = input("苹果的单价:")

# 2.输入苹果的重量
weight_str = input("苹果的重量:")

# 3.计算支付的总金额
# 注意:两个字符串变量之间是不能直接用乘法的
# money = price_str * weight_str
# 1> 将价格转换成小数
price = float(price_str)

# 2> 将重量转换成小数
weight = float(weight_str)

# 3> 用两个小数来计算最终的金额
money = price * weight #浮点数

print("您需要支付" + str(money) + "元")
[Python基础之买苹果改进]
1
2
3
4
5
6
7
8
9
10
# 1. 提示用户输入苹果的单价
price = float(input("苹果的单价:"))

# 2. 提示用户输入苹果的重量
weight = float(input("苹果的重量:"))

# 3. 计算金额
money = price * weight

print(money)
[Python基础之格式化输出]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 定义字符串变量name,输出 我的名字叫小明,请多多关照!
name = "小明"
print("我的名字叫 %s,请多多关照!" % name)

# 定义整数变量 student_no,输出 我的学号的 000001
student_no = 2
print("我的学号是 %06d" % student_no)

# 定义小数 price、weight、money
# 输出 苹果单价 9.00 元/斤,购买了 5.00 斤,需要支付 45.00 元
price = 8.5
weight = 7.5
money = price * weight
print("苹果单价 %.2f 元/斤,购买了 %.2f 斤,需要支付 %.2f 元" %(price,weight,money))

# 定义一个小数scale,输出 数据比例是10.00%
scale = 0.8
print("数据比例是 %.2f%%" % (scale * 100))


        

Author: 云亦然

Link: http://JaneBraun.github.io/2019/07/26/Python之Python基础/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
Python之分支
NextPost >
网络安全之暴力破解攻击
CATALOG
  1. 1. python学习笔记之Python基础