Python学习笔记 chapter 2基础

程序输入

>>> print('%s is number %d'%('Python', 1))
Python is number 1

输出重定向有问题(待定)

文本输入
>>> user = input('Enter login name:')
Enter login name:root
>>> print('Your login is:', user)
Your login is: root

数值字符串输入
>>> num = input('Now enter a number:')
Now enter a number:22
>>> print('doubling your number: %d'% (int(num)*2))
doubling your number: 44

while循环
>>> num = 0
>>> while num < 3:
print('loop #%d'% (num))
num +=1


loop #0
loop #1
loop #2


for循环
>>> for item in [1,2,3,4,5]:
print(item, end='') # end表示print如何结束,默认为end="\n"(换行)


12345

posted @ 2017-05-27 11:28  阑珊0701  阅读(207)  评论(0编辑  收藏  举报