打开运行栏的方法使用win+r组合快捷键。在运行栏中输入cmd打开命令行窗口 在命令提示符窗口中首先进入py命令所在的文件夹。dos命令中切换根目录直接输入驱动器盘符即可: 直接键入python xx.py后回车确认。得到正确的运行结果。本例是个最简单的hello,world!的程序,运行后在命令行窗口中显示该串字符
>>> print(‘eat‘,10+15+7+4+7+3) eat 46 >>> print(‘cloth‘,20) cloth 20 >>> print(‘traffic‘,6+6+6+6+6) traffic 30 >>> print(‘精神‘,300+300+400+200) 精神 1200 >>> >>> >>> print(‘总消费‘, 46+20+30+1200) 总消费 1296
>>> eat = 10+15+7+4+7+3 >>> cloth = 20 >>> traffic = 6+6+6+6+6 >>> Spirit=300+300+200+400 >>> >>> total = eat + cloth + traffic + Spirit >>> print(‘总消费‘,total) 总消费 1296
常量即指不变的量,例如,pai=3.141592653..., 或在程序运行过程中不会改变的量。在Python中没有一个专门的语法代表常量,约定俗成用变量名全部大写代表常量
name = input("What is your name:") print("Hello " + name )
让用户输入多个信息:
name = input("What is your name:") age = input("How old are you:") hometown = input("Where is your hometown:") print("Hello ",name , "your are ", age , "years old, you came from",hometown)
What is your name:Guang‘tou‘qiang How old are you:18 Where is your hometown:DaShenLin Hello Guang‘tou‘qiang your are 18 years old, you come from DaShenLin
代码注释分为单行和多行注释。 单行注释用#,多行注释可以用三对双引号""" """
①不用全部加注释,只需要在自己觉得重要或不好理解的部分加注释即可。
②注释可以用中文或英文,但绝对不要用拼音。
原文:https://www.cnblogs.com/bypp/p/10316833.html