python的输入输出(input、print)

input输入

input:接受用户从键盘的输入,接受的类型都是字符串

username=input("please input your name:")
password=input("please input your password:")
print(username,type(username))
print(password,type(password))
输出:
please input your name:python
please input your password:123
python <class 'str'>
123 <class 'str'>
​
如果想要得到一个整型,可以使用类型转换int()
username=input("please input your name:")
password=int(input("please input your passqord:"))
print(username,type(username))
print(password,type(password))
输出:
please input your name:python
please input your passqord:123
python <class 'str'>
123 <class 'int'>、

隐藏密码输入getpass()

import getpass  #首先导入getpass,因为getpass不是内建函数
username = input("please input your name:")
password=getpass.getpass("please input password:")  使用 getpass模块下的getpass
print("your name is:",username)
print("your password is:",password)
因为pycharm中无法进行,所以以下答案是在Linux中测试的
输出:
please input your name:python
please input password:
your name is: python
your password is: 123
​

print输出

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

help(print)
print('a','b','c',7)    #value,输出的值
print('a','b','c',7, sep="%&&&")    #sep,分隔符类型
print('a','b','c',7,end="%")    #end,指定追加符
f =open("file.txt",'w+')
print('a','b','c',file=f)   #file,指定输出到哪里,默认是输出到sys.stdout(*屏幕)
输出:
a b c 7
a%&&&b%&&&c%&&&7
a b c 7%
还输出了一个file.txt的文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值