python笔记day1——print、input

print函数

>>> help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.**默认空格**
    end:   string appended after the last value, default a newline.**转义字符**
    flush: whether to forcibly flush the stream.

>>>    
  1. 实际使用
#print用法
#1.
name ='xiaobai'
print(name)

#2.
age =18
gender ='boy'
print(name,age,gender) #逗号分隔,结果间隔一个空格
print(name,age,gender,sep="#")

print("aaa",end="")	#默认为\n
print("bbb",end="")
print("ccc")
  1. 转义字符
print("某某某:","\t点击激活",sep="\n")

#转义字符 
#\n换行    newline,开个新行
#\r    carriage return 回车,光标回到行首,如果没有\n直接\r就会覆盖打印

#\t制表符 \'单引号   \"双引号   \r   \\反斜杠

print("你说:\"想吃冰淇凌\"")
print(" 你说:'想吃冰淇凌' ")
print(' 你说:"想吃冰淇凌" ')#单、双引号嵌套时不需要转义字符

# r" "   # r'' raw 原样输出,即使有\ 转义 也原样输出
print('hello\py\\thon')
print(r'hello\py\thon')
  1. 单引号,双引号,三引号
message='''
'''
三引号作用
1、保留字符串的格式
2、多行注释(没有赋值时)
'''
message='''
[淘宝]
您正在使用验证码登录
验证码是:xxxx
涉及账户安全,请保密
'''
print(message)
  1. 格式化输出
#格式化输出,
#1、占位符
#先用%s占位,后再填充,避免用+号拼接
#加号拼接的必须是str+str
print('姓名是:%s,性别是:%s,年龄是:%s' %(name,gender,age,))
#str(int)---->把int变为str
print('年龄是:'+str(age))
print('年龄是:%s' % age) #%s  是str的简写,底层用了str()强制类型转化

#%d  digit数字,底层调用了int(),精度取整丢失,只剩18
age=18.5
print('年龄是:%d' % age) 

# %f 浮点型float,小数点后面的保留位数,且四舍五入
print('年龄是:%f' % age)
salary=8899.355
print('薪水是:%.2f' %salary)

movie='大侦探'
ticket=45.6
count=35
total=ticket*count
#写法1
message2='''
电影:%s
人数:%d
单价:%f
总票价:%.1f(小数点后保留一位)
'''
print(message2 % (movie,count,ticket,total))
#写法2
message3='''
电影:%s
人数:%d
单价:%f
总票价:%.1f(小数点后保留一位)
'''% (movie,count,ticket,total)
print(message3)

#2、format调用字符串的内置函数,按顺序赋值
age=8.5
s='已经上'
message4='乔治说:我今年{}岁了,{}幼儿园'.format(age,s)
print(message4)

input函数

>>> help(input)
Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.
按行接受,按回车将信息送入流中
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.

    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.
>>>    

使用

name=input("请输入你的名字")#阻塞式
print(name)

coins=input('充值金额')
coins=int(coins)
print("%s用户充值成功!当前余额为%d" %(name,coins))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值