Python journey-02. The first Python program, python-02

Source: Internet
Author: User

Python journey-02. The first Python program, python-02

The previous chapter introduces the knowledge of Python. This chapter begins with operations. To create our first Python program, you must first configure the Python runtime environment.

 

1. Install python in 1.1.windows

Windows 10
Configure environment variables to prevent Program Calling errors

[Right-click this computer] --> [properties] --> [advanced system settings] --> [advanced] --> [environment variables] --> [in the system variables column, select the variable name Path and edit it. --> append the Python installation directory to the variable value and separate it]

For example, my path is D: \ Program Files (x86) \ python-362. Note that there is a semicolon before

1.2.upgrade and install python in Linux

In linux, python is known by default. The version is generally 2.7. We recommend that you upgrade it to at least 3.5. For details, see my other article.
Upgrade Python to version 3.5.2 in Linux:
Http://www.cnblogs.com/tssc/p/7762998.html

# Python-3.6.2 download
Wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

1.3.install Python on Mac

Similar to linux

 

2. My first program: 'Hello World! '2.1.python program running Method

(1) Run Python command line directly (built-in interactive device idel)
Enter python in Windows or Linux Command lines to enter the python command line mode.

>>>print('Hello World!')Hello World!

(2) Write a small program and call it directly using python

Use a text editor such as vim or notepad ++ to write a helloworld. py file with the following content:

vim helloworld.py
print('Hello World!')

Exit the text editor and enter:

python helloworld.py

Run helloworld. py. You can see the subsequent output of Python.

Hello World!

(3) Specify the interpreter, edit it as an executable script, and run it.

You can also change the Python program helloworld. py to an executable script and then execute it directly:

#!/usr/bin/env pythonprint('Hello World!')

Then, modify the permission to be executable and run it directly to see the effect.

chmod 755 hello.py./hello.py

Related Knowledge points:

1) print is a common function. Its function is to output strings in parentheses.
2) in Python 2.x, print can also be a keyword and can be written as print 'Hello World! ', But this does not work in 3.x.
3) in python, single quotes and double quotation marks are not distinguished. They are different from shell scripts.
4) The above is a common method to run python programs. In actual development, it is usually carried out using auxiliary tools developed such as pycharm.

 

Extended: hello world in other languages

1) C Language

#include <stdio.h>int main(void){printf("\nhello world!");return 0;}

2) C ++

#include <iostream>int main(void){std::cout<<"Hello world!";}

3) java language

Public class HelloWorld {// program entry public static void main (String args []) {// output information to the console System. out. println ("Hello World! ");}}

4) PHP

<?php     echo "hello world!"; ?> 

5) ruby Language

puts "Hello world!" 

6) go Language

package mainimport "fmt"func main(){   fmt.Printf("Hello World!\n God Bless You!");}

# Complete, haha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.