User interaction python basis of -python

Why interaction

Personal vernacular (ATM interaction, words can convey his ideas): give people a more convenient interface to interact with the computer and give it a valid irrespective of whether the information basis.


How to interact

name = input('请输入你的姓名:')
pwd = input('请输入你的密码:')

print(type(name))
print(type(pwd))

Please enter your name: nash
Please enter your password: 123
<class 'str'>
<class 'str'>

Can be found in input () method is the role of the received value.
Key: Accept value type to a string type that is str

python2 interaction

The following code is only available only in normal use python2

name = raw_input('请输入你的姓名:')
pwd = raw_input('请输入你的密码:')

print(type(name))  # 'str'
print(type(pwd))  # 'str'

Note: python2 among raw_input () and python3 in input () is exactly the same.

input in the python2

x = input('username: ')  # 必须输入明确的数据类型,你输入什么类型则接收什么数据类型,输入'egon'而不是egon,否则会报错

Python3 cross each other compared to Python2 should be more reasonable, although the interaction Python3 are used in the program is in trouble, because if the input of age also need to cast, but if the input python2, the user needs to know what data you entered is data types, user-unfriendly, so the program may write tomorrow no one uses.

A pit !!!

Ps: This can be mapped to user interaction ATM cart for ATM use input but the object is needed is a digital object (because only numbers can be logical and normal subtraction), so the value to be entered using a picture of isdigit () (meaning whether the object is composed of purely digital, and False or True) is determined, it is necessary to set up the associated string object int () or otherwise, must be converted into digital type, and then the addition and subtraction --- -> Note that point, a pit !!!!!!!!!

Guess you like

Origin www.cnblogs.com/suren-apan/p/11374621.html