Python3 Study notes--001--python HelloWorld

Source: Internet
Author: User
Tags python script shebang

Python uses UTF-8 encoding by default

A python3 version of the HelloWorld code is as follows:


#!/usr/bin/env pythonprint (' Hello world! ')
If this Python script file is named: hello.py, there are two ways to run this script file:


1. Python hello.py


[email protected] python]$ python hello.py Hello world! [Email protected] python]$
2, modify the hello.py permissions,./hello.py



[Email protected] python]$/hello.py Hello world! [Email protected] python]$
The first row, called the Shebang (shell execution) row, specifies which interpreter to use
The shebang line usually has two types of equations:
#!/bin/bin/python
Or
#!/usr/bin/env python
The first form uses the specified interpreter, and the second equation uses the first Python interpreter found in a shell environment

For both python2.x and python3.x, a reliable and viable approach is to use the LN command to create a link to a different name in the/usr/bin/directory. For example, I only created a Python soft link to the PYTHON3 interpreter, and if necessary, you can create a python2 soft link to the Python2 interpreter.



Key elements of Python:

1. Input and output:

First, the output: print ()

After you install Python on windows, you'll see a python 3.4 Docs Server (pydoc-64 bit) in the menu, and you'll see the following page in your browser when you open it:

Where print is the text I entered, the carriage return will see the following:

I feel that the help document looks a little better in this way.

You can see that many of these parameters have default values, which is a good explanation.

Inputs: Input


Input (...) Input ([prompt]), string Read A string from the standard input.  The trailing newline is stripped. If the user hits EOF (unix:ctl-d, Windows:ctl-z+return), raise Eoferror.on Unix, GNU readline is used if enabled.  The prompt string, if given,is printed without a trailing newline before reading.
It is important to note that input returns a string type


An example of using input and print:


#!/usr/bin/env pythonprint (' Hello world! ') Name=input ("Input your Name:") print ("Your name is:" + name)
You can see that declaring a variable in Python is not necessary to indicate its type, which is a bit like JS.


2. int and Str in the built-in type

In Python, the int type is much friendlier than the C language, and we can use a very large number of int types without worrying about overflow

For string types, you can use [] to get a character in a string

However, it is necessary to propose that both int and string types are immutable. However, we can change the type of a data item by using an int (str) that can be str (int).

3. Object references

In Python, you can use the = operator to direct a variable to another variable, a practical example:


[Email protected] python]$/bin/cat hello.py #!/usr/bin/env pythonprint (' Hello world! ')  Name=input ("Input your Name:") var=nameprint ("Your name is:" + var) sex=input ("Input your Sex:") var=sexprint ("Your name is : "+ var" age=input ("Input your Age:") var=int print ("Your-is:", sep= ', end= ') print (VAR) [[Email protected] Pyth  on]$./hello.py Hello world!input your name:xiao dai mayour name Is:xiao dai mainput your sex:nanyour name Is:naninput Your Age:24your age Is:24[[email protected] python]$
You can see that the Var variable refers to a different variable, and the type of the content and value that it points to also changes.



HelloWorld here for the time being.


Python3 Learning Note--001--python HelloWorld

Related Article

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.