2.跟老韩学Python之hello初体验

学习编程需要多加练习,敲代码,下面开始我们的Python学习之旅。
1.第一行代码

[root@zabbix_server ~]# ipython
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: print("hello,world")                                                                                   
hello,world

上述代码表示进入ipython的交互式开发环境。

2.代码扩展
print函数除了可以输出字符串之外,还可以输出变量、整数运算结果、布尔运算结果,代码如下所示。

In [2]: str_1 = 'hello,world'                                                             

In [3]: print(str_1)                                                                                           
hello,world

In [4]: str_1                                                                                                  
Out[4]: 'hello,world'

In [5]: print(1 + 1)                                                                                           
2

In [6]: print(True)                                                                                            
True

In [7]: print(True + False)                                                                                    
1

上述代码分别定义了变量str_1、并使用print函数打印该变量,接着使用print打印输出1 + 1的整数运算结果,然后使用print函数打印出布尔True的值,最后使用print函数输出布尔True 和False的整数加运算结果。

总结:先对Python有最基础的了解,然后上手练习,逐渐精进。

猜你喜欢

转载自blog.51cto.com/hanyanwei/2445283