2 输入输出与运算符

输入

  Python3 里的输入都是 input(‘提示用户信息’)

      

 

  input()

  name = input()    #输入的值会直接赋值给name

  name = input("请输入你的姓名:")  

      #("")里的话是输入提示信息

 

 

>>> name = input('Please input you name >>>:')
Please input you name >>>:'tony'
>>> name
"'tony'"
>>> 

 

输出:

输出刚才的name值。(带文字提示)

1、print("姓名:",name)

2、print("姓名:%s" %name)    #%代表占位符s即字符 与后面的%对应

推荐第二个方式(格式化输出)因为可以控制打印位置。

 

name = input("姓名:")
age = int(input("年龄:"))
sex = int(input("性别:"))
height = float(input("身高:"))
msg = '''
--------%s info--------
name:%s
age:%s
sex:%s
height:%s
-----------------------
'''%(name,name,age,sex,height)
print(msg)

 

运算符:

  算术运算符

  定义两个变量a = 10 b = 20

  

  

  赋值运算符:

  

 

   比较运算符:

  

  逻辑运算符:

  

posted @ 2017-08-30 15:06  eggtea  阅读(314)  评论(1)    收藏  举报