[Learn python from zero] 03. Detailed explanation of Python interactive programming and annotations

Learn about pycharm

  1. Run Pycharm, select Create New Project, and create a new Python project.
    insert image description here

  2. Select 'Pure Python' to create a new pure Python project, Location indicates the save path of the project, and Interpreter is used to specify the version of the Python interpreter.
    insert image description here

  3. Right-click on the project, select New, then select Python File
    insert image description here

  4. Enter the file name HelloPython in the pop-up dialog box, and click OK to create a text file of a Python program. The default extension of the text file is .py
    insert image description here

  5. In the newly created HelloPython.py file, enter the following code, and right-click in the blank space to select Run to run, which means output a hello world string.

print("hello world!")

insert image description here

  1. After running successfully, the Pycharm Console window will display our output.
    insert image description here

interactive programming

Simply put, it is to run the interpreter directly in the terminal instead of using the file name to execute the file. This interactive programming environment, we can also call it REPL, which reads (Read) the input content, executes (Eval) the instructions entered by the user, prints (Print) the execution results, and then loops (Loop), Python Supports interactive programming.

1. Python interactive programming

insert image description here

2. Enter interactive programming in Pycharm

insert image description here

3. Installation and use of IPython

The interactive programming that comes with pyton is not powerful enough. For example, it cannot implement functions such as syntax highlighting and automatic line break. You can use the third-party package IPython (Interactive Python) to extend the functions of the built-in Python shell.

Install IPython

Using the pip command, you can quickly install IPython.

pip install ipython

use IPython

Enter ipython on the command line to enter ipython interactive programming.

Compared
insert image description here

Fourth, the advantages and disadvantages of interactive programming

advantage:

  • Suitable for learning/validating Python syntax or partial code

shortcoming:

  • Code cannot be saved
  • Not suitable for running very large programs

note

In the process of our work coding, if the logic of a piece of code is complex and not particularly easy to understand, we can add comments appropriately to assist ourselves or other coders to interpret the code.
insert image description here

Note: Comments are for programmers. In order to make it easier for programmers to read the code, the interpreter will ignore comments. It is a good coding habit to use the language you are familiar with and properly comment on the code.

Classification of comments

Single-line comments and multi-line comments are supported in Python.

single line comment

Starting with #, everything on the right of # is used as an explanation, not the actual program to be executed, and serves as an auxiliary explanation.

# #开头右边的都是注释,解析器会忽略注释
print('hello world')  #我的作用是在控制台输出hello world

multiline comment

Starting with ''' and ending with ''', we call it a multi-line comment.

'''
                               _ooOoo_
                              o8888888o
                              88" . "88
                              (| -_- |)
                              O\  =  /O
                           ____/`---'\____
                         .'  \\|     |//  `.
                        /  \\|||  :  |||//  \
                       /  _||||| -:- |||||-  \
                       |   | \\\  -  /// |   |
                       | \_|  ''\---/''  |   |
                       \  .-\__  `-`  ___/-. /
                     ___`. .'  /--.--\  `. . __
                  ."" '<  `.___\_<|>_/___.'  >'"".
                 | | :  `- \`.;`\ _ /`;.`/ - ` : | |
                 \  \ `-.   \_ __\ /__ _/   .-` /  /
            ======`-.____`-.___\_____/___.-`____.-'======
                               `=---='
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       佛祖保佑        永无BUG
              佛曰:
                     写字楼里写字间,写字间里程序员;
                     程序人员写程序,又拿程序换酒钱。
                     酒醒只在网上坐,酒醉还来网下眠;
                     酒醉酒醒日复日,网上网下年复年。
                     但愿老死电脑间,不愿鞠躬老板前;
                     奔驰宝马贵者趣,公交自行程序员。
                     别人笑我忒疯癫,我笑自己命太贱;
                     不见满街漂亮妹,哪个归得程序员?
'''

Advanced case

[Python] Python realizes the word guessing game-challenge your intelligence and luck!

[python] Python tkinter library implements GUI program for weight unit converter

