美文网首页
【4】python第四课--字符转化,格式输出

【4】python第四课--字符转化,格式输出

作者: 咗嚛 | 来源:发表于2020-03-08 22:21 被阅读0次

#输出程序

print('hello,world')

age =18

print(age)

print("我今年",(age))

# %s 字符串str

# %d  有符号的十进制整数,正负整数  (-10  10)

# %f 浮点型float

# %U 无符号的十进制整数 (正整数)10

a =1.111

转换格式,注意python3有  f 参数

'''

1.准备数据2.格式化符号输出数据'''

age =18

name ='Tom'

weight =75.1

stu_id =1

stu_id2 =10234

#1.今年我的年龄是x岁---%d

print('今年我的年龄是%d岁'%age)

# 2.我的名字是x---字符串%s

print('我的名字是%s' % name)

#我的体重是X公斤----%f 浮点 默认6位  (.四色五人  .1后面一位  .2 2位)

print('我的体重是%.f公斤' % weight)

#4.我的学号是x----%d

print('我的学号是%d' %stu_id)

#4.1 我的学号是001----- %03d  3位数 不足的用0补全

print('我的学号是%03d' %stu_id)

print('我的学号是%03d' %stu_id2)

#我的名字是X,今年x岁数

print('我的名字是%s,今年%d岁' %(name,age))

#我的名字是X,明年x岁数

print('我的名字是%s,明年%d岁' %(name,age+1))

#6 我的名字是X,今年x岁数,体重是多少,学号是多少

print('我的名字是%s,今年%d岁数,体重是%.2f公斤,学号是%03d' %(name,age,weight,stu_id))

相关文章

  • 【4】python第四课--字符转化,格式输出

    #输出程序 print('hello,world') age =18 print(age) print("我今年"...

  • 与C/C++的不同

    #格式化输出字符串 在C中输出字符串语法是 'printf("age is %d",age);' 而在Python...

  • python—输入与输出

    Python的格式化输出 使用字符串格式化的形式来优化Python的输出,使用%作为占位符。%后面跟的是变量的类型...

  • Python-05-认识格式化符号

    格式化输出 print的结束符 输出:作用:程序输出内容个用户 格式符号转化%s字符串%d有符号的十进制整数%f浮...

  • 2019-05-09 json文件的提取方法

    Python自带json解析库, json.load(str),将json格式的字符串文件转化为Python数据结...

  • Python(一)字符串操作

    Python字符串的操作 一: python字符串的格式 双引号或者单引号中的数据都是字符串 二: 字符串的输出 ...

  • 字符串操作

    Python字符串 字符串格式化 Python将若干值插入到带有"%"标记的字符串中,从而可以动态的输出字符串 ...

  • 【python】格式化输出

    python print格式化输出。 打印字符串print ("His name is %s"%("ofish")...

  • python常用的语句

    python中datetime模块非常好用,提供了日期格式和字符串格式相互转化的函数strftime/strpti...

  • python3:字符串的格式化输出

    字符串的格式化输出由槽格式和format()来组成的.举个例子: 该python为python3.x版...

网友评论

      本文标题:【4】python第四课--字符转化,格式输出

      本文链接:https://www.haomeiwen.com/subject/hilsdhtx.html