数据类型和字符格式化

#关于数据类型
#数字{int ,Float,Long}
#布尔{真或假,1或0}
#字符串{hello world}
#列表
#元组
#字典

#字符串格式化
name=input("please input your name:")
age=input("please input your age:")
job=input("please input your job:")
#print("Information of %s \nname:%s \nage:%s \njob:%s" %(name,name,age,job) )

#字符串格式化也可以这样写
msg="""
Information of %s
name:%s
age:%s
job:%s
""" %(name,name,age,job)
print(msg)

注意:%s代表字符串,%d代表数字,%f代表浮点型,如果上面age:%s换成了age:%d,要在
age=input("please input your age:")换成age=int(input("please input your age:"))

字符串常用功能:
去除空白:name=input("please input your name:").strip()  表示输入的时候,不管前后有没有空格都会去除


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章