【Python 教程】11_基础数据类型

本文详细介绍了Python的基本数据类型,包括数字、布尔、字符串、列表、元组、字典和集合,并通过实例展示了如何使用这些数据类型进行格式化输出,加深了对Python语法的理解。

在进行 python 学习的时候,我们首先得知道 what is python? why is python? how to study python?
…巴拉巴拉一大堆。
学习一门编程语言,首先要学习它的语法,学习语法的首要学习它的数据类型。
python的基本数据类型有以下几类:
(1)数字(int)类型:int、float、complex
(2)布尔(bloo)类型
(3)字符串(str)类型
(4)列表(list)
(5)元组(tuple)
(6)字典(dict)
(7)集合(set)

GitHub代码commits id:92448d8


将数据格式化输出

name = input("please input your name: ")
age = int(input("please input your age: "))
sex = bool(int(input("please input your sex: ")))
job = input("please input your job: ")
salary = input("please input your salary: ")

if sex == True:
    sex = 'male'
else:
    sex = 'fmale'

if salary.isdigit():
    salary = int(salary)
else:
    exit("salary must be int.")

print(name, age, sex, job, salary)   

# 格式化输出字符串
personal_info = '''
-------------Personal information of %s---------
.........NAME: %s
.........AGE: %d
.........SEX: %s
.........JOB: %s
.........SALARY: %f
.........WORK STILL: %d YEARS
--------------This is the end-------------
''' % (name, name, age, sex, job, salary, (65-age))

print(personal_info)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值