Learning Python 1 – 输出、输入、缩进、注释


● 输出 print()

print() 会依次打印每个字符串,遇到逗号“,”会输出一个空格

print('100 + 200 =',100+200)
----
100 + 200 = 300

print() 也可以打印整数或计算结果

print('100 + 200 =',100+200)
----
100 + 200 = 300


● 输入input()

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

name = input('please enter your name:')
print('hello',name)
----
please enter your name:linjie
hello linjie


● Python语法

Python采用缩进方式。

每一行都是一个语句,当语句以冒号:结尾时,缩进的语句视为代码块。

按照约定俗成的惯例,应该始终坚持使用4个空格的缩进

# print absolute value of an integer:

a = int(input('please enter an integer'))

if a >= 0:

    print(a)

else :

    print(-a)


● 注释 #

PyCharm中 使用commond+/快捷键

Python程序是大小写敏感的!

声明:自在独行|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Learning Python 1 – 输出、输入、缩进、注释


海阔凭鱼跃,天高任鸟飞