码迷,mamicode.com
首页 > 编程语言 > 详细

【python3的学习之路一】输入和输出

时间:2018-09-26 11:47:33      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:pre   color   int   you   keyword   final   tin   int()   实现   

标识符

  • 第一个字符必须是字母或下划线
  • 标识符的其他的部分由字母、数字和下划线组成
  • 标识符对大小写敏感

Python保留字

即关键字,不能把它们用作任何标识符名称

>>> import keyword
>>> keyword.kwlist
[False, None, True, and, as, assert, break, class, continue, def, del, elif, else, except, finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass, raise, return, try, while, with, yield]

多行语句

Python通常一行写完一条语句,但如果语句过长,我们可以使用反斜杠来实现多行语句

total = item_one +     item_two +     item_three

同一行显示多条语句

Python可以在同一行中使用多条语句,语句之间使用分号(;)分割

total = item_one +     item_two +     item_three;print(total)

输出

用 print() 在括号中加上字符串,就可以向屏幕输入指定的文字。同时print()函数也可以接受多个字符串,采用逗号隔开的方式就可以连成一串输出(遇到逗号会输出一个空格)。

print(Hello world!)
print(Hi,, what is your name?, Bye!)

关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符

print(str, end = ,)
print(str, end =  )

输入

input()函数可以让用户输入字符串,并存放到一个变量里。

name = input()
age = input(How old are you?)
print(name, is, age, years old!)

【python3的学习之路一】输入和输出

标签:pre   color   int   you   keyword   final   tin   int()   实现   

原文地址:https://www.cnblogs.com/CSgarcia/p/9705759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!