I guess you must now be eager to write your first program just like a man practicing martial arts eager to exercise his first move Well, let's waste no time learning how to write the classical "Hello, World" to see which programming styles can be applied and how we can get the running result of program To output a string of "Hello, World!" has almost become the most classical case for books, websites and related materials introducing programming languages Let's see how this program is written in Python At first, there is a string of "Hello, World! It can be expressed with single quote marks here Some other methods of expression are also available in Python Then, use this symbol the assignment equals sign assign it to the variable myString Then use print() to output this string Well, how can this program be run in Python? In Python there are two ways of running programs The first one is in Shell mode Shell is actually an interactive command interpreter In execution, it's like this input a command line for example a command like this The interpreter then interprets and executes this command Upon completion of execution, the corresponding result is output All right the string is output This is the first way of operation in Python The other way is by way of file In the IDE of Python we can create a file with file extension .py and use the Python interpreter to run for result in Shell Those two modes of operation seem somewhat different but both of them are indeed interpretation and execution thus, essentially the same In practice you may choose the way of Shell or the way of file execution Generally if the entire code segment is short the way of Shell is preferred If the code segment is long the way of file can be adopted Let's run it and have a look MacOS and Linux are often pre-installed with Python We may type "python" in Command Shell to open the Python 2 development environment type "python3" to open the Python 3 development environment Besides it, there are a lot of Python IDEs like the famous IPython or PyCharm Here we take the embedded IDE of Python - IDLE as an example Let's run the above program to output "Hello, World!" At first, define a string named myString and we may output this string This is the way of Shell Then, let's run this program by way of file Similarly, we input these two commands save it and run The result is shown in Shell such a line of string Then, how can we install integrated development environments (IDE) such as Python IDLE? Quite simple Just click Python IDLE on the homepage of Python’s official website download, install, and use it But for beginners, we prefer to recommend the use of some comprehensive integrated development environments or platforms since these environments have often been pre-installed with since these environments have often been pre-installed with lots of common third party libraries saving us the trouble of extra installation Currently, we tend to recommend the integrated development environment – Anaconda For the detailed installation of it, you may watch our supplementary video: Build a Python Environment Besides, we must point out that in subsequent learning if we need some special third party libraries we must separately install these libraries before use It's also easy to install them These libraries are normally inside the pip source of Python We may directly use "pip install packagename" at the OS terminal and can install it Give it a go For example, we'll use a famous Chinese text segmenter package – "jieba" in later lessons We may install it like this It's worth noticing that we install the third party library at the OS Shell namely, the OS terminal instead of a Python terminal It can be installed just like this It's detecting We can import and use it after proper installation Have a test Let's see whether such a complex sentence can be successfully segmented cut() is for text segmenting You must’ve heard this sentence With one grasp I was able to gain control of the handlebar. It seems to work well For the time being, we don’t need to install any additional third party library Please remember how we install it when we need it in the following weeks Now, let's look at the common interface and basic usages of Python environment in the integrated development environment Anaconda From its official website, it's quite easy download the installation versions of Anaconda for Windows, MacOS and Linux This is an interface of it containing IDE Spyder Since Python considers both the programming efficiency and the execution efficiency it has become a very popular language for scientific computing That's why Anaconda has integrated a lot of packages for scientific computing saving us the trouble of extra installation Let's look at the Spyder window The default interface is divided into three parts the left is the code editing window the upper right is the window of variable and file observation and the lower right is the console window for calling IDLE or IPython Such a way of combining several function windows into one window as we can obviously feel is more conducive to program editing running and debugging than in a single window Let's try the NumPy and Matplotlib modules in the famous scientific computing ecosystem - SciPy integrated in Anaconda Plot a line chart for three functions Let's first import such two modules Save and run As we see, three line charts appear in the console window We'll introduce the specific functions of this program later Leave it alone for a while After we introduce the operating modes and development environment of Python let's go back to the program After this lesson, I hope we can well write a super simple and mini but fully functional Python program Input and output are basic components of a program Let's look at the input and output then Output first In Python we use the print() function to output and its argument can be a variable or string like this In Python 2 we use a print statement for output The two are different In Python 2, to output the string "myString", you must write like this Then, let's look at the input In Python 3 we use the input() function to input It's written like this The argument of input() is the statement of prompting input after running it We can input the argument we'd like to input after it But pay attention here, the returned type of input() is str So we often need to use functions like int() and float() to convert the returned type into the type we need Or we may use the eval() function to consider the string as a valid Python expression to get the value and return the computation result Let's look at the output first It may output a string or a variable For example, we output the variable t in the program we ran just now Look at the input then Use the input() function After execution the argument of input() function is the prompt As we see, x is of str type So we may treat it like this Now as we see x is the int type we need Sure, we may use other functions to convert it into the type we need With an input and an output is it more like a real program? Before I teach you how to write programs to solve more complex problems let's talk about the style of program first The style is quite important just like that in painting. Is it right? The first point is about notes In Python, a note starts with "#" and ends at the end of this line Many positions are allowed Besides, the continuation character "\" is needed sometimes in Python What is the use of that? If a statement is quite long it can be divided into several lines Like this statement it is too long and thus divided into two lines A continuation character is used to indicate it Its actual effect is like this When is the continuation character unnecessary? Are there any cases in which we will think the current line is part of a string along with the previous or next line thus requiring no continuation character? Yes, there are! Like in this case If there are triple quotes which may also be used to express a string And if any triple quote starts we would expect a triple quote mark for ending Thus, no continuation character is needed between them Other cases are also similar like those with parentheses, square brackets or braces In those cases the system can determine the continuation relationship between them and we need not to add the continuation character Another style is multiple statements in one line At times, we may write several statements in a single line This is an example and it is equivalent to the example below Usually, we do not write several statements in one line except that these statements are closely related The styles we mentioned just now seem not quite influential on the entire program but the next one is vital What is it? It is the indentation in Python It is different from programming languages like the C language If you have learned the C language, you must know that In the C language, to use several statements to form a code block braces are needed to include them inside So, if braces are missing in the C language various problems may occur making us feel bothered In Python we find that no braces are needed any more Its design is quite convenient, natural and elegant Let's see its mode of alignment in this program It indents space of the same size at this side What does that mean It means they are in the same statement block In Python, we must pay special attention to this For example, if you add an additional space before "car" it cannot form a statement block with the statement below For this reason, there was an online argument between Python and C language fans A C language fan said to Python fans that a program could not run properly when I only typed in one more space So, we should pay special attention to indentation when writing Python programs and develop good programming habits What is the usual space for indentation? It's up to you to decide The usual practice, say, is 4 spaces You may also adopt some default settings in the development environment you use and it can be modified