[python] Use Selenium to get (2023 Blog Star) entries

[python] Use Selenium and Chrome WebDriver to obtain article information in [Tencent Cloud Studio Practical Training Camp]

Use Tencent Cloud Cloud studio to realize scheduling Baidu AI to realize text recognition

[Fun with Python series [Xiaobai must see] Python multi-threaded crawler: download pictures of emoticon package websites

[Play with Python series] [Must-see for Xiaobai] Use Python to crawl historical data of Shuangseqiu and analyze it visually

[Play with python series] [Must-see for Xiaobai] Use Python crawler technology to obtain proxy IP and save it to a file

[Must-see for Xiaobai] Python image synthesis example using PIL library to realize the synthesis of multiple images by ranks and columns

[Xiaobai must see] Python crawler actual combat downloads pictures of goddesses in batches and saves them locally

[Xiaobai must see] Python word cloud generator detailed analysis and code implementation

[Xiaobai must see] Python crawls an example of NBA player data

[Must-see for Xiaobai] Sample code for crawling and saving Himalayan audio using Python

[Must-see for Xiaobai] Technical realization of using Python to download League of Legends skin pictures in batches

[Xiaobai must see] Python crawler data processing and visualization

[Must-see for Xiaobai] Python crawler program to easily obtain hero skin pictures of King of Glory

[Must-see for Xiaobai] Use Python to generate a personalized list Word document

[Must-see for Xiaobai] Python crawler combat: get pictures from Onmyoji website and save them automatically

Xiaobai must-see series of library management system - sample code for login and registration functions

100 Cases of Xiaobai's Actual Combat: A Complete and Simple Shuangseqiu Lottery Winning Judgment Program, Suitable for Xiaobai Getting Started

Geospatial data processing and visualization using geopandas and shapely (.shp)

Use selenium to crawl Maoyan movie list data

Detailed explanation of the principle and implementation of image enhancement algorithm Retinex

Getting Started Guide to Crawlers (8): Write weather data crawler programs for visual analysis

Introductory Guide to Crawlers (7): Using Selenium and BeautifulSoup to Crawl Douban Movie Top250 Example Explanation [Reptile Xiaobai must watch]

Getting Started Guide to Crawlers (6): Anti-crawlers and advanced skills: IP proxy, User-Agent disguise, Cookie bypass login verification and verification code identification tools

Introductory Guide to Crawlers (5): Distributed Crawlers and Concurrency Control [Implementation methods to improve crawling efficiency and request rationality control]

Getting started with crawlers (4): The best way to crawl dynamic web pages using Selenium and API

Getting Started Guide to Crawlers (3): Python network requests and common anti-crawler strategies

Getting started with crawlers (2): How to use regular expressions for data extraction and processing

Getting started with reptiles (1): Learn the basics and skills of reptiles

Application of Deep Learning Model in Image Recognition: CIFAR-10 Dataset Practice and Accuracy Analysis

Python object-oriented programming basics and sample code

MySQL database operation guide: learn how to use Python to add, delete, modify and query operations

Python file operation guide: encoding, reading, writing and exception handling

Use Python and Selenium to automate crawling#【Dragon Boat Festival Special Call for Papers】Explore the ultimate technology, and the future will be due to you"Zong" #Contributed articles

Python multi-thread and multi-process tutorial: comprehensive analysis, code cases and optimization skills

Selenium Automation Toolset - Complete Guide and Tutorials

Python web crawler basics advanced to actual combat tutorial

Python introductory tutorial: master the basic knowledge of for loop, while loop, string operation, file reading and writing and exception handling

Pandas data processing and analysis tutorial: from basics to actual combat

Detailed explanation of commonly used data types and related operations in Python

[Latest in 2023] Detailed Explanation of Six Major Schemes to Improve Index of Classification Model

Introductory Python programming basics and advanced skills, web development, data analysis, and machine learning and artificial intelligence

Graph prediction results with 4 regression methods: Vector Regression, Random Forest Regression, Linear Regression, K-Nearest Neighbors Regression

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/132153752