用户进行交互
读取用户输入
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?Tom
How old are you?22
Where is your hometown?ShangHai
Hello Tom your are 22 years old, you came from ShangHai
注释
增加代码的可读性。
代码注释分单行和多行注释, 单行注释用#
,多行注释可以用三对双引号""" """
代码注释原则:
- 不用全部加注释,只需要在自己觉得重要或不好理解的部分加注释即可
- 注释可以用中文或英文,但绝对不要拼音