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有最基礎的瞭解,然後上手練習,逐漸精進。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章